Exemplo n.º 1
0
            public override void Read(Tokeniser t, CharacterReader r)
            {
                if (r.MatchesLetter())
                {
                    string name = r.ConsumeLetterSequence();
                    t.TagPending.AppendTagName(name.ToLowerInvariant());
                    t.DataBuffer.Append(name);
                    
                    return;
                }

                if (t.IsAppropriateEndTagToken() && !r.IsEmpty())
                {
                    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;
                        default:
                            t.DataBuffer.Append(c);
                            AnythingElse(t, r);
                            break;
                    }
                }
                else
                {
                    AnythingElse(t, r);
                }
            }
Exemplo n.º 2
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;
     }
 }
Exemplo n.º 3
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.º 4
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);
     }
 }
Exemplo n.º 5
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     char c = r.Consume();
     switch (c)
     {
         case '>':
             t.TagPending.IsSelfClosing = true;
             t.EmitTagPending();
             t.Transition(Data);
             break;
         case _eof:
             t.EofError(this);
             t.Transition(Data);
             break;
         default:
             t.Error(this);
             t.Transition(BeforeAttributeName);
             break;
     }
 }
Exemplo n.º 6
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;
     }
 }
Exemplo n.º 7
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.º 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;
     }
 }
Exemplo n.º 9
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
                }
            }