private static bool IsUnsafeCharacter( char ch, byte[] unsafeAsciiMap, byte unsafeAsciiMask, bool hasUnsafeUnicode, bool isFirstChar, IFallback fallback) { if (unsafeAsciiMap == null) { return(false); } var result = ((ch >= unsafeAsciiMap.Length) ? false : (unsafeAsciiMap[(int)ch] & unsafeAsciiMask) != 0); result = result || (hasUnsafeUnicode && ch >= 0x7F && fallback.IsUnsafeUnicode(ch, isFirstChar)); return(result); }
public void WriteComplete(char[] buffer, int offset, int count, IFallback fallback) { int num = 0; if (fallback != null || this.lineModeEncoding) { byte b = 0; byte[] array = null; uint num2 = 0U; bool flag = false; bool flag2 = false; if (fallback != null) { array = fallback.GetUnsafeAsciiMap(out b); if (array != null) { num2 = (uint)array.Length; } flag = fallback.HasUnsafeUnicode(); flag2 = fallback.TreatNonAsciiAsUnsafe(this.encoding.WebName); } while (count != 0) { while (count != 0 && this.lineBufferCount != this.lineBuffer.Length) { char c = buffer[offset]; if (fallback != null && (((uint)c < num2 && (array[(int)c] & b) != 0) || (!this.encodingCompleteUnicode && (c >= '\u007f' || c < ' ') && this.codePageMap.IsUnsafeExtendedCharacter(c)) || (flag && c >= '\u007f' && (flag2 || fallback.IsUnsafeUnicode(c, this.isFirstChar))))) { if (!fallback.FallBackChar(c, this.lineBuffer, ref this.lineBufferCount, this.lineBuffer.Length)) { break; } this.isFirstChar = false; } else { this.lineBuffer[this.lineBufferCount++] = c; this.isFirstChar = false; if (this.lineModeEncoding) { if (c == '\n' || c == '\r') { num = this.lineBufferCount; } else if (num > this.lineBuffer.Length - 256) { count--; offset++; break; } } } count--; offset++; } if (this.lineModeEncoding && (num > this.lineBuffer.Length - 256 || (this.lineBufferCount > this.lineBuffer.Length - 32 && num != 0))) { this.EncodeBuffer(this.lineBuffer, 0, num, false); this.lineBufferCount -= num; if (this.lineBufferCount != 0) { Buffer.BlockCopy(this.lineBuffer, num * 2, this.lineBuffer, 0, this.lineBufferCount * 2); } } else if (this.lineBufferCount > this.lineBuffer.Length - Math.Max(this.minCharsEncode, 32)) { this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false); this.lineBufferCount = 0; } num = 0; } return; } if (count > this.minCharsEncode) { if (this.lineBufferCount != 0) { this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false); this.lineBufferCount = 0; } this.EncodeBuffer(buffer, offset, count, false); return; } Buffer.BlockCopy(buffer, offset * 2, this.lineBuffer, this.lineBufferCount * 2, count * 2); this.lineBufferCount += count; if (this.lineBufferCount > this.lineBuffer.Length - this.minCharsEncode) { this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false); this.lineBufferCount = 0; } }
public void WriteComplete(char[] buffer, int offset, int count, IFallback fallback) { InternalDebug.Assert(!this.endOfFile); InternalDebug.Assert(this.encoding != null); if (fallback != null || this.lineModeEncoding) { byte unsafeAsciiMask = 0; byte[] unsafeAsciiMap = null; uint unsafeAsciiMapLength = 0; bool hasUnsafeUnicode = false; bool treatNonAsciiAsUnsafe = false; if (fallback != null) { unsafeAsciiMap = fallback.GetUnsafeAsciiMap(out unsafeAsciiMask); if (unsafeAsciiMap != null) { unsafeAsciiMapLength = (uint)unsafeAsciiMap.Length; } hasUnsafeUnicode = fallback.HasUnsafeUnicode(); treatNonAsciiAsUnsafe = fallback.TreatNonAsciiAsUnsafe(this.encoding.WebName); } while (0 != count) { for (; 0 != count && this.lineBufferCount != this.lineBuffer.Length; count--, offset++) { char ch = buffer[offset]; if (fallback != null) { if (((uint)ch < unsafeAsciiMapLength && (unsafeAsciiMap[(int)ch] & unsafeAsciiMask) != 0) || (!this.encodingCompleteUnicode && (ch >= 0x7F || ch < ' ') && this.codePageMap.IsUnsafeExtendedCharacter(ch)) || (hasUnsafeUnicode && ch >= 0x7F && (treatNonAsciiAsUnsafe || fallback.IsUnsafeUnicode(ch, this.isFirstChar)))) { if (!fallback.FallBackChar(ch, this.lineBuffer, ref this.lineBufferCount, this.lineBuffer.Length)) { break; } this.isFirstChar = false; continue; } } this.lineBuffer[this.lineBufferCount++] = ch; this.isFirstChar = false; if (this.lineModeEncoding) { if (ch == '\n' || ch == '\r') { this.lineBufferLastNL = this.lineBufferCount; } else if (this.lineBufferLastNL > this.lineBuffer.Length - LineSpaceThreshold) { count--; offset++; break; } } } if (this.lineModeEncoding && (this.lineBufferLastNL > this.lineBuffer.Length - LineSpaceThreshold || (this.lineBufferCount > this.lineBuffer.Length - SpaceThreshold && this.lineBufferLastNL != 0))) { this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferLastNL, false); this.lineBufferCount -= this.lineBufferLastNL; if (this.lineBufferCount != 0) { Buffer.BlockCopy(this.lineBuffer, this.lineBufferLastNL * 2, this.lineBuffer, 0, this.lineBufferCount * 2); } } else if (this.lineBufferCount > this.lineBuffer.Length - Math.Max(this.minCharsEncode, SpaceThreshold)) { this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false); this.lineBufferCount = 0; } this.lineBufferLastNL = 0; } } else { if (count > this.minCharsEncode) { if (this.lineBufferCount != 0) { this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false); this.lineBufferCount = 0; this.lineBufferLastNL = 0; } this.EncodeBuffer(buffer, offset, count, false); } else { InternalDebug.Assert(this.lineBufferCount + count <= this.lineBuffer.Length); Buffer.BlockCopy(buffer, offset * 2, this.lineBuffer, this.lineBufferCount * 2, count * 2); this.lineBufferCount += count; if (this.lineBufferCount > this.lineBuffer.Length - this.minCharsEncode) { this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false); this.lineBufferCount = 0; this.lineBufferLastNL = 0; } } } }
public void WriteComplete(char[] buffer, int offset, int count, IFallback fallback) { if (fallback != null || lineModeEncoding) { byte b = 0; byte[] array = null; uint num = 0u; bool flag = false; bool flag2 = false; if (fallback != null) { array = fallback.GetUnsafeAsciiMap(out b); if (array != null) { num = (uint)array.Length; } flag = fallback.HasUnsafeUnicode(); flag2 = fallback.TreatNonAsciiAsUnsafe(encoding.WebName); } while (count != 0) { while (count != 0 && lineBufferCount != lineBuffer.Length) { char c = buffer[offset]; if (fallback != null && (((uint)c < num && (array[(int)c] & b) != 0) || (!encodingCompleteUnicode && (c >= '\u007f' || c < ' ') && codePageMap.IsUnsafeExtendedCharacter(c)) || (flag && c >= '\u007f' && (flag2 || fallback.IsUnsafeUnicode(c, isFirstChar))))) { if (!fallback.FallBackChar(c, lineBuffer, ref lineBufferCount, lineBuffer.Length)) { break; } isFirstChar = false; } else { lineBuffer[lineBufferCount++] = c; isFirstChar = false; if (lineModeEncoding) { if (c == '\n' || c == '\r') { lineBufferLastNL = lineBufferCount; } else if (lineBufferLastNL > lineBuffer.Length - 256) { count--; offset++; break; } } } count--; offset++; } if (lineModeEncoding && (lineBufferLastNL > lineBuffer.Length - 256 || (lineBufferCount > lineBuffer.Length - 32 && lineBufferLastNL != 0))) { EncodeBuffer(lineBuffer, 0, lineBufferLastNL, false); lineBufferCount -= lineBufferLastNL; if (lineBufferCount != 0) { Buffer.BlockCopy(lineBuffer, lineBufferLastNL * 2, lineBuffer, 0, lineBufferCount * 2); } } else if (lineBufferCount > lineBuffer.Length - Math.Max(minCharsEncode, 32)) { EncodeBuffer(lineBuffer, 0, lineBufferCount, false); lineBufferCount = 0; } lineBufferLastNL = 0; } return; } if (count > minCharsEncode) { if (lineBufferCount != 0) { EncodeBuffer(lineBuffer, 0, lineBufferCount, false); lineBufferCount = 0; lineBufferLastNL = 0; } EncodeBuffer(buffer, offset, count, false); return; } Buffer.BlockCopy(buffer, offset * 2, lineBuffer, lineBufferCount * 2, count * 2); lineBufferCount += count; if (lineBufferCount > lineBuffer.Length - minCharsEncode) { EncodeBuffer(lineBuffer, 0, lineBufferCount, false); lineBufferCount = 0; lineBufferLastNL = 0; } }
// Token: 0x06001074 RID: 4212 RVA: 0x00078E04 File Offset: 0x00077004 private static bool IsUnsafeCharacter(char ch, byte[] unsafeAsciiMap, byte unsafeAsciiMask, bool hasUnsafeUnicode, bool isFirstChar, IFallback fallback) { return(unsafeAsciiMap != null && (((int)ch < unsafeAsciiMap.Length && (unsafeAsciiMap[(int)ch] & unsafeAsciiMask) != 0) || (hasUnsafeUnicode && ch >= '\u007f' && fallback.IsUnsafeUnicode(ch, isFirstChar)))); }