コード例 #1
0
 public override void Reset()
 {
     // Reset
     currentMode = ISO2022Modes.ModeASCII;
     shiftInOutMode = ISO2022Modes.ModeASCII;
     charLeftOver = (char)0;
     if (m_fallbackBuffer != null)
         m_fallbackBuffer.Reset();                
 }
コード例 #2
0
 public override void Reset()
 {
     // Reset
     bytesLeftOverCount = 0;
     bytesLeftOver = new byte[4];
     currentMode = ISO2022Modes.ModeASCII;
     shiftInOutMode = ISO2022Modes.ModeASCII;
     if (m_fallbackBuffer != null)
         m_fallbackBuffer.Reset();                
 }
コード例 #3
0
        private unsafe int GetCharsCP52936(byte *bytes, int byteCount, char *chars, int charCount, ISO2022Decoder decoder)
        {
            Encoding.EncodingCharBuffer buffer = new Encoding.EncodingCharBuffer(this, decoder, chars, charCount, bytes, byteCount);
            ISO2022Modes modeASCII             = ISO2022Modes.ModeASCII;
            int          num  = -1;
            bool         flag = false;

            if (decoder != null)
            {
                modeASCII = decoder.currentMode;
                if (decoder.bytesLeftOverCount != 0)
                {
                    num = decoder.bytesLeftOver[0];
                }
            }
            while (buffer.MoreData || (num >= 0))
            {
                byte nextByte;
                if (num >= 0)
                {
                    nextByte = (byte)num;
                    num      = -1;
                }
                else
                {
                    nextByte = buffer.GetNextByte();
                }
                if (nextByte == 0x7e)
                {
                    if (!buffer.MoreData)
                    {
                        if ((decoder == null) || decoder.MustFlush)
                        {
                            buffer.Fallback(nextByte);
                        }
                        else
                        {
                            if (decoder != null)
                            {
                                decoder.ClearMustFlush();
                            }
                            if (chars != null)
                            {
                                decoder.bytesLeftOverCount = 1;
                                decoder.bytesLeftOver[0]   = 0x7e;
                                flag = true;
                            }
                        }
                        break;
                    }
                    nextByte = buffer.GetNextByte();
                    if ((nextByte == 0x7e) && (modeASCII == ISO2022Modes.ModeASCII))
                    {
                        if (buffer.AddChar((char)nextByte, 2))
                        {
                            continue;
                        }
                        break;
                    }
                    if (nextByte == 0x7b)
                    {
                        modeASCII = ISO2022Modes.ModeHZ;
                        continue;
                    }
                    if (nextByte == 0x7d)
                    {
                        modeASCII = ISO2022Modes.ModeASCII;
                        continue;
                    }
                    if (nextByte == 10)
                    {
                        continue;
                    }
                    buffer.AdjustBytes(-1);
                    nextByte = 0x7e;
                }
                if ((modeASCII != ISO2022Modes.ModeASCII) && (nextByte >= 0x20))
                {
                    if (!buffer.MoreData)
                    {
                        if ((decoder == null) || decoder.MustFlush)
                        {
                            buffer.Fallback(nextByte);
                        }
                        else
                        {
                            if (decoder != null)
                            {
                                decoder.ClearMustFlush();
                            }
                            if (chars != null)
                            {
                                decoder.bytesLeftOverCount = 1;
                                decoder.bytesLeftOver[0]   = nextByte;
                                flag = true;
                            }
                        }
                    }
                    else
                    {
                        char   ch;
                        byte   num3  = buffer.GetNextByte();
                        ushort index = (ushort)((nextByte << 8) | num3);
                        if ((nextByte == 0x20) && (num3 != 0))
                        {
                            ch = (char)num3;
                        }
                        else
                        {
                            if ((((nextByte < 0x21) || (nextByte > 0x77)) || ((num3 < 0x21) || (num3 > 0x7e))) && (((nextByte < 0xa1) || (nextByte > 0xf7)) || ((num3 < 0xa1) || (num3 > 0xfe))))
                            {
                                if (((num3 == 0x20) && (0x21 <= nextByte)) && (nextByte <= 0x7d))
                                {
                                    index = 0x2121;
                                }
                                else
                                {
                                    if (buffer.Fallback((byte)(index >> 8), (byte)index))
                                    {
                                        continue;
                                    }
                                    break;
                                }
                            }
                            index = (ushort)(index | 0x8080);
                            ch    = base.mapBytesToUnicode[index];
                        }
                        if ((ch == '\0') && (index != 0))
                        {
                            if (buffer.Fallback((byte)(index >> 8), (byte)index))
                            {
                                continue;
                            }
                        }
                        else if (buffer.AddChar(ch, 2))
                        {
                            continue;
                        }
                    }
                    break;
                }
                char ch2 = base.mapBytesToUnicode[nextByte];
                if (((ch2 == '\0') || (ch2 == '\0')) && (nextByte != 0))
                {
                    if (buffer.Fallback(nextByte))
                    {
                        continue;
                    }
                    break;
                }
                if (!buffer.AddChar(ch2))
                {
                    break;
                }
            }
            if ((chars != null) && (decoder != null))
            {
                if (!flag)
                {
                    decoder.bytesLeftOverCount = 0;
                }
                if (decoder.MustFlush && (decoder.bytesLeftOverCount == 0))
                {
                    decoder.currentMode = ISO2022Modes.ModeASCII;
                }
                else
                {
                    decoder.currentMode = modeASCII;
                }
                decoder.m_bytesUsed = buffer.BytesUsed;
            }
            return(buffer.Count);
        }
コード例 #4
0
        private unsafe int GetCharsCP5022xJP(byte *bytes, int byteCount, char *chars, int charCount, ISO2022Decoder decoder)
        {
            Encoding.EncodingCharBuffer buffer = new Encoding.EncodingCharBuffer(this, decoder, chars, charCount, bytes, byteCount);
            ISO2022Modes modeASCII             = ISO2022Modes.ModeASCII;
            ISO2022Modes shiftInOutMode        = ISO2022Modes.ModeASCII;

            byte[] buffer2     = new byte[4];
            int    escapeCount = 0;

            if (decoder != null)
            {
                modeASCII      = decoder.currentMode;
                shiftInOutMode = decoder.shiftInOutMode;
                escapeCount    = decoder.bytesLeftOverCount;
                for (int i = 0; i < escapeCount; i++)
                {
                    buffer2[i] = decoder.bytesLeftOver[i];
                }
            }
            while (buffer.MoreData || (escapeCount > 0))
            {
                byte nextByte;
                if (escapeCount > 0)
                {
                    if (buffer2[0] == 0x1b)
                    {
                        if (!buffer.MoreData)
                        {
                            if ((decoder != null) && !decoder.MustFlush)
                            {
                                break;
                            }
                        }
                        else
                        {
                            buffer2[escapeCount++] = buffer.GetNextByte();
                            ISO2022Modes modes3 = this.CheckEscapeSequenceJP(buffer2, escapeCount);
                            if (modes3 != ISO2022Modes.ModeInvalidEscape)
                            {
                                if (modes3 != ISO2022Modes.ModeIncompleteEscape)
                                {
                                    escapeCount = 0;
                                    modeASCII   = shiftInOutMode = modes3;
                                }
                                continue;
                            }
                        }
                    }
                    nextByte = this.DecrementEscapeBytes(ref buffer2, ref escapeCount);
                }
                else
                {
                    nextByte = buffer.GetNextByte();
                    if (nextByte == 0x1b)
                    {
                        if (escapeCount == 0)
                        {
                            buffer2[0]  = nextByte;
                            escapeCount = 1;
                            continue;
                        }
                        buffer.AdjustBytes(-1);
                    }
                }
                if (nextByte == 14)
                {
                    shiftInOutMode = modeASCII;
                    modeASCII      = ISO2022Modes.ModeHalfwidthKatakana;
                }
                else
                {
                    if (nextByte == 15)
                    {
                        modeASCII = shiftInOutMode;
                        continue;
                    }
                    ushort index = nextByte;
                    bool   flag  = false;
                    if (modeASCII == ISO2022Modes.ModeJIS0208)
                    {
                        if (escapeCount > 0)
                        {
                            if (buffer2[0] != 0x1b)
                            {
                                index = (ushort)(index << 8);
                                index = (ushort)(index | this.DecrementEscapeBytes(ref buffer2, ref escapeCount));
                                flag  = true;
                            }
                        }
                        else if (buffer.MoreData)
                        {
                            index = (ushort)(index << 8);
                            index = (ushort)(index | buffer.GetNextByte());
                            flag  = true;
                        }
                        else
                        {
                            if ((decoder == null) || decoder.MustFlush)
                            {
                                buffer.Fallback(nextByte);
                            }
                            else if (chars != null)
                            {
                                buffer2[0]  = nextByte;
                                escapeCount = 1;
                            }
                            break;
                        }
                        if (flag && ((index & 0xff00) == 0x2a00))
                        {
                            index = (ushort)(index & 0xff);
                            index = (ushort)(index | 0x1000);
                        }
                    }
                    else if ((index >= 0xa1) && (index <= 0xdf))
                    {
                        index = (ushort)(index | 0x1000);
                        index = (ushort)(index & 0xff7f);
                    }
                    else if (modeASCII == ISO2022Modes.ModeHalfwidthKatakana)
                    {
                        index = (ushort)(index | 0x1000);
                    }
                    char ch = base.mapBytesToUnicode[index];
                    if ((ch == '\0') && (index != 0))
                    {
                        if (flag)
                        {
                            if (buffer.Fallback((byte)(index >> 8), (byte)index))
                            {
                                continue;
                            }
                        }
                        else if (buffer.Fallback(nextByte))
                        {
                            continue;
                        }
                        break;
                    }
                    if (!buffer.AddChar(ch, flag ? 2 : 1))
                    {
                        break;
                    }
                }
            }
            if ((chars != null) && (decoder != null))
            {
                if (!decoder.MustFlush || (escapeCount != 0))
                {
                    decoder.currentMode        = modeASCII;
                    decoder.shiftInOutMode     = shiftInOutMode;
                    decoder.bytesLeftOverCount = escapeCount;
                    decoder.bytesLeftOver      = buffer2;
                }
                else
                {
                    decoder.currentMode        = ISO2022Modes.ModeASCII;
                    decoder.shiftInOutMode     = ISO2022Modes.ModeASCII;
                    decoder.bytesLeftOverCount = 0;
                }
                decoder.m_bytesUsed = buffer.BytesUsed;
            }
            return(buffer.Count);
        }
コード例 #5
0
        private unsafe int GetBytesCP52936(char *chars, int charCount, byte *bytes, int byteCount, ISO2022Encoder encoder)
        {
            Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount);
            ISO2022Modes modeASCII             = ISO2022Modes.ModeASCII;

            if (encoder != null)
            {
                char charLeftOver = encoder.charLeftOver;
                modeASCII = encoder.currentMode;
                if (charLeftOver > '\0')
                {
                    buffer.Fallback(charLeftOver);
                }
            }
            while (buffer.MoreData)
            {
                char   nextChar = buffer.GetNextChar();
                ushort num      = base.mapUnicodeToBytes[nextChar];
                if ((num == 0) && (nextChar != '\0'))
                {
                    buffer.Fallback(nextChar);
                }
                else
                {
                    byte num2 = (byte)(num >> 8);
                    byte num3 = (byte)(num & 0xff);
                    if (((num2 != 0) && (((num2 < 0xa1) || (num2 > 0xf7)) || ((num3 < 0xa1) || (num3 > 0xfe)))) || (((num2 == 0) && (num3 > 0x80)) && (num3 != 0xff)))
                    {
                        buffer.Fallback(nextChar);
                        continue;
                    }
                    if (num2 != 0)
                    {
                        if (modeASCII != ISO2022Modes.ModeHZ)
                        {
                            if (!buffer.AddByte(0x7e, 0x7b, 2))
                            {
                                break;
                            }
                            modeASCII = ISO2022Modes.ModeHZ;
                        }
                        if (buffer.AddByte((byte)(num2 & 0x7f), (byte)(num3 & 0x7f)))
                        {
                            continue;
                        }
                        break;
                    }
                    if (modeASCII != ISO2022Modes.ModeASCII)
                    {
                        if (!buffer.AddByte(0x7e, 0x7d, (num3 == 0x7e) ? 2 : 1))
                        {
                            break;
                        }
                        modeASCII = ISO2022Modes.ModeASCII;
                    }
                    if (((num3 == 0x7e) && !buffer.AddByte(0x7e, 1)) || !buffer.AddByte(num3))
                    {
                        break;
                    }
                }
            }
            if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush))
            {
                if (buffer.AddByte(0x7e, (byte)0x7d))
                {
                    modeASCII = ISO2022Modes.ModeASCII;
                }
                else
                {
                    buffer.GetNextChar();
                }
            }
            if ((encoder != null) && (bytes != null))
            {
                encoder.currentMode = modeASCII;
                if (!buffer.fallbackBuffer.bUsedEncoder)
                {
                    encoder.charLeftOver = '\0';
                }
                encoder.m_charsUsed = buffer.CharsUsed;
            }
            return(buffer.Count);
        }
コード例 #6
0
        private unsafe int GetBytesCP5022xJP(char *chars, int charCount, byte *bytes, int byteCount, ISO2022Encoder encoder)
        {
            Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount);
            ISO2022Modes modeASCII             = ISO2022Modes.ModeASCII;
            ISO2022Modes shiftInOutMode        = ISO2022Modes.ModeASCII;

            if (encoder != null)
            {
                char charLeftOver = encoder.charLeftOver;
                modeASCII      = encoder.currentMode;
                shiftInOutMode = encoder.shiftInOutMode;
                if (charLeftOver > '\0')
                {
                    buffer.Fallback(charLeftOver);
                }
            }
            while (buffer.MoreData)
            {
                byte   num2;
                byte   num3;
                char   nextChar = buffer.GetNextChar();
                ushort num      = base.mapUnicodeToBytes[nextChar];
                while (true)
                {
                    num2 = (byte)(num >> 8);
                    num3 = (byte)(num & 0xff);
                    if (num2 != 0x10)
                    {
                        goto Label_010A;
                    }
                    if (this.CodePage != 0xc42c)
                    {
                        break;
                    }
                    if ((num3 < 0x21) || (num3 >= (0x21 + HalfToFullWidthKanaTable.Length)))
                    {
                        buffer.Fallback(nextChar);
                        continue;
                    }
                    num = (ushort)(HalfToFullWidthKanaTable[num3 - 0x21] & 0x7f7f);
                }
                if (modeASCII != ISO2022Modes.ModeHalfwidthKatakana)
                {
                    if (this.CodePage == 0xc42e)
                    {
                        if (!buffer.AddByte(14))
                        {
                            break;
                        }
                        shiftInOutMode = modeASCII;
                        modeASCII      = ISO2022Modes.ModeHalfwidthKatakana;
                    }
                    else
                    {
                        if (!buffer.AddByte(0x1b, 40, (byte)0x49))
                        {
                            break;
                        }
                        modeASCII = ISO2022Modes.ModeHalfwidthKatakana;
                    }
                }
                if (buffer.AddByte((byte)(num3 & 0x7f)))
                {
                    continue;
                }
                break;
Label_010A:
                if (num2 != 0)
                {
                    if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana))
                    {
                        if (!buffer.AddByte(15))
                        {
                            break;
                        }
                        modeASCII = shiftInOutMode;
                    }
                    if (modeASCII != ISO2022Modes.ModeJIS0208)
                    {
                        if (!buffer.AddByte(0x1b, 0x24, (byte)0x42))
                        {
                            break;
                        }
                        modeASCII = ISO2022Modes.ModeJIS0208;
                    }
                    if (buffer.AddByte(num2, num3))
                    {
                        continue;
                    }
                    break;
                }
                if ((num != 0) || (nextChar == '\0'))
                {
                    if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana))
                    {
                        if (!buffer.AddByte(15))
                        {
                            break;
                        }
                        modeASCII = shiftInOutMode;
                    }
                    if (modeASCII != ISO2022Modes.ModeASCII)
                    {
                        if (!buffer.AddByte(0x1b, 40, (byte)0x42))
                        {
                            break;
                        }
                        modeASCII = ISO2022Modes.ModeASCII;
                    }
                    if (buffer.AddByte(num3))
                    {
                        continue;
                    }
                    break;
                }
                buffer.Fallback(nextChar);
            }
            if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush))
            {
                if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana))
                {
                    if (buffer.AddByte(15))
                    {
                        modeASCII = shiftInOutMode;
                    }
                    else
                    {
                        buffer.GetNextChar();
                    }
                }
                if ((modeASCII != ISO2022Modes.ModeASCII) && ((this.CodePage != 0xc42e) || (modeASCII != ISO2022Modes.ModeHalfwidthKatakana)))
                {
                    if (buffer.AddByte(0x1b, 40, (byte)0x42))
                    {
                        modeASCII = ISO2022Modes.ModeASCII;
                    }
                    else
                    {
                        buffer.GetNextChar();
                    }
                }
            }
            if ((bytes != null) && (encoder != null))
            {
                encoder.currentMode    = modeASCII;
                encoder.shiftInOutMode = shiftInOutMode;
                if (!buffer.fallbackBuffer.bUsedEncoder)
                {
                    encoder.charLeftOver = '\0';
                }
                encoder.m_charsUsed = buffer.CharsUsed;
            }
            return(buffer.Count);
        }
コード例 #7
0
        private unsafe int GetBytesCP50225KR(char *chars, int charCount, byte *bytes, int byteCount, ISO2022Encoder encoder)
        {
            Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount);
            ISO2022Modes modeASCII             = ISO2022Modes.ModeASCII;
            ISO2022Modes shiftInOutMode        = ISO2022Modes.ModeASCII;

            if (encoder != null)
            {
                char charLeftOver = encoder.charLeftOver;
                modeASCII      = encoder.currentMode;
                shiftInOutMode = encoder.shiftInOutMode;
                if (charLeftOver > '\0')
                {
                    buffer.Fallback(charLeftOver);
                }
            }
            while (buffer.MoreData)
            {
                char   nextChar = buffer.GetNextChar();
                ushort num      = base.mapUnicodeToBytes[nextChar];
                byte   num2     = (byte)(num >> 8);
                byte   num3     = (byte)(num & 0xff);
                if (num2 != 0)
                {
                    if (shiftInOutMode != ISO2022Modes.ModeKR)
                    {
                        if (!buffer.AddByte(0x1b, 0x24, 0x29, (byte)0x43))
                        {
                            break;
                        }
                        shiftInOutMode = ISO2022Modes.ModeKR;
                    }
                    if (modeASCII != ISO2022Modes.ModeKR)
                    {
                        if (!buffer.AddByte(14))
                        {
                            break;
                        }
                        modeASCII = ISO2022Modes.ModeKR;
                    }
                    if (buffer.AddByte(num2, num3))
                    {
                        continue;
                    }
                    break;
                }
                if ((num != 0) || (nextChar == '\0'))
                {
                    if (modeASCII != ISO2022Modes.ModeASCII)
                    {
                        if (!buffer.AddByte(15))
                        {
                            break;
                        }
                        modeASCII = ISO2022Modes.ModeASCII;
                    }
                    if (buffer.AddByte(num3))
                    {
                        continue;
                    }
                    break;
                }
                buffer.Fallback(nextChar);
            }
            if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush))
            {
                if (buffer.AddByte(15))
                {
                    modeASCII = ISO2022Modes.ModeASCII;
                }
                else
                {
                    buffer.GetNextChar();
                }
            }
            if ((bytes != null) && (encoder != null))
            {
                if (!buffer.fallbackBuffer.bUsedEncoder)
                {
                    encoder.charLeftOver = '\0';
                }
                encoder.currentMode = modeASCII;
                if (!encoder.MustFlush || (encoder.charLeftOver != '\0'))
                {
                    encoder.shiftInOutMode = shiftInOutMode;
                }
                else
                {
                    encoder.shiftInOutMode = ISO2022Modes.ModeASCII;
                }
                encoder.m_charsUsed = buffer.CharsUsed;
            }
            return(buffer.Count);
        }