예제 #1
0
        private Block BadUrl(char current)
        {
            while (true)
            {
                if (current == Specification.EndOfFile)
                {
                    ErrorHandler(ParserError.EndOfFile, ErrorMessages.InvalidUrlEnd);

                    return(StringBlock.Url(FlushBuffer(), true));
                }

                if (current == Specification.ParenClose)
                {
                    return(StringBlock.Url(FlushBuffer(), true));
                }

                if (IsValidEscape(current))
                {
                    current = _stylesheetReader.Next;
                    _buffer.Append(ConsumeEscape(current));
                }

                current = _stylesheetReader.Next;
            }
        }
예제 #2
0
        private Block UrlStart(char current)
        {
            while (current.IsSpaceCharacter())
            {
                current = _stylesheetReader.Next;
            }

            switch (current)
            {
            case Specification.EndOfFile:
                ErrorHandler(ParserError.EndOfFile, ErrorMessages.InvalidUrlEnd);
                return(StringBlock.Url(string.Empty, true));

            case Specification.DoubleQuote:
                return(DoubleQuotedUrl(_stylesheetReader.Next));

            case Specification.SingleQuote:
                return(SingleQuoteUrl(_stylesheetReader.Next));

            case ')':
                return(StringBlock.Url(string.Empty));

            default:
                return(UnquotedUrl(current));
            }
        }
예제 #3
0
        private Block SingleQuoteUrl(char current)
        {
            while (true)
            {
                if (current.IsLineBreak())
                {
                    ErrorHandler(ParserError.UnexpectedLineBreak, ErrorMessages.SingleQuotedString);
                    return(BadUrl(_stylesheetReader.Next));
                }

                if (Specification.EndOfFile == current)
                {
                    return(StringBlock.Url(FlushBuffer()));
                }

                if (current == Specification.SingleQuote)
                {
                    return(UrlEnd(_stylesheetReader.Next));
                }

                if (current == Specification.ReverseSolidus)
                {
                    current = _stylesheetReader.Next;

                    if (current == Specification.EndOfFile)
                    {
                        _stylesheetReader.Back(2);
                        ErrorHandler(ParserError.EndOfFile, ErrorMessages.SingleQuotedString);
                        return(StringBlock.Url(FlushBuffer(), true));
                    }

                    if (current.IsLineBreak())
                    {
                        _buffer.AppendLine();
                    }
                    else
                    {
                        _buffer.Append(ConsumeEscape(current));
                    }
                }
                else
                {
                    _buffer.Append(current);
                }

                current = _stylesheetReader.Next;
            }
        }
예제 #4
0
        private Block UrlEnd(char current)
        {
            while (true)
            {
                if (current == Specification.ParenClose)
                {
                    return(StringBlock.Url(FlushBuffer()));
                }

                if (!current.IsSpaceCharacter())
                {
                    ErrorHandler(ParserError.InvalidCharacter, ErrorMessages.InvalidUrlCharacter);
                    return(BadUrl(current));
                }

                current = _stylesheetReader.Next;
            }
        }
예제 #5
0
        private Block UnquotedUrl(char current)
        {
            while (true)
            {
                if (current.IsSpaceCharacter())
                {
                    return(UrlEnd(_stylesheetReader.Next));
                }

                if (current == Specification.ParenClose || current == Specification.EndOfFile)
                {
                    return(StringBlock.Url(FlushBuffer()));
                }

                if (current == Specification.DoubleQuote || current == Specification.SingleQuote ||
                    current == Specification.ParenOpen || current.IsNonPrintable())
                {
                    ErrorHandler(ParserError.InvalidCharacter, ErrorMessages.InvalidUrlQuote);
                    return(BadUrl(_stylesheetReader.Next));
                }

                if (current == Specification.ReverseSolidus)
                {
                    if (IsValidEscape(current))
                    {
                        current = _stylesheetReader.Next;
                        _buffer.Append(ConsumeEscape(current));
                    }
                    else
                    {
                        ErrorHandler(ParserError.InvalidCharacter, ErrorMessages.InvalidUrlCharacter);
                        return(BadUrl(_stylesheetReader.Next));
                    }
                }
                else
                {
                    _buffer.Append(current);
                }

                current = _stylesheetReader.Next;
            }
        }