示例#1
0
        public String ReadStr(FastInputStream dis)
        {
            int sz = ReadSize(dis);

            if (chars == null || chars.Length < sz)
            {
                chars = new char[sz];
            }
            if (bytes == null || bytes.Length < sz)
            {
                bytes = new byte[sz];
            }
            dis.ReadFully(bytes, 0, sz);

            int outUpto = 0;

            for (int i = 0; i < sz;)
            {
                int b = bytes[i++] & 0xff;
                int ch;
                if (b < 0xc0)
                {
                    ch = b;
                }
                else if (b < 0xe0)
                {
                    ch = ((b & 0x1f) << 6) + (bytes[i++] & 0x3f);
                }
                else if (b < 0xf0)
                {
                    ch = ((b & 0xf) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f);
                }
                else
                {
                    ch = ((b & 0x7) << 18) + ((bytes[i++] & 0x3f) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f);
                }
                if (ch <= 0xFFFF)
                {
                    // target is a character <= 0xFFFF
                    chars[outUpto++] = (char)ch;
                }
                else
                {
                    // target is a character in range 0xFFFF - 0x10FFFF
                    int chHalf = ch - 0x10000;
                    chars[outUpto++] = (char)((chHalf >> 0xA) + 0xD800);
                    chars[outUpto++] = (char)((chHalf & 0x3FF) + 0xDC00);
                }
            }
            return(new String(chars, 0, outUpto));
        }
示例#2
0
        public String ReadStr(FastInputStream dis)
        {
            int sz = ReadSize(dis);
            if (chars == null || chars.Length < sz) chars = new char[sz];
            if (bytes == null || bytes.Length < sz) bytes = new byte[sz];
            dis.ReadFully(bytes, 0, sz);

            int outUpto = 0;
            for (int i = 0; i < sz; )
            {
                int b = bytes[i++] & 0xff;
                int ch;
                if (b < 0xc0)
                {
                    ch = b;
                }
                else if (b < 0xe0)
                {
                    ch = ((b & 0x1f) << 6) + (bytes[i++] & 0x3f);
                }
                else if (b < 0xf0)
                {
                    ch = ((b & 0xf) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f);
                }
                else
                {
                    ch = ((b & 0x7) << 18) + ((bytes[i++] & 0x3f) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f);
                }
                if (ch <= 0xFFFF)
                {
                    // target is a character <= 0xFFFF
                    chars[outUpto++] = (char)ch;
                }
                else
                {
                    // target is a character in range 0xFFFF - 0x10FFFF
                    int chHalf = ch - 0x10000;
                    chars[outUpto++] = (char)((chHalf >> 0xA) + 0xD800);
                    chars[outUpto++] = (char)((chHalf & 0x3FF) + 0xDC00);
                }
            }
            return new String(chars, 0, outUpto);
        }
示例#3
0
 public byte[] ReadByteArray(FastInputStream dis)
 {
     byte[] arr = new byte[ReadVInt(dis)];
     dis.ReadFully(arr);
     return arr;
 }
示例#4
0
 public byte[] ReadByteArray(FastInputStream dis)
 {
     byte[] arr = new byte[ReadVInt(dis)];
     dis.ReadFully(arr);
     return(arr);
 }