示例#1
0
        private static void ReadUTF8CharRaw(Stream stream, Stream ostream)
        {
            int tag = stream.ReadByte();

            switch (tag >> 4)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7: {
                // 0xxx xxxx
                ostream.WriteByte((byte)tag);
                break;
            }

            case 12:
            case 13: {
                // 110x xxxx   10xx xxxx
                ostream.WriteByte((byte)tag);
                ostream.WriteByte((byte)stream.ReadByte());
                break;
            }

            case 14: {
                // 1110 xxxx  10xx xxxx  10xx xxxx
                ostream.WriteByte((byte)tag);
                ostream.WriteByte((byte)stream.ReadByte());
                ostream.WriteByte((byte)stream.ReadByte());
                break;
            }

            default:
                throw ValueReader.BadEncoding(tag);
            }
        }
示例#2
0
        private static void ReadStringRaw(Stream stream, Stream ostream)
        {
            int count = 0;
            int tag   = '0';

            do
            {
                count *= 10;
                count += tag - '0';
                tag    = stream.ReadByte();
                ostream.WriteByte((byte)tag);
            } while (tag != TagQuote);
            for (int i = 0; i < count; ++i)
            {
                tag = stream.ReadByte();
                switch (tag >> 4)
                {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7: {
                    // 0xxx xxxx
                    ostream.WriteByte((byte)tag);
                    break;
                }

                case 12:
                case 13: {
                    // 110x xxxx   10xx xxxx
                    ostream.WriteByte((byte)tag);
                    ostream.WriteByte((byte)stream.ReadByte());
                    break;
                }

                case 14: {
                    // 1110 xxxx  10xx xxxx  10xx xxxx
                    ostream.WriteByte((byte)tag);
                    ostream.WriteByte((byte)stream.ReadByte());
                    ostream.WriteByte((byte)stream.ReadByte());
                    break;
                }

                case 15: {
                    // 1111 0xxx  10xx xxxx  10xx xxxx  10xx xxxx
                    if ((tag & 0xf) <= 4)
                    {
                        ostream.WriteByte((byte)tag);
                        ostream.WriteByte((byte)stream.ReadByte());
                        ostream.WriteByte((byte)stream.ReadByte());
                        ostream.WriteByte((byte)stream.ReadByte());
                        ++i;
                        break;
                    }
                    goto default;
                    // no break here!! here need throw exception.
                }

                default:
                    throw ValueReader.BadEncoding(tag);
                }
            }
            ostream.WriteByte((byte)stream.ReadByte());
        }