public override void Write(char[] buffer, int offset, int count, IFallback fallback) { InternalDebug.Assert(!endOfFile); byte unsafeAsciiMask = 0; var unsafeAsciiMap = fallback == null ? null : fallback.GetUnsafeAsciiMap(out unsafeAsciiMask); var hasUnsafeUnicode = fallback == null ? false : fallback.HasUnsafeUnicode(); if (cache.Length != 0 || canRestart) { while (count != 0) { char[] cacheBuffer; int cacheOffset; int cacheSpace; if (fallback != null) { cache.GetBuffer(FallbackExpansionMax, out cacheBuffer, out cacheOffset, out cacheSpace); var cacheOffsetStart = cacheOffset; for (; 0 != count && cacheSpace != 0; count--, offset++) { var ch = buffer[offset]; if (IsUnsafeCharacter(ch, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, isFirstChar, fallback)) { var cacheOffsetSave = cacheOffset; if (!fallback.FallBackChar(ch, cacheBuffer, ref cacheOffset, cacheOffset + cacheSpace)) { break; } cacheSpace -= (cacheOffset - cacheOffsetSave); } else { cacheBuffer[cacheOffset++] = ch; cacheSpace--; } isFirstChar = false; } cache.Commit(cacheOffset - cacheOffsetStart); } else { var minSpace = Math.Min(count, 256); cache.GetBuffer(minSpace, out cacheBuffer, out cacheOffset, out cacheSpace); var countToCopy = Math.Min(cacheSpace, count); Buffer.BlockCopy(buffer, offset * 2, cacheBuffer, cacheOffset * 2, countToCopy * 2); isFirstChar = false; cache.Commit(countToCopy); offset += countToCopy; count -= countToCopy; } } } else if (pullSink != null) { char[] pullBuffer; int pullOffset; int pullSpace; pullSink.GetOutputBuffer(out pullBuffer, out pullOffset, out pullSpace); if (pullSpace != 0) { if (fallback != null) { var pullStartOffset = pullOffset; for (; 0 != count && 0 != pullSpace; count--, offset++) { var ch = buffer[offset]; if (IsUnsafeCharacter(ch, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, isFirstChar, fallback)) { var pullOffsetSave = pullOffset; if (!fallback.FallBackChar(ch, pullBuffer, ref pullOffset, pullOffset + pullSpace)) { break; } pullSpace -= (pullOffset - pullOffsetSave); } else { pullBuffer[pullOffset++] = ch; pullSpace--; } isFirstChar = false; } pullSink.ReportOutput(pullOffset - pullStartOffset); } else { var countToCopy = Math.Min(pullSpace, count); Buffer.BlockCopy(buffer, offset * 2, pullBuffer, pullOffset * 2, countToCopy * 2); isFirstChar = false; count -= countToCopy; offset += countToCopy; pullSink.ReportOutput(countToCopy); pullOffset += countToCopy; pullSpace -= countToCopy; } } while (count != 0) { char[] cacheBuffer; int cacheOffset; int cacheSpace; if (fallback != null) { cache.GetBuffer(FallbackExpansionMax, out cacheBuffer, out cacheOffset, out cacheSpace); var cacheOffsetStart = cacheOffset; for (; 0 != count && cacheSpace != 0; count--, offset++) { var ch = buffer[offset]; if (IsUnsafeCharacter(ch, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, isFirstChar, fallback)) { var cacheOffsetSave = cacheOffset; if (!fallback.FallBackChar(ch, cacheBuffer, ref cacheOffset, cacheOffset + cacheSpace)) { break; } cacheSpace -= (cacheOffset - cacheOffsetSave); } else { cacheBuffer[cacheOffset++] = ch; cacheSpace--; } isFirstChar = false; } cache.Commit(cacheOffset - cacheOffsetStart); } else { var minSpace = Math.Min(count, 256); cache.GetBuffer(minSpace, out cacheBuffer, out cacheOffset, out cacheSpace); var countToCopy = Math.Min(cacheSpace, count); Buffer.BlockCopy(buffer, offset * 2, cacheBuffer, cacheOffset * 2, countToCopy * 2); isFirstChar = false; cache.Commit(countToCopy); offset += countToCopy; count -= countToCopy; } } while (pullSpace != 0 && cache.Length != 0) { char[] outputBuffer; int outputOffset; int outputCount; cache.GetData(out outputBuffer, out outputOffset, out outputCount); var countToCopy = Math.Min(outputCount, pullSpace); Buffer.BlockCopy(outputBuffer, outputOffset * 2, pullBuffer, pullOffset * 2, countToCopy * 2); cache.ReportRead(countToCopy); pullSink.ReportOutput(countToCopy); pullOffset += countToCopy; pullSpace -= countToCopy; } } else { if (fallback != null) { char[] cacheBuffer; int cacheOffset; int cacheSpace; cache.GetBuffer(1024, out cacheBuffer, out cacheOffset, out cacheSpace); var cacheOffsetStart = cacheOffset; var cacheSpaceStart = cacheSpace; while (count != 0) { for (; 0 != count && cacheSpace != 0; count--, offset++) { var ch = buffer[offset]; if (IsUnsafeCharacter(ch, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, isFirstChar, fallback)) { var cacheOffsetSave = cacheOffset; if (!fallback.FallBackChar(ch, cacheBuffer, ref cacheOffset, cacheOffset + cacheSpace)) { break; } cacheSpace -= (cacheOffset - cacheOffsetSave); } else { cacheBuffer[cacheOffset++] = ch; cacheSpace--; } isFirstChar = false; } if (cacheOffset - cacheOffsetStart != 0) { pushSink.Write(cacheBuffer, cacheOffsetStart, cacheOffset - cacheOffsetStart); cacheOffset = cacheOffsetStart; cacheSpace = cacheSpaceStart; } } } else { if (count != 0) { pushSink.Write(buffer, offset, count); isFirstChar = false; } } } }
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: 0x0600106F RID: 4207 RVA: 0x00078874 File Offset: 0x00076A74 public override void Write(char[] buffer, int offset, int count, IFallback fallback) { byte unsafeAsciiMask = 0; byte[] unsafeAsciiMap = (fallback == null) ? null : fallback.GetUnsafeAsciiMap(out unsafeAsciiMask); bool hasUnsafeUnicode = fallback != null && fallback.HasUnsafeUnicode(); if (this.cache.Length == 0) { if (!this.canRestart) { if (this.pullSink != null) { char[] array; int num; int num2; this.pullSink.GetOutputBuffer(out array, out num, out num2); if (num2 != 0) { if (fallback != null) { int num3 = num; while (count != 0 && num2 != 0) { char c = buffer[offset]; if (ConverterUnicodeOutput.IsUnsafeCharacter(c, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, this.isFirstChar, fallback)) { int num4 = num; if (!fallback.FallBackChar(c, array, ref num, num + num2)) { break; } num2 -= num - num4; } else { array[num++] = c; num2--; } this.isFirstChar = false; count--; offset++; } this.pullSink.ReportOutput(num - num3); } else { int num5 = Math.Min(num2, count); Buffer.BlockCopy(buffer, offset * 2, array, num * 2, num5 * 2); this.isFirstChar = false; count -= num5; offset += num5; this.pullSink.ReportOutput(num5); num += num5; num2 -= num5; } } while (count != 0) { if (fallback != null) { char[] array2; int num6; int num7; this.cache.GetBuffer(16, out array2, out num6, out num7); int num8 = num6; while (count != 0 && num7 != 0) { char c2 = buffer[offset]; if (ConverterUnicodeOutput.IsUnsafeCharacter(c2, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, this.isFirstChar, fallback)) { int num9 = num6; if (!fallback.FallBackChar(c2, array2, ref num6, num6 + num7)) { break; } num7 -= num6 - num9; } else { array2[num6++] = c2; num7--; } this.isFirstChar = false; count--; offset++; } this.cache.Commit(num6 - num8); } else { int size = Math.Min(count, 256); char[] array2; int num6; int num7; this.cache.GetBuffer(size, out array2, out num6, out num7); int num10 = Math.Min(num7, count); Buffer.BlockCopy(buffer, offset * 2, array2, num6 * 2, num10 * 2); this.isFirstChar = false; this.cache.Commit(num10); offset += num10; count -= num10; } } while (num2 != 0) { if (this.cache.Length == 0) { return; } char[] src; int num11; int val; this.cache.GetData(out src, out num11, out val); int num12 = Math.Min(val, num2); Buffer.BlockCopy(src, num11 * 2, array, num * 2, num12 * 2); this.cache.ReportRead(num12); this.pullSink.ReportOutput(num12); num += num12; num2 -= num12; } } else { if (fallback != null) { char[] array3; int num13; int num14; this.cache.GetBuffer(1024, out array3, out num13, out num14); int num15 = num13; int num16 = num14; while (count != 0) { while (count != 0 && num14 != 0) { char c3 = buffer[offset]; if (ConverterUnicodeOutput.IsUnsafeCharacter(c3, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, this.isFirstChar, fallback)) { int num17 = num13; if (!fallback.FallBackChar(c3, array3, ref num13, num13 + num14)) { break; } num14 -= num13 - num17; } else { array3[num13++] = c3; num14--; } this.isFirstChar = false; count--; offset++; } if (num13 - num15 != 0) { this.pushSink.Write(array3, num15, num13 - num15); num13 = num15; num14 = num16; } } return; } if (count != 0) { this.pushSink.Write(buffer, offset, count); this.isFirstChar = false; } } return; } } while (count != 0) { if (fallback != null) { char[] array4; int num18; int num19; this.cache.GetBuffer(16, out array4, out num18, out num19); int num20 = num18; while (count != 0 && num19 != 0) { char c4 = buffer[offset]; if (ConverterUnicodeOutput.IsUnsafeCharacter(c4, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, this.isFirstChar, fallback)) { int num21 = num18; if (!fallback.FallBackChar(c4, array4, ref num18, num18 + num19)) { break; } num19 -= num18 - num21; } else { array4[num18++] = c4; num19--; } this.isFirstChar = false; count--; offset++; } this.cache.Commit(num18 - num20); } else { int size2 = Math.Min(count, 256); char[] array4; int num18; int num19; this.cache.GetBuffer(size2, out array4, out num18, out num19); int num22 = Math.Min(num19, count); Buffer.BlockCopy(buffer, offset * 2, array4, num18 * 2, num22 * 2); this.isFirstChar = false; this.cache.Commit(num22); offset += num22; count -= num22; } } }