示例#1
0
        public void unconsume()
        {
            CharacterReader r = new CharacterReader("one");
            Assert.AreEqual('o', r.Consume());
            Assert.AreEqual('n', r.Current());
            r.Unconsume();
            Assert.AreEqual('o', r.Current());

            Assert.AreEqual('o', r.Consume());
            Assert.AreEqual('n', r.Consume());
            Assert.AreEqual('e', r.Consume());
            Assert.IsTrue(r.IsEmpty());
            r.Unconsume();
            Assert.IsFalse(r.IsEmpty());
            Assert.AreEqual('e', r.Current());
            Assert.AreEqual('e', r.Consume());
            Assert.IsTrue(r.IsEmpty());

            Assert.AreEqual(CharacterReader.EOF, r.Consume());
            r.Unconsume();
            Assert.IsTrue(r.IsEmpty());
            Assert.AreEqual(CharacterReader.EOF, r.Current());
        }
示例#2
0
            public override void Read(Tokeniser t, CharacterReader r)
            {
                if (r.MatchesLetter())
                {
                    string name = r.ConsumeLetterSequence();
                    t.DataBuffer.Append(name.ToLowerInvariant());
                    t.Emit(name);
                    return;
                }

                char c = r.Consume();
                switch (c)
                {
                    case '\t':
                    case '\n':
                    case '\r':
                    case '\f':
                    case ' ':
                    case '/':
                    case '>':
                        if (t.DataBuffer.ToString().Equals("script"))
                        {
                            t.Transition(ScriptDataEscaped);
                        }
                        else
                        {
                            t.Transition(ScriptDataDoubleEscaped);
                        }
                        t.Emit(c);
                        break;
                    default:
                        r.Unconsume();
                        t.Transition(ScriptDataDoubleEscaped);
                        break;
                }
            }
示例#3
0
 // from tagname <xxx
 public override void Read(Tokeniser t, CharacterReader r)
 {
     char c = r.Consume();
     switch (c)
     {
         case '\t':
         case '\n':
         case '\r':
         case '\f':
         case ' ':
             break; // ignore whitespace
         case '/':
             t.Transition(SelfClosingStartTag);
             break;
         case '>':
             t.EmitTagPending();
             t.Transition(Data);
             break;
         case _nullChar:
             t.Error(this);
             t.TagPending.NewAttribute();
             r.Unconsume();
             t.Transition(AttributeName);
             break;
         case _eof:
             t.EofError(this);
             t.Transition(Data);
             break;
         case '"':
         case '\'':
         case '<':
         case '=':
             t.Error(this);
             t.TagPending.NewAttribute();
             t.TagPending.AppendAttributeName(c);
             t.Transition(AttributeName);
             break;
         default: // A-Z, anything else
             t.TagPending.NewAttribute();
             r.Unconsume();
             t.Transition(AttributeName);
             break;
     }
 }
示例#4
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     switch (r.Consume())
     {
         case '/':
             t.CreateTempBuffer();
             t.Transition(ScriptDataEndTagOpen);
             break;
         case '!':
             t.Emit("<!");
             t.Transition(ScriptDataEscapeStart);
             break;
         default:
             t.Emit("<");
             r.Unconsume();
             t.Transition(ScriptData);
             break;
     }
 }
示例#5
0
 // from < in rcdata
 public override void Read(Tokeniser t, CharacterReader r)
 {
     if (r.Matches('/'))
     {
         t.CreateTempBuffer();
         t.AdvanceTransition(RcDataEndTagOpen);
     }
     else if (r.MatchesLetter() && !r.ContainsIgnoreCase("</" + t.AppropriateEndTagName()))
     {
         // diverge from spec: got a start tag, but there's no appropriate end tag (</title>), so rather than
         // consuming to EOF; break out here
         t.TagPending = new Token.EndTag(t.AppropriateEndTagName());
         t.EmitTagPending();
         r.Unconsume(); // undo "<"
         t.Transition(Data);
     }
     else
     {
         t.Emit("<");
         t.Transition(RcData);
     }
 }
示例#6
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     // todo: handle bogus comment starting from eof. when does that trigger?
     // rewind to capture character that lead us here
     r.Unconsume();
     Token.Comment comment = new Token.Comment();
     comment.Data.Append(r.ConsumeTo('>'));
     // todo: replace nullChar with replaceChar
     t.Emit(comment);
     t.AdvanceTransition(Data);
 }
示例#7
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     char c = r.Consume();
     switch (c)
     {
         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 _eof:
             t.EofError(this);
             t.Transition(Data);
             break;
         default:
             t.Error(this);
             r.Unconsume();
             t.Transition(BeforeAttributeName);
             break;
     }
 }
示例#8
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     char c = r.Consume();
     switch (c)
     {
         case '\t':
         case '\n':
         case '\r':
         case '\f':
         case ' ':
             // ignore
             break;
         case '"':
             t.Transition(AttributeValueDoubleQuoted);
             break;
         case '&':
             r.Unconsume();
             t.Transition(AttributeValueUnquoted);
             break;
         case '\'':
             t.Transition(AttributeValueSingleQuoted);
             break;
         case _nullChar:
             t.Error(this);
             t.TagPending.AppendAttributeValue(_replacementChar);
             t.Transition(AttributeValueUnquoted);
             break;
         case _eof:
             t.EofError(this);
             t.Transition(Data);
             break;
         case '>':
             t.Error(this);
             t.EmitTagPending();
             t.Transition(Data);
             break;
         case '<':
         case '=':
         case '`':
             t.Error(this);
             t.TagPending.AppendAttributeValue(c);
             t.Transition(AttributeValueUnquoted);
             break;
         default:
             r.Unconsume();
             t.Transition(AttributeValueUnquoted);
             break;
     }
 }