Наследование: NonBlockingStreamReader
Пример #1
0
 internal XmlScanner(XmlStreamReader reader, XmlNameTable ntable) : this(reader, ntable, null) {
     // Intentionally Empty
 }
Пример #2
0
        internal XmlScanner(XmlStreamReader reader, XmlNameTable ntable, Encoding enc) : this(ntable) {
            _nLineNum = 1;
            _StreamReader = reader;
            _TextReader = null;
            _nSize = (int) ((reader.CanCalcLength && reader.Length < BUFSIZE) ? reader.Length:BUFSIZE);
            _ByteBuffer = new byte[_nSize+1];
            _ByteLen = _StreamReader.Read(_ByteBuffer, 0, _nSize);
            _ByteStart = 0;

            _nCodePage = 0;
            if (null != enc) {
                _Encoding = enc;
            }
            else {
                _Encoding = null;
                switch(AutoDetectEncoding(_ByteBuffer))
                {
                case UniCodeBE://2:
                    _Encoding = Encoding.BigEndianUnicode;
                    break;
                case UniCode: //3:
                    _Encoding = Encoding.Unicode;
                    break;
                case UCS4BE: //4:
                case UCS4BEB: // 5:
                    _Encoding = Ucs4Encoding.UCS4_Bigendian;
                    break;

                case UCS4: //6:
                case UCS4B: //7:
                    _Encoding = Ucs4Encoding.UCS4_Littleendian;
                    break;

                case UCS434://8:
                case UCS434B: //9:
                    _Encoding = Ucs4Encoding.UCS4_3412;
                    break;
                case UCS421: //10:
                case UCS421B://11:
                    _Encoding = Ucs4Encoding.UCS4_2143;
                    break;

                case EBCDIC: //12: ebcdic
                    throw new XmlException(Res.Xml_UnknownEncoding, "ebcdic", LineNum, LinePos);
                    //break;
                case UTF8: //13:
                    _EncodingSetByDefault = true;
                    _Encoding = new UTF8Encoding(true);
                    break;
                default:
                    _Encoding = new UTF8Encoding(true, true);

                    break;
                }

            }

            _Decoder = _Encoding.GetDecoder();
            _PermitEncodingChange = true;
            if(_Encoding != null)
                _nCodePage = _Encoding.CodePage;
            _achText = new char[_nSize+1];

            int preambleLength = 0;
            try {
                byte[] preamble = _Encoding.GetPreamble();
                preambleLength = preamble.Length;
                bool hasByteOrderMark = true;
                for (int i = 0; i < preambleLength && hasByteOrderMark; i++) {
                    hasByteOrderMark &= (_ByteBuffer[i] == preamble[i]);
                }
                if (hasByteOrderMark) {
                    _ByteStart = preambleLength;
                }
            }
            catch (Exception) {
            }

            _nUsed += GetChars(_ByteBuffer, ref _ByteStart , _ByteLen - _ByteStart, _achText, 0, true);

            _achText[_nUsed] = (char)0;
        }
Пример #3
0
        // Initialize the scanner given a StreamReader.
        internal XmlScanner(TextReader reader, XmlNameTable ntable)  : this(ntable) {
            const int BUFSIZE_SMALL = 256;
            _TextReader = reader;
            _StreamReader = null;
            _nSize = BUFSIZE;
            StreamReader streamReader = reader as StreamReader;
            if (streamReader != null) {
                Stream stream = streamReader.BaseStream;
                if (stream.CanSeek && stream.Length < BUFSIZE) {
                    _nSize = BUFSIZE_SMALL;
                }
            }
            _achText = new char[_nSize+1];
            _PermitEncodingChange = false;
            _Encoding = Encoding.Unicode;

            //no need to check Encoding, start reading
            Read();
        }