Esempio n. 1
0
        public void ConsumeToAny()
        {
            CharacterReader r = new CharacterReader("One &bar; qux");

            Assert.AreEqual("One ", r.ConsumeToAny('&', ';'));
            Assert.IsTrue(r.Matches('&'));
            Assert.IsTrue(r.Matches("&bar;"));
            Assert.AreEqual('&', r.Consume());
            Assert.AreEqual("bar", r.ConsumeToAny('&', ';'));
            Assert.AreEqual(';', r.Consume());
            Assert.AreEqual(" qux", r.ConsumeToAny('&', ';'));
        }
Esempio n. 2
0
            // in data state, gather characters until a character reference or tag is found
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                switch (r.Current())
                {
                    case '&':
                        t.AdvanceTransition(TokeniserState.CharacterReferenceInData);
                        break;

                    case '<':
                        t.AdvanceTransition(TokeniserState.TagOpen);
                        break;

                    case TokeniserState.nullChar:
                        t.Error(this);
                        // NOT replacement character (oddly?)
                        t.Emit(r.Consume());
                        break;

                    case TokeniserState.eof:
                        t.Emit(new Token.EOF());
                        break;

                    default:
                        string data = r.ConsumeToAny('&', '<', TokeniserState.nullChar);
                        t.Emit(data);
                        break;
                }
            }
Esempio n. 3
0
        public void MatchesAny()
        {
            char[]          scan = { ' ', '\n', '\t' };
            CharacterReader r    = new CharacterReader("One\nTwo\tThree");

            Assert.IsFalse(r.MatchesAny(scan));
            Assert.AreEqual("One", r.ConsumeToAny(scan));
            Assert.IsTrue(r.MatchesAny(scan));
            Assert.AreEqual('\n', r.Consume());
            Assert.IsFalse(r.MatchesAny(scan));
        }
Esempio n. 4
0
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                char c = r.Current();
                switch (c)
                {
                    case '-':
                        t.Emit(c);
                        t.AdvanceTransition(TokeniserState.ScriptDataDoubleEscapedDash);
                        break;

                    case '<':
                        t.Emit(c);
                        t.AdvanceTransition(TokeniserState.ScriptDataDoubleEscapedLessthanSign
                            );
                        break;

                    case TokeniserState.nullChar:
                        t.Error(this);
                        r.Advance();
                        t.Emit(TokeniserState.replacementChar);
                        break;

                    case TokeniserState.eof:
                        t.EofError(this);
                        t.Transition(TokeniserState.Data);
                        break;

                    default:
                        string data = r.ConsumeToAny('-', '<', TokeniserState.nullChar);
                        t.Emit(data);
                        break;
                }
            }
Esempio n. 5
0
            /// handles data in title, textarea etc
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                switch (r.Current())
                {
                    case '&':
                        t.AdvanceTransition(TokeniserState.CharacterReferenceInRcdata);
                        break;

                    case '<':
                        t.AdvanceTransition(TokeniserState.RcdataLessthanSign);
                        break;

                    case TokeniserState.nullChar:
                        t.Error(this);
                        r.Advance();
                        t.Emit(TokeniserState.replacementChar);
                        break;

                    case TokeniserState.eof:
                        t.Emit(new Token.EOF());
                        break;

                    default:
                        string data = r.ConsumeToAny('&', '<', TokeniserState.nullChar);
                        t.Emit(data);
                        break;
                }
            }
Esempio n. 6
0
            // from < or </ in data, will have start or end tag pending
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                // previous TagOpen state did NOT consume, will have a letter char in current
                string tagName = r.ConsumeToAny('\t', '\n', '\r', '\f', ' ', '/', '>', TokeniserState.nullChar).ToLower();
                t.tagPending.AppendTagName(tagName);
                switch (r.Consume())
                {
                    case '\t':
                    case '\n':
                    case '\r':
                    case '\f':
                    case ' ':
                        t.Transition(TokeniserState.BeforeAttributeName);
                        break;

                    case '/':
                        t.Transition(TokeniserState.SelfClosingStartTag);
                        break;

                    case '>':
                        t.EmitTagPending();
                        t.Transition(TokeniserState.Data);
                        break;

                    case TokeniserState.nullChar:
                        // replacement
                        t.tagPending.AppendTagName(TokeniserState.replacementStr);
                        break;

                    case TokeniserState.eof:
                        // should emit pending tag?
                        t.EofError(this);
                        t.Transition(TokeniserState.Data);
                        break;
                }
            }
Esempio n. 7
0
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                char c = r.Current();
                switch (c)
                {
                    case '-':
                        t.AdvanceTransition(TokeniserState.CommentEndDash);
                        break;

                    case TokeniserState.nullChar:
                        t.Error(this);
                        r.Advance();
                        t.commentPending.data.Append(TokeniserState.replacementChar);
                        break;

                    case TokeniserState.eof:
                        t.EofError(this);
                        t.EmitCommentPending();
                        t.Transition(TokeniserState.Data);
                        break;

                    default:
                        t.commentPending.data.Append(r.ConsumeToAny('-', TokeniserState.nullChar
                            ));
                        break;
                }
            }
Esempio n. 8
0
            // no default, handled in consume to any above
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                string value = r.ConsumeToAny('\t', '\n', '\r', '\f', ' ', '&', '>', TokeniserState.nullChar, '"', '\'', '<', '=', '`');
                if (value.Length > 0)
                {
                    t.tagPending.AppendAttributeValue(value);
                }
                char c = r.Consume();
                switch (c)
                {
                    case '\t':
                    case '\n':
                    case '\r':
                    case '\f':
                    case ' ':
                        t.Transition(TokeniserState.BeforeAttributeName);
                        break;

                    case '&':
                        char[] @ref = t.ConsumeCharacterReference('>', true);
                        if (@ref != null)
                        {
                            t.tagPending.AppendAttributeValue(@ref);
                        }
                        else
                        {
                            t.tagPending.AppendAttributeValue('&');
                        }
                        break;

                    case '>':
                        t.EmitTagPending();
                        t.Transition(TokeniserState.Data);
                        break;

                    case TokeniserState.nullChar:
                        t.Error(this);
                        t.tagPending.AppendAttributeValue(TokeniserState.replacementChar);
                        break;

                    case TokeniserState.eof:
                        t.EofError(this);
                        t.Transition(TokeniserState.Data);
                        break;

                    case '"':
                    case '\'':
                    case '<':
                    case '=':
                    case '`':
                        t.Error(this);
                        t.tagPending.AppendAttributeValue(c);
                        break;
                }
            }
Esempio n. 9
0
            // no default, handled in consume to any above
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                string value = r.ConsumeToAny('\'', '&', TokeniserState.nullChar);
                if (value.Length > 0)
                {
                    t.tagPending.AppendAttributeValue(value);
                }
                char c = r.Consume();
                switch (c)
                {
                    case '\'':
                        t.Transition(TokeniserState.AfterAttributeValue_quoted);
                        break;

                    case '&':
                        char[] @ref = t.ConsumeCharacterReference('\'', true);
                        if (@ref != null)
                        {
                            t.tagPending.AppendAttributeValue(@ref);
                        }
                        else
                        {
                            t.tagPending.AppendAttributeValue('&');
                        }
                        break;

                    case TokeniserState.nullChar:
                        t.Error(this);
                        t.tagPending.AppendAttributeValue(TokeniserState.replacementChar);
                        break;

                    case TokeniserState.eof:
                        t.EofError(this);
                        t.Transition(TokeniserState.Data);
                        break;
                }
            }
Esempio n. 10
0
            // from before attribute name
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                string name = r.ConsumeToAny('\t', '\n', '\r', '\f', ' ', '/', '=', '>', TokeniserState.nullChar, '"', '\'', '<');
                t.tagPending.AppendAttributeName(name.ToLower());
                char c = r.Consume();
                switch (c)
                {
                    case '\t':
                    case '\n':
                    case '\r':
                    case '\f':
                    case ' ':
                        t.Transition(TokeniserState.AfterAttributeName);
                        break;

                    case '/':
                        t.Transition(TokeniserState.SelfClosingStartTag);
                        break;

                    case '=':
                        t.Transition(TokeniserState.BeforeAttributeValue);
                        break;

                    case '>':
                        t.EmitTagPending();
                        t.Transition(TokeniserState.Data);
                        break;

                    case TokeniserState.nullChar:
                        t.Error(this);
                        t.tagPending.AppendAttributeName(TokeniserState.replacementChar);
                        break;

                    case TokeniserState.eof:
                        t.EofError(this);
                        t.Transition(TokeniserState.Data);
                        break;

                    case '"':
                    case '\'':
                    case '<':
                        t.Error(this);
                        t.tagPending.AppendAttributeName(c);
                        break;
                }
            }