Пример #1
0
        private int GetCharCount(byte[] bytes, int index, int count, DBCSDecoder decoder)
        {
            int    charCount = 0;
            ushort u;
            char   c;

            for (int i = 0; i < count; index++, charCount++, i++)
            {
                u = 0;
                if (decoder != null && decoder.pendingByte != 0)
                {
                    u = decoder.pendingByte;
                    decoder.pendingByte = 0;
                }

                u = (ushort)(u << 8 | bytes[index]);
                c = _dbcsToUnicode[u];
                if (c == LEAD_BYTE_CHAR)
                {
                    if (i < count - 1)
                    {
                        index++;
                        i++;
                    }
                    else if (decoder != null)
                    {
                        decoder.pendingByte = bytes[index];
                        return(charCount);
                    }
                }
            }

            return(charCount);
        }
Пример #2
0
        private int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, DBCSDecoder decoder)
        {
            int    charCount = 0;
            ushort u;
            char   c;

            for (int i = 0; i < byteCount; byteIndex++, charIndex++, charCount++, i++)
            {
                u = 0;
                if (decoder != null && decoder.pendingByte != 0)
                {
                    u = decoder.pendingByte;
                    decoder.pendingByte = 0;
                }

                u = (ushort)(u << 8 | bytes[byteIndex]);
                c = _dbcsToUnicode[u];
                if (c == LEAD_BYTE_CHAR)
                {
                    if (i < byteCount - 1)
                    {
                        byteIndex++;
                        i++;
                        u = (ushort)(u << 8 | bytes[byteIndex]);
                        c = _dbcsToUnicode[u];
                    }
                    else if (decoder == null)
                    {
                        c = '\0';
                    }
                    else
                    {
                        decoder.pendingByte = bytes[byteIndex];
                        return(charCount);
                    }
                }
                if (c == 0 && u != 0)
                {
                    chars[charIndex] = '?';
                }
                else
                {
                    chars[charIndex] = c;
                }
            }

            return(charCount);
        }
Пример #3
0
        private int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, DBCSDecoder decoder)
        {
            int charCount = 0;
            ushort u;
            char c;

            for (int i = 0; i < byteCount; byteIndex++, charIndex++, charCount++, i++)
            {
                u = 0;
                if (decoder != null && decoder.pendingByte != 0)
                {
                    u = decoder.pendingByte;
                    decoder.pendingByte = 0;
                }

                u = (ushort)(u << 8 | bytes[byteIndex]);
                c = _dbcsToUnicode[u];
                if (c == LEAD_BYTE_CHAR)
                {
                    if (i < byteCount - 1)
                    {
                        byteIndex++;
                        i++;
                        u = (ushort)(u << 8 | bytes[byteIndex]);
                        c = _dbcsToUnicode[u];
                    }
                    else if (decoder == null)
                    {
                        c = '\0';
                    }
                    else
                    {
                        decoder.pendingByte = bytes[byteIndex];
                        return charCount;
                    }
                }
                if (c == 0 && u != 0)
                    chars[charIndex] = '?';
                else
                    chars[charIndex] = c;
            }

            return charCount;
        }
Пример #4
0
        private int GetCharCount(byte[] bytes, int index, int count, DBCSDecoder decoder)
        {
            int charCount = 0;
            ushort u;
            char c;

            for (int i = 0; i < count; index++, charCount++, i++)
            {
                u = 0;
                if (decoder != null && decoder.pendingByte != 0)
                {
                    u = decoder.pendingByte;
                    decoder.pendingByte = 0;
                }

                u = (ushort)(u << 8 | bytes[index]);
                c = _dbcsToUnicode[u];
                if (c == LEAD_BYTE_CHAR)
                {
                    if (i < count - 1)
                    {
                        index++;
                        i++;
                    }
                    else if (decoder != null)
                    {
                        decoder.pendingByte = bytes[index];
                        return charCount;
                    }
                }
            }

            return charCount;
        }
Пример #5
0
        internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder)
        {
            base.CheckMemorySection();
            DBCSDecoder           decoder        = (DBCSDecoder)baseDecoder;
            byte *                numPtr         = bytes;
            byte *                numPtr2        = bytes + byteCount;
            char *                chPtr          = chars;
            char *                charEnd        = chars + charCount;
            bool                  flag           = false;
            DecoderFallbackBuffer fallbackBuffer = null;

            if ((decoder != null) && (decoder.bLeftOver > 0))
            {
                if (byteCount == 0)
                {
                    if (!decoder.MustFlush)
                    {
                        return(0);
                    }
                    fallbackBuffer = decoder.FallbackBuffer;
                    fallbackBuffer.InternalInitialize(bytes, charEnd);
                    byte[] buffer2 = new byte[] { decoder.bLeftOver };
                    if (!fallbackBuffer.InternalFallback(buffer2, bytes, ref chars))
                    {
                        base.ThrowCharsOverflow(decoder, true);
                    }
                    decoder.bLeftOver = 0;
                    return((int)((long)((chars - chPtr) / 2)));
                }
                int index = decoder.bLeftOver << 8;
                index |= bytes[0];
                bytes++;
                char ch = this.mapBytesToUnicode[index];
                if ((ch == '\0') && (index != 0))
                {
                    fallbackBuffer = decoder.FallbackBuffer;
                    fallbackBuffer.InternalInitialize(numPtr2 - byteCount, charEnd);
                    byte[] buffer3 = new byte[] { (byte)(index >> 8), (byte)index };
                    if (!fallbackBuffer.InternalFallback(buffer3, bytes, ref chars))
                    {
                        base.ThrowCharsOverflow(decoder, true);
                    }
                }
                else
                {
                    if (chars >= charEnd)
                    {
                        base.ThrowCharsOverflow(decoder, true);
                    }
                    chars++;
                    chars[0] = ch;
                }
            }
            while (bytes < numPtr2)
            {
                int num2 = bytes[0];
                bytes++;
                char ch2 = this.mapBytesToUnicode[num2];
                if (ch2 == 0xfffe)
                {
                    if (bytes < numPtr2)
                    {
                        num2  = num2 << 8;
                        num2 |= bytes[0];
                        bytes++;
                        ch2 = this.mapBytesToUnicode[num2];
                    }
                    else if ((decoder == null) || decoder.MustFlush)
                    {
                        ch2 = '\0';
                    }
                    else
                    {
                        flag = true;
                        decoder.bLeftOver = (byte)num2;
                        break;
                    }
                }
                if ((ch2 == '\0') && (num2 != 0))
                {
                    if (fallbackBuffer == null)
                    {
                        if (decoder == null)
                        {
                            fallbackBuffer = base.DecoderFallback.CreateFallbackBuffer();
                        }
                        else
                        {
                            fallbackBuffer = decoder.FallbackBuffer;
                        }
                        fallbackBuffer.InternalInitialize(numPtr2 - byteCount, charEnd);
                    }
                    byte[] buffer4 = null;
                    if (num2 < 0x100)
                    {
                        buffer4 = new byte[] { (byte)num2 };
                    }
                    else
                    {
                        buffer4 = new byte[] { (byte)(num2 >> 8), (byte)num2 };
                    }
                    if (fallbackBuffer.InternalFallback(buffer4, bytes, ref chars))
                    {
                        continue;
                    }
                    bytes -= buffer4.Length;
                    fallbackBuffer.InternalReset();
                    base.ThrowCharsOverflow(decoder, bytes == numPtr);
                    break;
                }
                if (chars >= charEnd)
                {
                    bytes--;
                    if (num2 >= 0x100)
                    {
                        bytes--;
                    }
                    base.ThrowCharsOverflow(decoder, bytes == numPtr);
                    break;
                }
                chars++;
                chars[0] = ch2;
            }
            if (decoder != null)
            {
                if (!flag)
                {
                    decoder.bLeftOver = 0;
                }
                decoder.m_bytesUsed = (int)((long)((bytes - numPtr) / 1));
            }
            return((int)((long)((chars - chPtr) / 2)));
        }
Пример #6
0
        internal override unsafe int GetCharCount(byte *bytes, int count, DecoderNLS baseDecoder)
        {
            base.CheckMemorySection();
            DBCSDecoder           decoder        = (DBCSDecoder)baseDecoder;
            DecoderFallbackBuffer fallbackBuffer = null;
            byte *numPtr = bytes + count;
            int   num    = count;

            if ((decoder != null) && (decoder.bLeftOver > 0))
            {
                if (count == 0)
                {
                    if (!decoder.MustFlush)
                    {
                        return(0);
                    }
                    fallbackBuffer = decoder.FallbackBuffer;
                    fallbackBuffer.InternalInitialize(bytes, null);
                    byte[] buffer2 = new byte[] { decoder.bLeftOver };
                    return(fallbackBuffer.InternalFallback(buffer2, bytes));
                }
                int index = decoder.bLeftOver << 8;
                index |= bytes[0];
                bytes++;
                if ((this.mapBytesToUnicode[index] == '\0') && (index != 0))
                {
                    num--;
                    fallbackBuffer = decoder.FallbackBuffer;
                    fallbackBuffer.InternalInitialize(numPtr - count, null);
                    byte[] buffer3 = new byte[] { (byte)(index >> 8), (byte)index };
                    num += fallbackBuffer.InternalFallback(buffer3, bytes);
                }
            }
            while (bytes < numPtr)
            {
                int num3 = bytes[0];
                bytes++;
                char ch2 = this.mapBytesToUnicode[num3];
                if (ch2 == 0xfffe)
                {
                    num--;
                    if (bytes < numPtr)
                    {
                        num3  = num3 << 8;
                        num3 |= bytes[0];
                        bytes++;
                        ch2 = this.mapBytesToUnicode[num3];
                    }
                    else
                    {
                        if ((decoder != null) && !decoder.MustFlush)
                        {
                            return(num);
                        }
                        num++;
                        ch2 = '\0';
                    }
                }
                if ((ch2 == '\0') && (num3 != 0))
                {
                    if (fallbackBuffer == null)
                    {
                        if (decoder == null)
                        {
                            fallbackBuffer = base.DecoderFallback.CreateFallbackBuffer();
                        }
                        else
                        {
                            fallbackBuffer = decoder.FallbackBuffer;
                        }
                        fallbackBuffer.InternalInitialize(numPtr - count, null);
                    }
                    num--;
                    byte[] buffer4 = null;
                    if (num3 < 0x100)
                    {
                        buffer4 = new byte[] { (byte)num3 };
                    }
                    else
                    {
                        buffer4 = new byte[] { (byte)(num3 >> 8), (byte)num3 };
                    }
                    num += fallbackBuffer.InternalFallback(buffer4, bytes);
                }
            }
            return(num);
        }