Ejemplo n.º 1
0
        static bool TryParseElement(Lexer lexer, out EntityTagHeaderValue parsedValue, out Token t)
        {
            parsedValue = null;

            t = lexer.Scan();
            bool is_weak = false;

            if (t == Token.Type.Token)
            {
                var s = lexer.GetStringValue(t);
                if (s == "*")
                {
                    parsedValue = any;

                    t = lexer.Scan();
                    return(true);
                }

                if (s != "W" || lexer.PeekChar() != '/')
                {
                    return(false);
                }

                is_weak = true;
                lexer.EatChar();
                t = lexer.Scan();
            }

            if (t != Token.Type.QuotedString)
            {
                return(false);
            }

            parsedValue        = new EntityTagHeaderValue();
            parsedValue.Tag    = lexer.GetStringValue(t);
            parsedValue.IsWeak = is_weak;

            t = lexer.Scan();

            return(true);
        }
        static bool TryParseElement(Lexer lexer, out ViaHeaderValue parsedValue, out Token t)
        {
            parsedValue = null;

            t = lexer.Scan();
            if (t != Token.Type.Token)
            {
                return(false);
            }

            var            next  = lexer.Scan();
            ViaHeaderValue value = new ViaHeaderValue();

            if (next == Token.Type.SeparatorSlash)
            {
                next = lexer.Scan();
                if (next != Token.Type.Token)
                {
                    return(false);
                }

                value.ProtocolName    = lexer.GetStringValue(t);
                value.ProtocolVersion = lexer.GetStringValue(next);

                next = lexer.Scan();
            }
            else
            {
                value.ProtocolVersion = lexer.GetStringValue(t);
            }

            if (next != Token.Type.Token)
            {
                return(false);
            }

            if (lexer.PeekChar() == ':')
            {
                lexer.EatChar();

                t = lexer.Scan();
                if (t != Token.Type.Token)
                {
                    return(false);
                }
            }
            else
            {
                t = next;
            }

            value.ReceivedBy = lexer.GetStringValue(next, t);

            string comment;

            if (lexer.ScanCommentOptional(out comment, out t))
            {
                t = lexer.Scan();
            }

            value.Comment = comment;
            parsedValue   = value;
            return(true);
        }
Ejemplo n.º 3
0
        static bool TryParseElement(Lexer lexer, out WarningHeaderValue parsedValue, out Token t)
        {
            parsedValue = null;

            t = lexer.Scan();

            if (t != Token.Type.Token)
            {
                return(false);
            }

            int code;

            if (!lexer.TryGetNumericValue(t, out code) || !IsCodeValid(code))
            {
                return(false);
            }

            t = lexer.Scan();
            if (t != Token.Type.Token)
            {
                return(false);
            }

            var next = t;

            if (lexer.PeekChar() == ':')
            {
                lexer.EatChar();

                next = lexer.Scan();
                if (next != Token.Type.Token)
                {
                    return(false);
                }
            }

            var value = new WarningHeaderValue();

            value.Code  = code;
            value.Agent = lexer.GetStringValue(t, next);

            t = lexer.Scan();
            if (t != Token.Type.QuotedString)
            {
                return(false);
            }

            value.Text = lexer.GetStringValue(t);

            t = lexer.Scan();
            if (t == Token.Type.QuotedString)
            {
                DateTimeOffset date;
                if (!lexer.TryGetDateValue(t, out date))
                {
                    return(false);
                }

                value.Date = date;
                t          = lexer.Scan();
            }

            parsedValue = value;
            return(true);
        }