internal unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder) { base.CheckMemorySection(); DBCSCodePageEncoding.DBCSDecoder dbcsdecoder = (DBCSCodePageEncoding.DBCSDecoder)baseDecoder; byte *ptr = bytes; byte *ptr2 = bytes + byteCount; char *ptr3 = chars; char *ptr4 = chars + charCount; bool flag = false; DecoderFallbackBuffer decoderFallbackBuffer = null; if (dbcsdecoder != null && dbcsdecoder.bLeftOver > 0) { if (byteCount == 0) { if (!dbcsdecoder.MustFlush) { return(0); } decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(bytes, ptr4); byte[] bytes2 = new byte[] { dbcsdecoder.bLeftOver }; if (!decoderFallbackBuffer.InternalFallback(bytes2, bytes, ref chars)) { base.ThrowCharsOverflow(dbcsdecoder, true); } dbcsdecoder.bLeftOver = 0; return((int)((long)(chars - ptr3))); } else { int num = (int)dbcsdecoder.bLeftOver << 8; num |= (int)(*bytes); bytes++; char c = this.mapBytesToUnicode[num]; if (c == '\0' && num != 0) { decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(ptr2 - byteCount, ptr4); byte[] bytes3 = new byte[] { (byte)(num >> 8), (byte)num }; if (!decoderFallbackBuffer.InternalFallback(bytes3, bytes, ref chars)) { base.ThrowCharsOverflow(dbcsdecoder, true); } } else { if (chars >= ptr4) { base.ThrowCharsOverflow(dbcsdecoder, true); } *(chars++) = c; } } } while (bytes < ptr2) { int num2 = (int)(*bytes); bytes++; char c2 = this.mapBytesToUnicode[num2]; if (c2 == '') { if (bytes < ptr2) { num2 <<= 8; num2 |= (int)(*bytes); bytes++; c2 = this.mapBytesToUnicode[num2]; } else { if (dbcsdecoder != null && !dbcsdecoder.MustFlush) { flag = true; dbcsdecoder.bLeftOver = (byte)num2; break; } c2 = '\0'; } } if (c2 == '\0' && num2 != 0) { if (decoderFallbackBuffer == null) { if (dbcsdecoder == null) { decoderFallbackBuffer = base.DecoderFallback.CreateFallbackBuffer(); } else { decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; } decoderFallbackBuffer.InternalInitialize(ptr2 - byteCount, ptr4); } byte[] array; if (num2 < 256) { array = new byte[] { (byte)num2 }; } else { array = new byte[] { (byte)(num2 >> 8), (byte)num2 }; } if (!decoderFallbackBuffer.InternalFallback(array, bytes, ref chars)) { bytes -= array.Length; decoderFallbackBuffer.InternalReset(); base.ThrowCharsOverflow(dbcsdecoder, bytes == ptr); break; } } else { if (chars >= ptr4) { bytes--; if (num2 >= 256) { bytes--; } base.ThrowCharsOverflow(dbcsdecoder, bytes == ptr); break; } *(chars++) = c2; } } if (dbcsdecoder != null) { if (!flag) { dbcsdecoder.bLeftOver = 0; } dbcsdecoder.m_bytesUsed = (int)((long)(bytes - ptr)); } return((int)((long)(chars - ptr3))); }
internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder) { this.CheckMemorySection(); DBCSCodePageEncoding.DBCSDecoder dbcsDecoder = (DBCSCodePageEncoding.DBCSDecoder)baseDecoder; byte *numPtr1 = bytes; byte *numPtr2 = bytes + byteCount; char *chPtr = chars; char *charEnd = chars + charCount; bool flag = false; DecoderFallbackBuffer decoderFallbackBuffer = (DecoderFallbackBuffer)null; if (dbcsDecoder != null && (int)dbcsDecoder.bLeftOver > 0) { if (byteCount == 0) { if (!dbcsDecoder.MustFlush) { return(0); } DecoderFallbackBuffer fallbackBuffer = dbcsDecoder.FallbackBuffer; fallbackBuffer.InternalInitialize(bytes, charEnd); byte[] bytes1 = new byte[1] { dbcsDecoder.bLeftOver }; if (!fallbackBuffer.InternalFallback(bytes1, bytes, ref chars)) { this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, true); } dbcsDecoder.bLeftOver = (byte)0; return((int)(chars - chPtr)); } int index = (int)dbcsDecoder.bLeftOver << 8 | (int)*bytes; ++bytes; char ch = this.mapBytesToUnicode[index]; if ((int)ch == 0 && index != 0) { decoderFallbackBuffer = dbcsDecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(numPtr2 - byteCount, charEnd); byte[] bytes1 = new byte[2] { (byte)(index >> 8), (byte)index }; if (!decoderFallbackBuffer.InternalFallback(bytes1, bytes, ref chars)) { this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, true); } } else { if (chars >= charEnd) { this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, true); } *chars++ = ch; } } while (bytes < numPtr2) { int index = (int)*bytes; ++bytes; char ch = this.mapBytesToUnicode[index]; if ((int)ch == 65534) { if (bytes < numPtr2) { index = index << 8 | (int)*bytes; ++bytes; ch = this.mapBytesToUnicode[index]; } else if (dbcsDecoder == null || dbcsDecoder.MustFlush) { ch = char.MinValue; } else { flag = true; dbcsDecoder.bLeftOver = (byte)index; break; } } if ((int)ch == 0 && index != 0) { if (decoderFallbackBuffer == null) { decoderFallbackBuffer = dbcsDecoder != null ? dbcsDecoder.FallbackBuffer : this.DecoderFallback.CreateFallbackBuffer(); decoderFallbackBuffer.InternalInitialize(numPtr2 - byteCount, charEnd); } byte[] bytes1; if (index < 256) { bytes1 = new byte[1] { (byte)index } } ; else { bytes1 = new byte[2] { (byte)(index >> 8), (byte)index } }; if (!decoderFallbackBuffer.InternalFallback(bytes1, bytes, ref chars)) { bytes -= bytes1.Length; decoderFallbackBuffer.InternalReset(); this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, bytes == numPtr1); break; } } else { if (chars >= charEnd) { --bytes; if (index >= 256) { --bytes; } this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, bytes == numPtr1); break; } *chars++ = ch; } } if (dbcsDecoder != null) { if (!flag) { dbcsDecoder.bLeftOver = (byte)0; } dbcsDecoder.m_bytesUsed = (int)(bytes - numPtr1); } return((int)(chars - chPtr)); }
internal unsafe override int GetCharCount(byte *bytes, int count, DecoderNLS baseDecoder) { base.CheckMemorySection(); DBCSCodePageEncoding.DBCSDecoder dbcsdecoder = (DBCSCodePageEncoding.DBCSDecoder)baseDecoder; DecoderFallbackBuffer decoderFallbackBuffer = null; byte *ptr = bytes + count; int num = count; if (dbcsdecoder != null && dbcsdecoder.bLeftOver > 0) { if (count == 0) { if (!dbcsdecoder.MustFlush) { return(0); } decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(bytes, null); byte[] bytes2 = new byte[] { dbcsdecoder.bLeftOver }; return(decoderFallbackBuffer.InternalFallback(bytes2, bytes)); } else { int num2 = (int)dbcsdecoder.bLeftOver << 8; num2 |= (int)(*bytes); bytes++; if (this.mapBytesToUnicode[num2] == '\0' && num2 != 0) { num--; decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(ptr - count, null); byte[] bytes3 = new byte[] { (byte)(num2 >> 8), (byte)num2 }; num += decoderFallbackBuffer.InternalFallback(bytes3, bytes); } } } while (bytes < ptr) { int num3 = (int)(*bytes); bytes++; char c = this.mapBytesToUnicode[num3]; if (c == '') { num--; if (bytes < ptr) { num3 <<= 8; num3 |= (int)(*bytes); bytes++; c = this.mapBytesToUnicode[num3]; } else { if (dbcsdecoder != null && !dbcsdecoder.MustFlush) { break; } num++; c = '\0'; } } if (c == '\0' && num3 != 0) { if (decoderFallbackBuffer == null) { if (dbcsdecoder == null) { decoderFallbackBuffer = base.DecoderFallback.CreateFallbackBuffer(); } else { decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; } decoderFallbackBuffer.InternalInitialize(ptr - count, null); } num--; byte[] bytes4; if (num3 < 256) { bytes4 = new byte[] { (byte)num3 }; } else { bytes4 = new byte[] { (byte)(num3 >> 8), (byte)num3 }; } num += decoderFallbackBuffer.InternalFallback(bytes4, bytes); } } return(num); }
internal override unsafe int GetCharCount(byte *bytes, int count, DecoderNLS baseDecoder) { this.CheckMemorySection(); DBCSCodePageEncoding.DBCSDecoder dbcsDecoder = (DBCSCodePageEncoding.DBCSDecoder)baseDecoder; DecoderFallbackBuffer decoderFallbackBuffer = (DecoderFallbackBuffer)null; byte *numPtr = bytes + count; int num1 = count; if (dbcsDecoder != null && (int)dbcsDecoder.bLeftOver > 0) { if (count == 0) { if (!dbcsDecoder.MustFlush) { return(0); } DecoderFallbackBuffer fallbackBuffer = dbcsDecoder.FallbackBuffer; fallbackBuffer.InternalInitialize(bytes, (char *)null); byte[] bytes1 = new byte[1] { dbcsDecoder.bLeftOver }; return(fallbackBuffer.InternalFallback(bytes1, bytes)); } int index = (int)dbcsDecoder.bLeftOver << 8 | (int)*bytes; ++bytes; if ((int)this.mapBytesToUnicode[index] == 0 && index != 0) { int num2 = num1 - 1; decoderFallbackBuffer = dbcsDecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(numPtr - count, (char *)null); byte[] bytes1 = new byte[2] { (byte)(index >> 8), (byte)index }; num1 = num2 + decoderFallbackBuffer.InternalFallback(bytes1, bytes); } } while (bytes < numPtr) { int index = (int)*bytes; ++bytes; char ch = this.mapBytesToUnicode[index]; if ((int)ch == 65534) { --num1; if (bytes < numPtr) { index = index << 8 | (int)*bytes; ++bytes; ch = this.mapBytesToUnicode[index]; } else if (dbcsDecoder == null || dbcsDecoder.MustFlush) { ++num1; ch = char.MinValue; } else { break; } } if ((int)ch == 0 && index != 0) { if (decoderFallbackBuffer == null) { decoderFallbackBuffer = dbcsDecoder != null ? dbcsDecoder.FallbackBuffer : this.DecoderFallback.CreateFallbackBuffer(); decoderFallbackBuffer.InternalInitialize(numPtr - count, (char *)null); } int num2 = num1 - 1; byte[] bytes1; if (index < 256) { bytes1 = new byte[1] { (byte)index } } ; else { bytes1 = new byte[2] { (byte)(index >> 8), (byte)index } }; num1 = num2 + decoderFallbackBuffer.InternalFallback(bytes1, bytes); } } return(num1); }