Exemplo n.º 1
0
        /// <summary>
        /// See 8.2.4.53 Before DOCTYPE name state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken DoctypeNameBefore(Char c)
        {
            while (c.IsSpaceCharacter())
                c = Next;

            if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(Char.ToLower(c));
                return DoctypeName(Next, HtmlToken.Doctype(false));
            }
            else if (c == Specification.Null)
            {
                RaiseErrorOccurred(ErrorCode.Null);
                _stringBuffer.Clear();
                _stringBuffer.Append(Specification.Replacement);
                return DoctypeName(Next, HtmlToken.Doctype(false));
            }
            else if (c == Specification.GreaterThan)
            {
                _state = HtmlParseMode.PCData;
                RaiseErrorOccurred(ErrorCode.TagClosedWrong);
                return HtmlToken.Doctype(true);
            }
            else if (c == Specification.EndOfFile)
            {
                RaiseErrorOccurred(ErrorCode.EOF);
                Back();
                return HtmlToken.Doctype(true);
            }

            _stringBuffer.Clear();
            _stringBuffer.Append(c);
            return DoctypeName(Next, HtmlToken.Doctype(false));
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 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 == 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);
     }
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// See 8.2.4.54 DOCTYPE name state
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="doctype">The current doctype token.</param>
        /// <returns>The emitted token.</returns>
        HtmlToken DoctypeName(Char c, HtmlDoctypeToken doctype)
        {
            while (true)
            {
                if (c.IsSpaceCharacter())
                {
                    doctype.Name = _stringBuffer.ToString();
                    _stringBuffer.Clear();
                    return DoctypeNameAfter(_src.Next, doctype);
                }
                else if (c == Specification.GT)
                {
                    _model = HtmlParseMode.PCData;
                    doctype.Name = _stringBuffer.ToString();
                    return doctype;
                }
                else if (c.IsUppercaseAscii())
                    _stringBuffer.Append(Char.ToLower(c));
                else if (c == Specification.NULL)
                {
                    RaiseErrorOccurred(ErrorCode.NULL);
                    _stringBuffer.Append(Specification.REPLACEMENT);
                }
                else if (c == Specification.EOF)
                {
                    RaiseErrorOccurred(ErrorCode.EOF);
                    _src.Back();
                    doctype.IsQuirksForced = true;
                    doctype.Name = _stringBuffer.ToString();
                    return doctype;
                }
                else
                    _stringBuffer.Append(c);

                c = _src.Next;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// See 8.2.4.35 Attribute 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 AttributeName(Char c, HtmlTagToken tag)
        {
            while (true)
            {
                if (c.IsSpaceCharacter())
                {
                    tag.AddAttribute(_stringBuffer.ToString());
                    return AttributeAfterName(Next, tag);
                }
                else if (c == Specification.Solidus)
                {
                    tag.AddAttribute(_stringBuffer.ToString());
                    return TagSelfClosing(Next, tag);
                }
                else if (c == Specification.Equality)
                {
                    tag.AddAttribute(_stringBuffer.ToString());
                    return AttributeBeforeValue(Next, tag);
                }
                else if (c == Specification.GreaterThan)
                {
                    tag.AddAttribute(_stringBuffer.ToString());
                    return EmitTag(tag);
                }
                else if (c == Specification.EndOfFile)
                    return HtmlToken.EOF;
                else if (c == Specification.Null)
                {
                    RaiseErrorOccurred(ErrorCode.Null);
                    _stringBuffer.Append(Specification.Replacement);
                }
                else if (c.IsUppercaseAscii())
                    _stringBuffer.Append(Char.ToLower(c));
                else if (c == Specification.DoubleQuote || c == Specification.SingleQuote || c == Specification.LessThan)
                {
                    RaiseErrorOccurred(ErrorCode.AttributeNameInvalid);
                    _stringBuffer.Append(c);
                }
                else
                    _stringBuffer.Append(c);

                c = Next;
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// See 8.2.4.10 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 TagName(Char c, HtmlTagToken tag)
        {
            while (true)
            {
                if (c.IsSpaceCharacter())
                {
                    tag.Name = _stringBuffer.ToString();
                    return AttributeBeforeName(Next, tag);
                }
                else if (c == Specification.Solidus)
                {
                    tag.Name = _stringBuffer.ToString();
                    return TagSelfClosing(Next, tag);
                }
                else if (c == Specification.GreaterThan)
                {
                    tag.Name = _stringBuffer.ToString();
                    return EmitTag(tag);
                }
                else if (c == Specification.Null)
                {
                    RaiseErrorOccurred(ErrorCode.Null);
                    _stringBuffer.Append(Specification.Replacement);
                }
                else if (c == Specification.EndOfFile)
                {
                    RaiseErrorOccurred(ErrorCode.EOF);
                    return HtmlToken.EOF;
                }
                else if (c.IsUppercaseAscii())
                    _stringBuffer.Append(Char.ToLower(c));
                else
                    _stringBuffer.Append(c);

                c = Next;
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
     }
 }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        /// <summary>
        /// See 8.2.4.53 Before DOCTYPE name state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken DoctypeNameBefore(Char c)
        {
            while (c.IsSpaceCharacter())
                c = _src.Next;

            if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(Char.ToLower(c));
                return DoctypeName(_src.Next, HtmlToken.Doctype(false));
            }
            else if (c == Specification.NULL)
            {
                RaiseErrorOccurred(ErrorCode.NULL);
                _stringBuffer.Clear();
                _stringBuffer.Append(Specification.REPLACEMENT);
                return DoctypeName(_src.Next, HtmlToken.Doctype(false));
            }
            else if (c == Specification.GT)
            {
                _model = HtmlParseMode.PCData;
                RaiseErrorOccurred(ErrorCode.TagClosedWrong);
                return HtmlToken.Doctype(true);
            }
            else if (c == Specification.EOF)
            {
                RaiseErrorOccurred(ErrorCode.EOF);
                _src.Back();
                return HtmlToken.Doctype(true);
            }

            _stringBuffer.Clear();
            _stringBuffer.Append(c);
            return DoctypeName(_src.Next, HtmlToken.Doctype(false));
        }
Exemplo n.º 15
0
        /// <summary>
        /// See 8.2.4.54 DOCTYPE name state
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="doctype">The current doctype token.</param>
        /// <returns>The emitted token.</returns>
        HtmlToken DoctypeName(Char c, HtmlDoctypeToken doctype)
        {
            while (true)
            {
                if (c.IsSpaceCharacter())
                {
                    doctype.Name = _stringBuffer.ToString();
                    _stringBuffer.Clear();
                    return DoctypeNameAfter(Next, doctype);
                }
                else if (c == Specification.GreaterThan)
                {
                    _state = HtmlParseMode.PCData;
                    doctype.Name = _stringBuffer.ToString();
                    return doctype;
                }
                else if (c.IsUppercaseAscii())
                    _stringBuffer.Append(Char.ToLower(c));
                else if (c == Specification.Null)
                {
                    RaiseErrorOccurred(ErrorCode.Null);
                    _stringBuffer.Append(Specification.Replacement);
                }
                else if (c == Specification.EndOfFile)
                {
                    RaiseErrorOccurred(ErrorCode.EOF);
                    Back();
                    doctype.IsQuirksForced = true;
                    doctype.Name = _stringBuffer.ToString();
                    return doctype;
                }
                else
                    _stringBuffer.Append(c);

                c = Next;
            }
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        /// <summary>
        /// See 8.2.4.34 Before attribute 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 AttributeBeforeName(Char c, HtmlTagToken tag)
        {
            while (c.IsSpaceCharacter())
                c = _src.Next;

            if (c == Specification.SOLIDUS)
            {
                return TagSelfClosing(_src.Next, tag);
            }
            else if (c == Specification.GT)
            {
                return EmitTag(tag);
            }
            else if (c.IsUppercaseAscii())
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c.ToLower());
                return AttributeName(_src.Next, tag);
            }
            else if (c == Specification.NULL)
            {
                RaiseErrorOccurred(ErrorCode.NULL);
                _stringBuffer.Clear();
                _stringBuffer.Append(Specification.REPLACEMENT);
                return AttributeName(_src.Next, tag);
            }
            else if (c == Specification.SQ || c == Specification.DQ || c == Specification.EQ || c == Specification.LT)
            {
                RaiseErrorOccurred(ErrorCode.AttributeNameInvalid);
                _stringBuffer.Clear();
                _stringBuffer.Append(c);
                return AttributeName(_src.Next, tag);
            }
            else if (c == Specification.EOF)
            {
                return HtmlToken.EOF;
            }
            else
            {
                _stringBuffer.Clear();
                _stringBuffer.Append(c);
                return AttributeName(_src.Next, tag);
            }
        }
Exemplo n.º 18
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);
     }
 }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        /// <summary>
        /// See 8.2.4.35 Attribute 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 AttributeName(Char c, HtmlTagToken tag)
        {
            while (true)
            {
                if (c.IsSpaceCharacter())
                {
                    tag.AddAttribute(_stringBuffer.ToString());
                    return AttributeAfterName(_src.Next, tag);
                }
                else if (c == Specification.SOLIDUS)
                {
                    tag.AddAttribute(_stringBuffer.ToString());
                    return TagSelfClosing(_src.Next, tag);
                }
                else if (c == Specification.EQ)
                {
                    tag.AddAttribute(_stringBuffer.ToString());
                    return AttributeBeforeValue(_src.Next, tag);
                }
                else if (c == Specification.GT)
                {
                    tag.AddAttribute(_stringBuffer.ToString());
                    return EmitTag(tag);
                }
                else if (c == Specification.EOF)
                    return HtmlToken.EOF;
                else if (c == Specification.NULL)
                {
                    RaiseErrorOccurred(ErrorCode.NULL);
                    _stringBuffer.Append(Specification.REPLACEMENT);
                }
                else if (c.IsUppercaseAscii())
                    _stringBuffer.Append(Char.ToLower(c));
                else if (c == Specification.DQ || c == Specification.SQ || c == Specification.LT)
                {
                    RaiseErrorOccurred(ErrorCode.AttributeNameInvalid);
                    _stringBuffer.Append(c);
                }
                else
                    _stringBuffer.Append(c);

                c = _src.Next;
            }
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        /// <summary>
        /// See 8.2.4.53 Before DOCTYPE name state
        /// </summary>
        /// <param name="c">The next input character.</param>
        HtmlToken DoctypeNameBefore(Char c)
        {
            while (c.IsSpaceCharacter())
                c = GetNext();

            if (c.IsUppercaseAscii())
            {
                var doctype = NewDoctype(false);
                _stringBuffer.Append(Char.ToLower(c));
                return DoctypeName(doctype);
            }
            else if (c == Symbols.Null)
            {
                var doctype = NewDoctype(false);
                RaiseErrorOccurred(HtmlParseError.Null);
                _stringBuffer.Append(Symbols.Replacement);
                return DoctypeName(doctype);
            }
            else if (c == Symbols.GreaterThan)
            {
                var doctype = NewDoctype(true);
                _state = HtmlParseMode.PCData;
                RaiseErrorOccurred(HtmlParseError.TagClosedWrong);
                return doctype;
            }
            else if (c == Symbols.EndOfFile)
            {
                var doctype = NewDoctype(true);
                RaiseErrorOccurred(HtmlParseError.EOF);
                Back();
                return doctype;
            }
            else
            {
                var doctype = NewDoctype(false);
                _stringBuffer.Append(c);
                return DoctypeName(doctype);
            }
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
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();
            }
        }
Exemplo n.º 25
0
        AttributeDeclarationEntry AttributeDeclarationType(Char c, AttributeDeclarationEntry value)
        {
            while (c.IsSpaceCharacter())
                c = _src.Next;

            if (c == Specification.RBO)
            {
                var type = new AttributeEnumeratedType();
                value.ValueType = type;
                AttributeDeclarationTypeEnumeration(_src.Next, type);
            }
            else if (c.IsUppercaseAscii())
            {
                var id = String.Empty;

                while (true)
                {
                    if (c.IsSpaceCharacter())
                    {
                        id = _stringBuffer.ToString();
                        _stringBuffer.Clear();
                        break;
                    }
                    else if (c == Specification.GT)
                        throw new ArgumentException("Declaration invalid.");
                    else if (c == Specification.NULL)
                    {
                        RaiseErrorOccurred(ErrorCode.NULL);
                        _stringBuffer.Append(Specification.REPLACEMENT);
                    }
                    else if (c == Specification.EOF)
                        throw new ArgumentException("The document ended unexpectedly.");
                    else
                        _stringBuffer.Append(c);

                    c = _src.Next;
                }

                switch (id)
                {
                    case "CDATA":
                        value.ValueType = new AttributeStringType();
                        break;
                    case "ID":
                        value.ValueType = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.ID };
                        break;
                    case "IDREF":
                        value.ValueType = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.IDREF };
                        break;
                    case "IDREFS":
                        value.ValueType = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.IDREFS };
                        break;
                    case "ENTITY":
                        value.ValueType = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.ENTITY };
                        break;
                    case "ENTITIES":
                        value.ValueType = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.ENTITIES };
                        break;
                    case "NMTOKEN":
                        value.ValueType = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.NMTOKEN };
                        break;
                    case "NMTOKENS":
                        value.ValueType = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.NMTOKENS };
                        break;
                    case "NOTATION":
                        var type = new AttributeEnumeratedType { IsNotation = true };
                        value.ValueType = type;

                        while (c.IsSpaceCharacter())
                            c = _src.Next;

                        if (c != Specification.RBO)
                            throw new ArgumentException("Declaration invalid.");

                        AttributeDeclarationTypeEnumeration(_src.Next, type);
                        break;
                    default:
                        throw new ArgumentException("Declaration invalid.");
                }
            }

            return AttributeDeclarationValue(_src.Next, value);
        }
Exemplo n.º 26
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);
     }
 }
Exemplo n.º 27
0
        AttributeDeclarationEntry AttributeDeclarationType(Char c, AttributeDeclarationEntry value)
        {
            while (c.IsSpaceCharacter())
                c = _stream.Next;

            if (c == Specification.RBO)
            {
                var type = new AttributeEnumeratedType();
                value.Type = type;
                AttributeDeclarationTypeEnumeration(_stream.Next, type);
            }
            else if (c.IsUppercaseAscii())
            {
                var id = String.Empty;

                while (true)
                {
                    if (c.IsSpaceCharacter())
                    {
                        id = _stringBuffer.ToString();
                        _stringBuffer.Clear();
                        break;
                    }
                    else if (c == Specification.GT)
                        throw Errors.Xml(ErrorCode.DtdAttListInvalid);
                    else if (c == Specification.NULL)
                    {
                        RaiseErrorOccurred(ErrorCode.NULL);
                        _stringBuffer.Append(Specification.REPLACEMENT);
                    }
                    else if (c == Specification.EOF)
                        throw Errors.Xml(ErrorCode.EOF);
                    else
                        _stringBuffer.Append(c);

                    c = _stream.Next;
                }

                switch (id)
                {
                    case CDATA:
                        value.Type = new AttributeStringType();
                        break;

                    case ID:
                        value.Type = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.ID };
                        break;

                    case IDREF:
                        value.Type = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.IDREF };
                        break;

                    case IDREFS:
                        value.Type = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.IDREFS };
                        break;

                    case ENTITY:
                        value.Type = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.ENTITY };
                        break;

                    case ENTITIES:
                        value.Type = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.ENTITIES };
                        break;

                    case NMTOKEN:
                        value.Type = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.NMTOKEN };
                        break;

                    case NMTOKENS:
                        value.Type = new AttributeTokenizedType { Value = AttributeTokenizedType.TokenizedType.NMTOKENS };
                        break;

                    case NOTATION:
                        var type = new AttributeEnumeratedType { IsNotation = true };
                        value.Type = type;

                        while (c.IsSpaceCharacter())
                            c = _stream.Next;

                        if (c != Specification.RBO)
                            throw Errors.Xml(ErrorCode.DtdAttListInvalid);

                        AttributeDeclarationTypeEnumeration(_stream.Next, type);
                        break;

                    default:
                        throw Errors.Xml(ErrorCode.DtdAttListInvalid);
                }
            }

            return AttributeDeclarationValue(_stream.Next, value);
        }