static bool TryParseElement(Lexer lexer, out ProductInfoHeaderValue parsedValue)
        {
            string comment;

            parsedValue = null;
            Token t;

            if (lexer.ScanCommentOptional(out comment, out t))
            {
                if (comment == null)
                {
                    return(false);
                }

                parsedValue         = new ProductInfoHeaderValue();
                parsedValue.Comment = comment;
                return(true);
            }

            if (t == Token.Type.End)
            {
                return(true);
            }

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

            var value = new ProductHeaderValue();

            value.Name = lexer.GetStringValue(t);

            var pos = lexer.Position;

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

                value.Version = lexer.GetStringValue(t);
            }
            else
            {
                lexer.Position = pos;
            }

            parsedValue = new ProductInfoHeaderValue(value);
            return(true);
        }
Ejemplo n.º 2
0
            public static void CheckComment(string s)
            {
                if (s == null)
                {
                    throw new ArgumentNullException();
                }

                var lexer = new Lexer(s);

                string temp;

                if (!lexer.ScanCommentOptional(out temp))
                {
                    if (s.Length == 0)
                    {
                        throw new ArgumentException();
                    }

                    throw new FormatException(s);
                }
            }
        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);
        }