ucs4decoder.cs

来自「Freetextbox是优秀的在线编辑器」· CS 代码 · 共 70 行

CS
70
字号
namespace FreeTextBoxControls.Support.Sgml
{
    using System;
    using System.Text;

    internal abstract class Ucs4Decoder : System.Text.Decoder
    {
        protected Ucs4Decoder()
        {
            this.temp = new byte[4];
            this.tempBytes = 0;
        }

        public override int GetCharCount(byte[] bytes, int index, int count)
        {
            return ((count + this.tempBytes) / 4);
        }

        public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
        {
            int num1 = this.tempBytes;
            if (this.tempBytes > 0)
            {
                while (num1 < 4)
                {
                    this.temp[num1] = bytes[byteIndex];
                    byteIndex++;
                    byteCount--;
                    num1++;
                }
                num1 = 1;
                this.GetFullChars(this.temp, 0, 4, chars, charIndex);
                charIndex++;
            }
            else
            {
                num1 = 0;
            }
            num1 = this.GetFullChars(bytes, byteIndex, byteCount, chars, charIndex) + num1;
            int num2 = (this.tempBytes + byteCount) % 4;
            byteCount += byteIndex;
            byteIndex = byteCount - num2;
            this.tempBytes = 0;
            if (byteIndex >= 0)
            {
                while (byteIndex < byteCount)
                {
                    this.temp[this.tempBytes] = bytes[byteIndex];
                    this.tempBytes++;
                    byteIndex++;
                }
            }
            return num1;
        }

        internal abstract int GetFullChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex);
        internal char UnicodeToUTF16(uint code)
        {
            byte num1 = (byte) (0xd7c0 + (code >> 10));
            byte num2 = (byte) (0xdc00 | (code & 0x3ff));
            return (char) ((ushort) ((num2 << 8) | num1));
        }


        internal byte[] temp;
        internal int tempBytes;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?