Exemplo n.º 1
0
 // in data state, gather characters until a character reference or tag is found
 public override void Read(Tokeniser t, CharacterReader r)
 {
     switch (r.Current())
     {
         case '&':
             t.AdvanceTransition(CharacterReferenceInData);
             break;
         case '<':
             t.AdvanceTransition(TagOpen);
             break;
         case _nullChar:
             t.Error(this); // NOT replacement character (oddly?)
             t.Emit(r.Consume());
             break;
         case _eof:
             t.Emit(new Token.EOF());
             break;
         default:
             string data = r.ConsumeToAny('&', '<', _nullChar);
             t.Emit(data);
             break;
     }
 }
Exemplo n.º 2
0
 /// handles data in title, textarea etc
 public override void Read(Tokeniser t, CharacterReader r)
 {
     switch (r.Current())
     {
         case '&':
             t.AdvanceTransition(CharacterReferenceInRcData);
             break;
         case '<':
             t.AdvanceTransition(RcDataLessThanSign);
             break;
         case _nullChar:
             t.Error(this);
             r.Advance();
             t.Emit(_replacementChar);
             break;
         case _eof:
             t.Emit(new Token.EOF());
             break;
         default:
             string data = r.ConsumeToAny('&', '<', _nullChar);
             t.Emit(data);
             break;
     }
 }
Exemplo 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));
 }
Exemplo n.º 4
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('&', ';'));
 }
Exemplo n.º 5
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     char c = r.Current();
     switch (c)
     {
         case '-':
             t.Emit(c);
             t.AdvanceTransition(ScriptDataDoubleEscapedDash);
             break;
         case '<':
             t.Emit(c);
             t.AdvanceTransition(ScriptDataDoubleEscapedLessthanSign);
             break;
         case _nullChar:
             t.Error(this);
             r.Advance();
             t.Emit(_replacementChar);
             break;
         case _eof:
             t.EofError(this);
             t.Transition(Data);
             break;
         default:
             string data = r.ConsumeToAny('-', '<', _nullChar);
             t.Emit(data);
             break;
     }
 }
Exemplo n.º 6
0
            public override void Read(Tokeniser t, CharacterReader r)
            {
                if (r.IsEmpty())
                {
                    t.EofError(this);
                    t.Transition(Data);
                    return;
                }

                switch (r.Current())
                {
                    case '-':
                        t.Emit('-');
                        t.AdvanceTransition(ScriptDataEscapedDash);
                        break;
                    case '<':
                        t.AdvanceTransition(ScriptDataEscapedLessThanSign);
                        break;
                    case _nullChar:
                        t.Error(this);
                        r.Advance();
                        t.Emit(_replacementChar);
                        break;
                    default:
                        string data = r.ConsumeToAny('-', '<', _nullChar);
                        t.Emit(data);
                        break;
                }
            }
Exemplo n.º 7
0
            // from < or </ in data, will have start or end tag pending
            public 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', ' ', '/', '>', _nullChar).ToLowerInvariant();
                t.TagPending.AppendTagName(tagName);

                switch (r.Consume())
                {
                    case '\t':
                    case '\n':
                    case '\r':
                    case '\f':
                    case ' ':
                        t.Transition(BeforeAttributeName);
                        break;
                    case '/':
                        t.Transition(SelfClosingStartTag);
                        break;
                    case '>':
                        t.EmitTagPending();
                        t.Transition(Data);
                        break;
                    case _nullChar: // replacement
                        t.TagPending.AppendTagName(_replacementStr);
                        break;
                    case _eof: // should Emit pending tag?
                        t.EofError(this);
                        t.Transition(Data);
                        break;
                    // no default, as covered with above ConsumeToAny
                }
            }
Exemplo n.º 8
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     char c = r.Current();
     switch (c)
     {
         case '-':
             t.AdvanceTransition(CommentEndDash);
             break;
         case _nullChar:
             t.Error(this);
             r.Advance();
             t.CommentPending.Data.Append(_replacementChar);
             break;
         case _eof:
             t.EofError(this);
             t.EmitCommentPending();
             t.Transition(Data);
             break;
         default:
             t.CommentPending.Data.Append(r.ConsumeToAny('-', _nullChar));
             break;
     }
 }
Exemplo n.º 9
0
            public override void Read(Tokeniser t, CharacterReader r)
            {
                string value = r.ConsumeToAny('\t', '\n', '\r', '\f', ' ', '&', '>', _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(BeforeAttributeName);
                        break;
                    case '&':
                        char? reference = t.ConsumeCharacterReference('>', true);
                        if (reference != null)
                        {
                            t.TagPending.AppendAttributeValue(reference.Value);
                        }
                        else
                        {
                            t.TagPending.AppendAttributeValue('&');
                        }
                        break;
                    case '>':
                        t.EmitTagPending();
                        t.Transition(Data);
                        break;
                    case _nullChar:
                        t.Error(this);
                        t.TagPending.AppendAttributeValue(_replacementChar);
                        break;
                    case _eof:
                        t.EofError(this);
                        t.Transition(Data);
                        break;
                    case '"':
                    case '\'':
                    case '<':
                    case '=':
                    case '`':
                        t.Error(this);
                        t.TagPending.AppendAttributeValue(c);
                        break;
                    // no default, handled in Consume to any above
                }

            }
Exemplo n.º 10
0
            public override void Read(Tokeniser t, CharacterReader r)
            {
                string value = r.ConsumeToAny('\'', '&', _nullChar);
                if (value.Length > 0)
                {
                    t.TagPending.AppendAttributeValue(value);
                }

                char c = r.Consume();
                switch (c)
                {
                    case '\'':
                        t.Transition(AfterAttributeValueQuoted);
                        break;
                    case '&':
                        char? reference = t.ConsumeCharacterReference('\'', true);
                        if (reference != null)
                        {
                            t.TagPending.AppendAttributeValue(reference.Value);
                        }
                        else
                        {
                            t.TagPending.AppendAttributeValue('&');
                        }
                        break;
                    case _nullChar:
                        t.Error(this);
                        t.TagPending.AppendAttributeValue(_replacementChar);
                        break;
                    case _eof:
                        t.EofError(this);
                        t.Transition(Data);
                        break;
                    // no default, handled in Consume to any above
                }
            }
Exemplo n.º 11
0
            // from before attribute name
            public override void Read(Tokeniser t, CharacterReader r)
            {
                string name = r.ConsumeToAny('\t', '\n', '\r', '\f', ' ', '/', '=', '>', _nullChar, '"', '\'', '<');
                t.TagPending.AppendAttributeName(name.ToLowerInvariant());

                char c = r.Consume();
                switch (c)
                {
                    case '\t':
                    case '\n':
                    case '\r':
                    case '\f':
                    case ' ':
                        t.Transition(AfterAttributeName);
                        break;
                    case '/':
                        t.Transition(SelfClosingStartTag);
                        break;
                    case '=':
                        t.Transition(BeforeAttributeValue);
                        break;
                    case '>':
                        t.EmitTagPending();
                        t.Transition(Data);
                        break;
                    case _nullChar:
                        t.Error(this);
                        t.TagPending.AppendAttributeName(_replacementChar);
                        break;
                    case _eof:
                        t.EofError(this);
                        t.Transition(Data);
                        break;
                    case '"':
                    case '\'':
                    case '<':
                        t.Error(this);
                        t.TagPending.AppendAttributeName(c);
                        break;
                    // no default, as covered in ConsumeToAny
                }
            }