Пример #1
0
        private int DetermineFormat(TokenizerStream stream)
        {
            if (stream.GetNextToken() == Tokenizer.bra)
            {
                if (stream.GetNextToken() == Tokenizer.quest)
                {
                    _t.GetTokens(stream, -1, true);
                    stream.GoToPosition(2);

                    bool sawEquals   = false;
                    bool sawEncoding = false;

                    short i;

                    for (i = stream.GetNextToken(); i != -1 && i != Tokenizer.ket; i = stream.GetNextToken())
                    {
                        switch (i)
                        {
                        case Tokenizer.cstr:
                            if (sawEquals && sawEncoding)
                            {
                                _t.ChangeFormat(System.Text.Encoding.GetEncoding(stream.GetNextString()));
                                return(0);
                            }
                            else if (!sawEquals)
                            {
                                if (String.Compare(stream.GetNextString(), "encoding", StringComparison.Ordinal) == 0)
                                {
                                    sawEncoding = true;
                                }
                            }
                            else
                            {
                                sawEquals   = false;
                                sawEncoding = false;
                                stream.ThrowAwayNextString();
                            }
                            break;

                        case Tokenizer.equals:
                            sawEquals = true;
                            break;

                        default:
                            throw new XmlSyntaxException("XMLSyntax_UnexpectedEndOfFile");
                        }
                    }

                    return(0);
                }
            }

            return(2);
        }
Пример #2
0
        private void ParseContents()
        {
            short i;

            TokenizerStream stream = new TokenizerStream();

            _t.GetTokens(stream, 2, false);
            stream.Reset();

            int gotoPosition = DetermineFormat(stream);

            stream.GoToPosition(gotoPosition);
            _t.GetTokens(stream, -1, false);
            stream.Reset();

            int neededIndex = 0;

            GetRequiredSizes(stream, ref neededIndex);

            _doc = new SecurityDocument(neededIndex);
            int position = 0;

            stream.Reset();

            for (i = stream.GetNextFullToken(); i != -1; i = stream.GetNextFullToken())
            {
                if ((i & c_flag) != c_flag)
                {
                    continue;
                }
                else
                {
                    switch ((short)(i & 0xFF00))
                    {
                    case c_elementtag:
                        _doc.AddToken(SecurityDocument.c_element, ref position);
                        _doc.AddString(stream.GetNextString(), ref position);
                        break;

                    case c_attributetag:
                        _doc.AddToken(SecurityDocument.c_attribute, ref position);
                        _doc.AddString(stream.GetNextString(), ref position);
                        _doc.AddString(stream.GetNextString(), ref position);
                        break;

                    case c_texttag:
                        _doc.AddToken(SecurityDocument.c_text, ref position);
                        _doc.AddString(stream.GetNextString(), ref position);
                        break;

                    case c_additionaltexttag:
                        _doc.AppendString(" ", ref position);
                        _doc.AppendString(stream.GetNextString(), ref position);
                        break;

                    case c_childrentag:
                        _doc.AddToken(SecurityDocument.c_children, ref position);
                        break;

                    case c_wastedstringtag:
                        stream.ThrowAwayNextString();
                        break;

                    default:
                        throw new XmlSyntaxException("error");
                    }
                }
            }
        }