예제 #1
0
 /// <summary>
 /// See 8.2.4.9 End tag open state
 /// </summary>
 /// <param name="c">The next input character.</param>
 HtmlToken TagEnd(Char c)
 {
     if (c.IsLowercaseAscii())
     {
         _stringBuffer.Append(c);
         return TagName(NewTagClose());
     }
     else if (c.IsUppercaseAscii())
     {
         _stringBuffer.Append(Char.ToLower(c));
         return TagName(NewTagClose());
     }
     else if (c == Symbols.GreaterThan)
     {
         _state = HtmlParseMode.PCData;
         RaiseErrorOccurred(HtmlParseError.TagClosedWrong);
         return Data(GetNext());
     }
     else if (c == Symbols.EndOfFile)
     {
         Back();
         RaiseErrorOccurred(HtmlParseError.EOF);
         _stringBuffer.Append(Symbols.LessThan).Append(Symbols.Solidus);
         return NewCharacter();
     }
     else
     {
         RaiseErrorOccurred(HtmlParseError.BogusComment);
         return BogusComment(c);
     }
 }
예제 #2
0
        /// <summary>
        /// See 8.2.4.16 RAWTEXT end tag name state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken RawtextNameEndTag(Char c)
        {
            while (true)
            {
                var token = CreateIfAppropriate(c);

                if (token != null)
                {
                    return token;
                }
                else if (c.IsUppercaseAscii())
                {
                    _stringBuffer.Append(Char.ToLower(c));
                }
                else if (c.IsLowercaseAscii())
                {
                    _stringBuffer.Append(c);
                }
                else
                {
                    _stringBuffer.Insert(0, Symbols.LessThan).Insert(1, Symbols.Solidus);
                    return RawtextText(c);
                }

                c = GetNext();
            }
        }
예제 #3
0
 /// <summary>
 /// See 8.2.4.8 Tag open state
 /// </summary>
 /// <param name="c">The next input character.</param>
 HtmlToken TagOpen(Char c)
 {
     if (c == Symbols.Solidus)
     {
         return TagEnd(GetNext());
     }
     else if (c.IsLowercaseAscii())
     {
         _stringBuffer.Append(c);
         return TagName(NewTagOpen());
     }
     else if (c.IsUppercaseAscii())
     {
         _stringBuffer.Append(Char.ToLower(c));
         return TagName(NewTagOpen());
     }
     else if (c == Symbols.ExclamationMark)
     {
         return MarkupDeclaration(GetNext());
     }
     else if (c != Symbols.QuestionMark)
     {
         _state = HtmlParseMode.PCData;
         RaiseErrorOccurred(HtmlParseError.AmbiguousOpenTag);
         _stringBuffer.Append(Symbols.LessThan);
         return DataText(c);
     }
     else
     {
         RaiseErrorOccurred(HtmlParseError.BogusComment);
         return BogusComment(c);
     }
 }
예제 #4
0
        /// <summary>
        /// See 8.2.4.8 Tag open state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken TagOpen(Char c)
        {
            if (c == Specification.EM)
            {
                return MarkupDeclaration(_src.Next);
            }
            else if (c == Specification.SOLIDUS)
            {
                return TagEnd(_src.Next);
            }
            else if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(Char.ToLower(c));
                return TagName(_src.Next, HtmlToken.OpenTag());
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c);
                return TagName(_src.Next, HtmlToken.OpenTag());
            }
            else if (c == Specification.QM)
            {
                RaiseErrorOccurred(ErrorCode.BogusComment);
                return BogusComment(c);
            }

            _model = HtmlParseMode.PCData;
            RaiseErrorOccurred(ErrorCode.AmbiguousOpenTag);
            _buffer.Append(Specification.LT);
            return Data(c);
        }
예제 #5
0
        /// <summary>
        /// See 8.2.4.14 RAWTEXT less-than sign state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken RawtextLT(Char c)
        {
            if (c == Symbols.Solidus)
            {
                // See 8.2.4.15 RAWTEXT end tag open state
                c = GetNext();

                if (c.IsUppercaseAscii())
                {
                    _stringBuffer.Append(Char.ToLower(c));
                    return RawtextNameEndTag(GetNext());
                }
                else if (c.IsLowercaseAscii())
                {
                    _stringBuffer.Append(c);
                    return RawtextNameEndTag(GetNext());
                }
                else
                {
                    _stringBuffer.Append(Symbols.LessThan).Append(Symbols.Solidus);
                    return RawtextText(c);
                }
            }
            else
            {
                _stringBuffer.Append(Symbols.LessThan);
                return RawtextText(c);
            }
        }
예제 #6
0
        /// <summary>
        /// See 8.2.4.13 RCDATA end tag name state
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        /// <returns>The emitted token.</returns>
        HtmlToken RCDataNameEndTag(Char c, HtmlTagToken tag)
        {
            var name = _stringBuffer.ToString();
            var appropriateTag = name == _lastStartTag;

            if (appropriateTag && c.IsSpaceCharacter())
            {
                tag.Name = name;
                return AttributeBeforeName(_src.Next, tag);
            }
            else if (appropriateTag && c == Specification.SOLIDUS)
            {
                tag.Name = name;
                return TagSelfClosing(_src.Next, tag);
            }
            else if (appropriateTag && c == Specification.GT)
            {
                tag.Name = name;
                return EmitTag(tag);
            }
            else if (c.IsUppercaseAscii())
            {
                _stringBuffer.Append(Char.ToLower(c));
                return RCDataNameEndTag(_src.Next, tag);
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Append(c);
                return RCDataNameEndTag(_src.Next, tag);
            }

            _buffer.Append(Specification.LT).Append(Specification.SOLIDUS);
            _buffer.Append(_stringBuffer.ToString());
            return RCData(c);
        }
예제 #7
0
 /// <summary>
 /// See 8.2.4.9 End tag open state
 /// </summary>
 /// <param name="c">The next input character.</param>
 HtmlToken TagEnd(Char c)
 {
     if (c.IsUppercaseAscii())
     {
         _stringBuffer.Clear();
         _stringBuffer.Append(Char.ToLower(c));
         return TagName(_src.Next, HtmlToken.CloseTag());
     }
     else if (c.IsLowercaseAscii())
     {
         _stringBuffer.Clear();
         _stringBuffer.Append(c);
         return TagName(_src.Next, HtmlToken.CloseTag());
     }
     else if (c == Specification.GT)
     {
         _model = HtmlParseMode.PCData;
         RaiseErrorOccurred(ErrorCode.TagClosedWrong);
         return Data(_src.Next);
     }
     else if (c == Specification.EOF)
     {
         _src.Back();
         RaiseErrorOccurred(ErrorCode.EOF);
         _buffer.Append(Specification.LT).Append(Specification.SOLIDUS);
         return HtmlToken.EOF;
     }
     else
     {
         RaiseErrorOccurred(ErrorCode.BogusComment);
         return BogusComment(c);
     }
 }
예제 #8
0
        /// <summary>
        /// See 8.2.4.11 RCDATA less-than sign state
        /// </summary>
        /// <param name="c">The next input character.</param>
        private HtmlToken RCDataLt(Char c)
        {
            if (c == Symbols.Solidus)
            {
                // See 8.2.4.12 RCDATA end tag open state
                c = GetNext();

                if (c.IsUppercaseAscii())
                {
                    StringBuffer.Append(Char.ToLowerInvariant(c));
                    return RCDataNameEndTag(GetNext());
                }
                else if (c.IsLowercaseAscii())
                {
                    StringBuffer.Append(c);
                    return RCDataNameEndTag(GetNext());
                }
                else
                {
                    StringBuffer.Append(Symbols.LessThan).Append(Symbols.Solidus);
                    return RCDataText(c);
                }
            }
            else
            {
                StringBuffer.Append(Symbols.LessThan);
                return RCDataText(c);
            }
        }
예제 #9
0
        /// <summary>
        /// See 8.2.4.12 RCDATA end tag open state
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <returns>The emitted token.</returns>
        HtmlToken RCDataEndTag(Char c)
        {
            if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(Char.ToLower(c));
                return RCDataNameEndTag(_src.Next, HtmlToken.CloseTag());
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c);
                return RCDataNameEndTag(_src.Next, HtmlToken.CloseTag());
            }

            _buffer.Append(Specification.LT).Append(Specification.SOLIDUS);
            return RCData(c);
        }
예제 #10
0
        /// <summary>
        /// See 8.2.4.25 Script data escaped less-than sign state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken ScriptDataEscapedLT(Char c)
        {
            if (c == Specification.SOLIDUS)
            {
                return ScriptDataEndTag(_src.Next);
            }
            else if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c.ToLower());
                _buffer.Append(Specification.LT);
                _buffer.Append(c);
                return ScriptDataStartDoubleEscape(_src.Next);
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Clear();
                _stringBuffer.Append(c);
                _buffer.Append(Specification.LT);
                _buffer.Append(c);
                return ScriptDataStartDoubleEscape(_src.Next);
            }

            _buffer.Append(Specification.LT);
            return ScriptDataEscaped(c);
        }
예제 #11
0
        /// <summary>
        /// See 8.2.4.28 Script data double escape start state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken ScriptDataStartDoubleEscape(Char c)
        {
            if (c.IsSpaceCharacter() || c == Specification.SOLIDUS || c == Specification.GT)
            {
                _buffer.Append(c);

                if (_stringBuffer.ToString() == "script")
                    return ScriptDataEscapedDouble(_src.Next);

                return ScriptDataEscaped(_src.Next);
            }
            else if (c.IsUppercaseAscii())
            {
                _stringBuffer.Append(c.ToLower());
                _buffer.Append(c);
                return ScriptDataStartDoubleEscape(_src.Next);
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Append(c);
                _buffer.Append(c);
                return ScriptDataStartDoubleEscape(_src.Next);
            }

            return ScriptDataEscaped(c);
        }
예제 #12
0
        /// <summary>
        /// See 8.2.4.26 Script data escaped end tag open state
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        /// <returns>The emitted token.</returns>
        HtmlToken ScriptDataEscapedEndTag(Char c, HtmlTagToken tag)
        {
            if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c.ToLower());
                return ScriptDataEscapedEndTag(_src.Next, tag);
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c);
                return ScriptDataEscapedEndTag(_src.Next, tag);
            }

            _buffer.Append(Specification.LT).Append(Specification.SOLIDUS);
            return ScriptDataEscaped(c);
        }
예제 #13
0
        /// <summary>
        /// See 8.2.4.8 Tag open state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken TagOpen(Char c)
        {
            if (c == Specification.ExclamationMark)
            {
                return MarkupDeclaration(Next);
            }
            else if (c == Specification.Solidus)
            {
                return TagEnd(Next);
            }
            else if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(Char.ToLower(c));
                return TagName(Next, HtmlToken.OpenTag());
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c);
                return TagName(Next, HtmlToken.OpenTag());
            }
            else if (c == Specification.QuestionMark)
            {
                RaiseErrorOccurred(ErrorCode.BogusComment);
                return BogusComment(c);
            }

            _state = HtmlParseMode.PCData;
            RaiseErrorOccurred(ErrorCode.AmbiguousOpenTag);
            _buffer.Append(Specification.LessThan);
            return Data(c);
        }
예제 #14
0
 /// <summary>
 /// See 8.2.4.9 End tag open state
 /// </summary>
 /// <param name="c">The next input character.</param>
 HtmlToken TagEnd(Char c)
 {
     if (c.IsUppercaseAscii())
     {
         _stringBuffer.Clear();
         _stringBuffer.Append(Char.ToLower(c));
         return TagName(Next, HtmlToken.CloseTag());
     }
     else if (c.IsLowercaseAscii())
     {
         _stringBuffer.Clear();
         _stringBuffer.Append(c);
         return TagName(Next, HtmlToken.CloseTag());
     }
     else if (c == Specification.GreaterThan)
     {
         _state = HtmlParseMode.PCData;
         RaiseErrorOccurred(ErrorCode.TagClosedWrong);
         return Data(Next);
     }
     else if (c == Specification.EndOfFile)
     {
         Back();
         RaiseErrorOccurred(ErrorCode.EOF);
         _buffer.Append(Specification.LessThan).Append(Specification.Solidus);
         return HtmlToken.EOF;
     }
     else
     {
         RaiseErrorOccurred(ErrorCode.BogusComment);
         return BogusComment(c);
     }
 }
예제 #15
0
        /// <summary>
        /// See 8.2.4.16 RAWTEXT end tag name state
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        /// <returns>The emitted token.</returns>
        HtmlToken RawtextNameEndTag(Char c, HtmlTagToken tag)
        {
            var name = _stringBuffer.ToString();
            var appropriateTag = name == _lastStartTag;

            if (appropriateTag && c.IsSpaceCharacter())
            {
                tag.Name = name;
                return AttributeBeforeName(Next, tag);
            }
            else if (appropriateTag && c == Specification.Solidus)
            {
                tag.Name = name;
                return TagSelfClosing(Next, tag);
            }
            else if (appropriateTag && c == Specification.GreaterThan)
            {
                tag.Name = name;
                return EmitTag(tag);
            }
            else if (c.IsUppercaseAscii())
            {
                _stringBuffer.Append(Char.ToLower(c));
                return RawtextNameEndTag(Next, tag);
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Append(c);
                return RawtextNameEndTag(Next, tag);
            }

            _buffer.Append(Specification.LessThan).Append(Specification.Solidus);
            _buffer.Append(_stringBuffer.ToString());
            return Rawtext(c);
        }
예제 #16
0
        /// <summary>
        /// See 8.2.4.15 RAWTEXT end tag open state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken RawtextEndTag(Char c)
        {
            if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(Char.ToLower(c));
                return RawtextNameEndTag(Next, HtmlToken.CloseTag());
            }
            else if (c.IsLowercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c);
                return RawtextNameEndTag(Next, HtmlToken.CloseTag());
            }

            _buffer.Append(Specification.LessThan).Append(Specification.Solidus);
            return Rawtext(c);
        }