コード例 #1
0
ファイル: isciiencoding.cs プロジェクト: wwkkww1983/ZJCredit
        internal override unsafe int GetBytes(char *chars, int charCount, byte *bytes, int byteCount, EncoderNLS baseEncoder)
        {
            ISCIIEncoding.ISCIIEncoder  isciiEncoder       = (ISCIIEncoding.ISCIIEncoder)baseEncoder;
            Encoding.EncodingByteBuffer encodingByteBuffer = new Encoding.EncodingByteBuffer((Encoding)this, (EncoderNLS)isciiEncoder, bytes, byteCount, chars, charCount);
            int  num1 = this.defaultCodePage;
            bool flag = false;

            if (isciiEncoder != null)
            {
                num1 = isciiEncoder.currentCodePage;
                flag = isciiEncoder.bLastVirama;
                if ((int)isciiEncoder.charLeftOver > 0)
                {
                    encodingByteBuffer.Fallback(isciiEncoder.charLeftOver);
                    flag = false;
                }
            }
            while (encodingByteBuffer.MoreData)
            {
                char nextChar = encodingByteBuffer.GetNextChar();
                if ((int)nextChar < 160)
                {
                    if (encodingByteBuffer.AddByte((byte)nextChar))
                    {
                        flag = false;
                    }
                    else
                    {
                        break;
                    }
                }
                else if ((int)nextChar < 2305 || (int)nextChar > 3439)
                {
                    if (flag && ((int)nextChar == 8204 || (int)nextChar == 8205))
                    {
                        if ((int)nextChar == 8204)
                        {
                            if (!encodingByteBuffer.AddByte((byte)232))
                            {
                                break;
                            }
                        }
                        else if (!encodingByteBuffer.AddByte((byte)233))
                        {
                            break;
                        }
                        flag = false;
                    }
                    else
                    {
                        encodingByteBuffer.Fallback(nextChar);
                        flag = false;
                    }
                }
                else
                {
                    int  num2 = ISCIIEncoding.UnicodeToIndicChar[(int)nextChar - 2305];
                    byte b    = (byte)num2;
                    int  num3 = 15 & num2 >> 8;
                    int  num4 = 61440 & num2;
                    if (num2 == 0)
                    {
                        encodingByteBuffer.Fallback(nextChar);
                        flag = false;
                    }
                    else
                    {
                        if (num3 != num1)
                        {
                            if (encodingByteBuffer.AddByte((byte)239, (byte)(num3 | 64)))
                            {
                                num1 = num3;
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (encodingByteBuffer.AddByte(b, num4 != 0 ? 1 : 0))
                        {
                            flag = (int)b == 232;
                            if (num4 != 0 && !encodingByteBuffer.AddByte(ISCIIEncoding.SecondIndicByte[num4 >> 12]))
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            if (num1 != this.defaultCodePage && (isciiEncoder == null || isciiEncoder.MustFlush))
            {
                if (encodingByteBuffer.AddByte((byte)239, (byte)(this.defaultCodePage | 64)))
                {
                    num1 = this.defaultCodePage;
                }
                else
                {
                    int num2 = (int)encodingByteBuffer.GetNextChar();
                }
                flag = false;
            }
            if (isciiEncoder != null && (IntPtr)bytes != IntPtr.Zero)
            {
                if (!encodingByteBuffer.fallbackBuffer.bUsedEncoder)
                {
                    isciiEncoder.charLeftOver = char.MinValue;
                }
                isciiEncoder.currentCodePage = num1;
                isciiEncoder.bLastVirama     = flag;
                isciiEncoder.m_charsUsed     = encodingByteBuffer.CharsUsed;
            }
            return(encodingByteBuffer.Count);
        }