Beispiel #1
0
        /// <summary>
        /// 4.4.17. URL state
        /// </summary>
        CssToken UrlStart(Char current, CssTokenType type)
        {
            while (current.IsSpaceCharacter())
            {
                current = _src.Next;
            }

            switch (current)
            {
            case Specification.EndOfFile:
                RaiseErrorOccurred(ErrorCode.EOF);
                return(CssStringToken.Url(type, String.Empty, true));

            case Specification.DoubleQuote:
                return(UrlDQ(_src.Next, type));

            case Specification.SingleQuote:
                return(UrlSQ(_src.Next, type));

            case ')':
                return(CssStringToken.Url(type, String.Empty, false));

            default:
                return(UrlUQ(current, type));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 4.4.20. URL-end state
        /// </summary>
        CssToken UrlEnd(Char current, CssTokenType type)
        {
            while (true)
            {
                if (current == Specification.RoundBracketClose)
                {
                    return(CssStringToken.Url(type, FlushBuffer()));
                }
                else if (!current.IsSpaceCharacter())
                {
                    RaiseErrorOccurred(ErrorCode.InvalidCharacter);
                    return(UrlBad(current, type));
                }

                current = _src.Next;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 4.4.20. URL-end state
        /// </summary>
        CssToken UrlEnd(CssTokenType type)
        {
            while (true)
            {
                var current = GetNext();

                if (current == Symbols.RoundBracketClose)
                {
                    return(CssStringToken.Url(type, FlushBuffer()));
                }
                else if (!current.IsSpaceCharacter())
                {
                    RaiseErrorOccurred(ErrorCode.InvalidCharacter);
                    Back();
                    return(UrlBad(type));
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 4.4.18. URL-double-quoted state
        /// </summary>
        CssToken UrlDQ(CssTokenType type)
        {
            while (true)
            {
                var current = GetNext();

                if (current.IsLineBreak())
                {
                    RaiseErrorOccurred(ErrorCode.LineBreakUnexpected);
                    return(UrlBad(type));
                }
                else if (Symbols.EndOfFile == current)
                {
                    return(CssStringToken.Url(type, FlushBuffer()));
                }
                else if (current == Symbols.DoubleQuote)
                {
                    return(UrlEnd(type));
                }
                else if (current == Symbols.ReverseSolidus)
                {
                    current = GetNext();

                    if (current == Symbols.EndOfFile)
                    {
                        Back(2);
                        RaiseErrorOccurred(ErrorCode.EOF);
                        return(CssStringToken.Url(type, FlushBuffer(), true));
                    }
                    else if (current.IsLineBreak())
                    {
                        _stringBuffer.AppendLine();
                    }
                    else
                    {
                        _stringBuffer.Append(ConsumeEscape(current));
                    }
                }
                else
                {
                    _stringBuffer.Append(current);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 4.4.18. URL-double-quoted state
        /// </summary>
        CssToken UrlDQ(Char current, CssTokenType type)
        {
            while (true)
            {
                if (current.IsLineBreak())
                {
                    RaiseErrorOccurred(ErrorCode.LineBreakUnexpected);
                    return(UrlBad(_src.Next, type));
                }
                else if (Specification.EndOfFile == current)
                {
                    return(CssStringToken.Url(type, FlushBuffer()));
                }
                else if (current == Specification.DoubleQuote)
                {
                    return(UrlEnd(_src.Next, type));
                }
                else if (current == Specification.ReverseSolidus)
                {
                    current = _src.Next;

                    if (current == Specification.EndOfFile)
                    {
                        _src.Back(2);
                        RaiseErrorOccurred(ErrorCode.EOF);
                        return(CssStringToken.Url(type, FlushBuffer(), true));
                    }
                    else if (current.IsLineBreak())
                    {
                        _stringBuffer.AppendLine();
                    }
                    else
                    {
                        _stringBuffer.Append(ConsumeEscape(current));
                    }
                }
                else
                {
                    _stringBuffer.Append(current);
                }

                current = _src.Next;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 4.4.22. Bad URL state
        /// </summary>
        CssToken UrlBad(CssTokenType type)
        {
            while (true)
            {
                var current = GetNext();

                if (current == Symbols.EndOfFile)
                {
                    RaiseErrorOccurred(ErrorCode.EOF);
                    return(CssStringToken.Url(type, FlushBuffer(), true));
                }
                else if (current == Symbols.RoundBracketClose)
                {
                    return(CssStringToken.Url(type, FlushBuffer(), true));
                }
                else if (IsValidEscape(current))
                {
                    current = GetNext();
                    _stringBuffer.Append(ConsumeEscape(current));
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 4.4.22. Bad URL state
        /// </summary>
        CssToken UrlBad(Char current, CssTokenType type)
        {
            while (true)
            {
                if (current == Specification.EndOfFile)
                {
                    RaiseErrorOccurred(ErrorCode.EOF);
                    return(CssStringToken.Url(type, FlushBuffer(), true));
                }
                else if (current == Specification.RoundBracketClose)
                {
                    return(CssStringToken.Url(type, FlushBuffer(), true));
                }
                else if (IsValidEscape(current))
                {
                    current = _src.Next;
                    _stringBuffer.Append(ConsumeEscape(current));
                }

                current = _src.Next;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 4.4.21. URL-unquoted state
        /// </summary>
        CssToken UrlUQ(Char current, CssTokenType type)
        {
            while (true)
            {
                if (current.IsSpaceCharacter())
                {
                    return(UrlEnd(type));
                }
                else if (current == Symbols.RoundBracketClose || current == Symbols.EndOfFile)
                {
                    return(CssStringToken.Url(type, FlushBuffer()));
                }
                else if (current == Symbols.DoubleQuote || current == Symbols.SingleQuote || current == Symbols.RoundBracketOpen || current.IsNonPrintable())
                {
                    RaiseErrorOccurred(ErrorCode.InvalidCharacter);
                    return(UrlBad(type));
                }
                else if (current == Symbols.ReverseSolidus)
                {
                    if (IsValidEscape(current))
                    {
                        current = GetNext();
                        _stringBuffer.Append(ConsumeEscape(current));
                    }
                    else
                    {
                        RaiseErrorOccurred(ErrorCode.InvalidCharacter);
                        return(UrlBad(type));
                    }
                }
                else
                {
                    _stringBuffer.Append(current);
                }

                current = GetNext();
            }
        }
Beispiel #9
0
        /// <summary>
        /// 4.4.17. URL state
        /// </summary>
        CssToken UrlStart(CssTokenType type)
        {
            var current = SkipSpaces();

            switch (current)
            {
            case Symbols.EndOfFile:
                RaiseErrorOccurred(ErrorCode.EOF);
                return(CssStringToken.Url(type, String.Empty, true));

            case Symbols.DoubleQuote:
                return(UrlDQ(type));

            case Symbols.SingleQuote:
                return(UrlSQ(type));

            case ')':
                return(CssStringToken.Url(type, String.Empty, false));

            default:
                return(UrlUQ(current, type));
            }
        }