internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder) { GB18030Encoding.GB18030Decoder gb18030Decoder = (GB18030Encoding.GB18030Decoder)baseDecoder; Encoding.EncodingCharBuffer encodingCharBuffer = new Encoding.EncodingCharBuffer((Encoding)this, (DecoderNLS)gb18030Decoder, chars, charCount, bytes, byteCount); short num1 = -1; short num2 = -1; short num3 = -1; short num4 = -1; if (gb18030Decoder != null && (int)gb18030Decoder.bLeftOver1 != -1) { num1 = gb18030Decoder.bLeftOver1; num2 = gb18030Decoder.bLeftOver2; num3 = gb18030Decoder.bLeftOver3; num4 = gb18030Decoder.bLeftOver4; while ((int)num1 != -1) { if (!this.IsGBLeadByte(num1)) { if ((int)num1 <= (int)sbyte.MaxValue) { if (!encodingCharBuffer.AddChar((char)num1)) { break; } } else if (!encodingCharBuffer.Fallback((byte)num1)) { break; } num1 = num2; num2 = num3; num3 = num4; num4 = (short)-1; } else { while ((int)num2 == -1 || this.IsGBFourByteTrailing(num2) && (int)num4 == -1) { if (!encodingCharBuffer.MoreData) { if (!gb18030Decoder.MustFlush) { if ((IntPtr)chars != IntPtr.Zero) { gb18030Decoder.bLeftOver1 = num1; gb18030Decoder.bLeftOver2 = num2; gb18030Decoder.bLeftOver3 = num3; gb18030Decoder.bLeftOver4 = num4; } gb18030Decoder.m_bytesUsed = encodingCharBuffer.BytesUsed; return(encodingCharBuffer.Count); } break; } if ((int)num2 == -1) { num2 = (short)encodingCharBuffer.GetNextByte(); } else if ((int)num3 == -1) { num3 = (short)encodingCharBuffer.GetNextByte(); } else { num4 = (short)encodingCharBuffer.GetNextByte(); } } if (this.IsGBTwoByteTrailing(num2)) { int index = (int)num1 << 8 | (int)(byte)num2; if (encodingCharBuffer.AddChar(this.mapBytesToUnicode[index], 2)) { num1 = (short)-1; num2 = (short)-1; } else { break; } } else if (this.IsGBFourByteTrailing(num2) && this.IsGBLeadByte(num3) && this.IsGBFourByteTrailing(num4)) { int fourBytesOffset = this.GetFourBytesOffset(num1, num2, num3, num4); if (fourBytesOffset <= 39419) { if (!encodingCharBuffer.AddChar(this.map4BytesToUnicode[fourBytesOffset], 4)) { break; } } else if (fourBytesOffset >= 189000 && fourBytesOffset <= 1237575) { int num5 = fourBytesOffset - 189000; if (!encodingCharBuffer.AddChar((char)(55296 + num5 / 1024), (char)(56320 + num5 % 1024), 4)) { break; } } else if (!encodingCharBuffer.Fallback((byte)num1, (byte)num2, (byte)num3, (byte)num4)) { break; } num1 = (short)-1; num2 = (short)-1; num3 = (short)-1; num4 = (short)-1; } else if (encodingCharBuffer.Fallback((byte)num1)) { num1 = num2; num2 = num3; num3 = num4; num4 = (short)-1; } else { break; } } } } while (encodingCharBuffer.MoreData) { byte nextByte1 = encodingCharBuffer.GetNextByte(); if ((int)nextByte1 <= (int)sbyte.MaxValue) { if (!encodingCharBuffer.AddChar((char)nextByte1)) { break; } } else if (this.IsGBLeadByte((short)nextByte1)) { if (encodingCharBuffer.MoreData) { byte nextByte2 = encodingCharBuffer.GetNextByte(); if (this.IsGBTwoByteTrailing((short)nextByte2)) { int index = (int)nextByte1 << 8 | (int)nextByte2; if (!encodingCharBuffer.AddChar(this.mapBytesToUnicode[index], 2)) { break; } } else if (this.IsGBFourByteTrailing((short)nextByte2)) { if (encodingCharBuffer.EvenMoreData(2)) { byte nextByte3 = encodingCharBuffer.GetNextByte(); byte nextByte4 = encodingCharBuffer.GetNextByte(); if (this.IsGBLeadByte((short)nextByte3) && this.IsGBFourByteTrailing((short)nextByte4)) { int fourBytesOffset = this.GetFourBytesOffset((short)nextByte1, (short)nextByte2, (short)nextByte3, (short)nextByte4); if (fourBytesOffset <= 39419) { if (!encodingCharBuffer.AddChar(this.map4BytesToUnicode[fourBytesOffset], 4)) { break; } } else if (fourBytesOffset >= 189000 && fourBytesOffset <= 1237575) { int num5 = fourBytesOffset - 189000; if (!encodingCharBuffer.AddChar((char)(55296 + num5 / 1024), (char)(56320 + num5 % 1024), 4)) { break; } } else if (!encodingCharBuffer.Fallback(nextByte1, nextByte2, nextByte3, nextByte4)) { break; } } else { encodingCharBuffer.AdjustBytes(-3); if (!encodingCharBuffer.Fallback(nextByte1)) { break; } } } else { if (gb18030Decoder != null && !gb18030Decoder.MustFlush) { if ((IntPtr)chars != IntPtr.Zero) { num1 = (short)nextByte1; num2 = (short)nextByte2; num3 = !encodingCharBuffer.MoreData ? (short)-1 : (short)encodingCharBuffer.GetNextByte(); num4 = (short)-1; break; } break; } if (!encodingCharBuffer.Fallback(nextByte1, nextByte2)) { break; } } } else { encodingCharBuffer.AdjustBytes(-1); if (!encodingCharBuffer.Fallback(nextByte1)) { break; } } } else { if (gb18030Decoder != null && !gb18030Decoder.MustFlush) { if ((IntPtr)chars != IntPtr.Zero) { num1 = (short)nextByte1; num2 = (short)-1; num3 = (short)-1; num4 = (short)-1; break; } break; } if (!encodingCharBuffer.Fallback(nextByte1)) { break; } } } else if (!encodingCharBuffer.Fallback(nextByte1)) { break; } } if (gb18030Decoder != null) { if ((IntPtr)chars != IntPtr.Zero) { gb18030Decoder.bLeftOver1 = num1; gb18030Decoder.bLeftOver2 = num2; gb18030Decoder.bLeftOver3 = num3; gb18030Decoder.bLeftOver4 = num4; } gb18030Decoder.m_bytesUsed = encodingCharBuffer.BytesUsed; } return(encodingCharBuffer.Count); }
internal unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder) { GB18030Encoding.GB18030Decoder gb18030Decoder = (GB18030Encoding.GB18030Decoder)baseDecoder; Encoding.EncodingCharBuffer encodingCharBuffer = new Encoding.EncodingCharBuffer(this, gb18030Decoder, chars, charCount, bytes, byteCount); short num = -1; short num2 = -1; short num3 = -1; short num4 = -1; if (gb18030Decoder != null && gb18030Decoder.bLeftOver1 != -1) { num = gb18030Decoder.bLeftOver1; num2 = gb18030Decoder.bLeftOver2; num3 = gb18030Decoder.bLeftOver3; num4 = gb18030Decoder.bLeftOver4; while (num != -1) { if (!this.IsGBLeadByte(num)) { if (num <= 127) { if (!encodingCharBuffer.AddChar((char)num)) { break; } } else if (!encodingCharBuffer.Fallback((byte)num)) { break; } num = num2; num2 = num3; num3 = num4; num4 = -1; } else { while (num2 == -1 || (this.IsGBFourByteTrailing(num2) && num4 == -1)) { if (!encodingCharBuffer.MoreData) { if (!gb18030Decoder.MustFlush) { if (chars != null) { gb18030Decoder.bLeftOver1 = num; gb18030Decoder.bLeftOver2 = num2; gb18030Decoder.bLeftOver3 = num3; gb18030Decoder.bLeftOver4 = num4; } gb18030Decoder.m_bytesUsed = encodingCharBuffer.BytesUsed; return(encodingCharBuffer.Count); } break; } else if (num2 == -1) { num2 = (short)encodingCharBuffer.GetNextByte(); } else if (num3 == -1) { num3 = (short)encodingCharBuffer.GetNextByte(); } else { num4 = (short)encodingCharBuffer.GetNextByte(); } } if (this.IsGBTwoByteTrailing(num2)) { int num5 = (int)num << 8; num5 |= (int)((byte)num2); if (!encodingCharBuffer.AddChar(this.mapBytesToUnicode[num5], 2)) { break; } num = -1; num2 = -1; } else if (this.IsGBFourByteTrailing(num2) && this.IsGBLeadByte(num3) && this.IsGBFourByteTrailing(num4)) { int num6 = this.GetFourBytesOffset(num, num2, num3, num4); if (num6 <= 39419) { if (!encodingCharBuffer.AddChar(this.map4BytesToUnicode[num6], 4)) { break; } } else if (num6 >= 189000 && num6 <= 1237575) { num6 -= 189000; if (!encodingCharBuffer.AddChar((char)(55296 + num6 / 1024), (char)(56320 + num6 % 1024), 4)) { break; } } else if (!encodingCharBuffer.Fallback((byte)num, (byte)num2, (byte)num3, (byte)num4)) { break; } num = -1; num2 = -1; num3 = -1; num4 = -1; } else { if (!encodingCharBuffer.Fallback((byte)num)) { break; } num = num2; num2 = num3; num3 = num4; num4 = -1; } } } } while (encodingCharBuffer.MoreData) { byte nextByte = encodingCharBuffer.GetNextByte(); if (nextByte <= 127) { if (!encodingCharBuffer.AddChar((char)nextByte)) { break; } } else if (this.IsGBLeadByte((short)nextByte)) { if (encodingCharBuffer.MoreData) { byte nextByte2 = encodingCharBuffer.GetNextByte(); if (this.IsGBTwoByteTrailing((short)nextByte2)) { int num7 = (int)nextByte << 8; num7 |= (int)nextByte2; if (!encodingCharBuffer.AddChar(this.mapBytesToUnicode[num7], 2)) { break; } } else if (this.IsGBFourByteTrailing((short)nextByte2)) { if (encodingCharBuffer.EvenMoreData(2)) { byte nextByte3 = encodingCharBuffer.GetNextByte(); byte nextByte4 = encodingCharBuffer.GetNextByte(); if (this.IsGBLeadByte((short)nextByte3) && this.IsGBFourByteTrailing((short)nextByte4)) { int num8 = this.GetFourBytesOffset((short)nextByte, (short)nextByte2, (short)nextByte3, (short)nextByte4); if (num8 <= 39419) { if (!encodingCharBuffer.AddChar(this.map4BytesToUnicode[num8], 4)) { break; } } else if (num8 >= 189000 && num8 <= 1237575) { num8 -= 189000; if (!encodingCharBuffer.AddChar((char)(55296 + num8 / 1024), (char)(56320 + num8 % 1024), 4)) { break; } } else if (!encodingCharBuffer.Fallback(nextByte, nextByte2, nextByte3, nextByte4)) { break; } } else { encodingCharBuffer.AdjustBytes(-3); if (!encodingCharBuffer.Fallback(nextByte)) { break; } } } else if (gb18030Decoder != null && !gb18030Decoder.MustFlush) { if (chars != null) { num = (short)nextByte; num2 = (short)nextByte2; if (encodingCharBuffer.MoreData) { num3 = (short)encodingCharBuffer.GetNextByte(); } else { num3 = -1; } num4 = -1; break; } break; } else if (!encodingCharBuffer.Fallback(nextByte, nextByte2)) { break; } } else { encodingCharBuffer.AdjustBytes(-1); if (!encodingCharBuffer.Fallback(nextByte)) { break; } } } else if (gb18030Decoder != null && !gb18030Decoder.MustFlush) { if (chars != null) { num = (short)nextByte; num2 = -1; num3 = -1; num4 = -1; break; } break; } else if (!encodingCharBuffer.Fallback(nextByte)) { break; } } else if (!encodingCharBuffer.Fallback(nextByte)) { break; } } if (gb18030Decoder != null) { if (chars != null) { gb18030Decoder.bLeftOver1 = num; gb18030Decoder.bLeftOver2 = num2; gb18030Decoder.bLeftOver3 = num3; gb18030Decoder.bLeftOver4 = num4; } gb18030Decoder.m_bytesUsed = encodingCharBuffer.BytesUsed; } return(encodingCharBuffer.Count); }