Example #1
0
        DateTimeOffset?GetDateValue(string name)
        {
            var value = FindParameter(name);

            if (value == null || value == null)
            {
                return(null);
            }

            if (value.Length < 3)
            {
                return(null);
            }

            if (value[0] == '\"')
            {
                value = value.Substring(1, value.Length - 2);
            }

            DateTimeOffset offset;

            if (Lexer.TryGetDateValue(value, out offset))
            {
                return(offset);
            }

            return(null);
        }
Example #2
0
        public static bool TryParse(string input, out RangeConditionHeaderValue parsedValue)
        {
            parsedValue = null;

            var  lexer = new Lexer(input);
            var  t     = lexer.Scan();
            bool is_weak;

            if (t == Token.Type.Token)
            {
                if (lexer.GetStringValue(t) != "W")
                {
                    DateTimeOffset date;
                    if (!Lexer.TryGetDateValue(input, out date))
                    {
                        return(false);
                    }

                    parsedValue = new RangeConditionHeaderValue(date);
                    return(true);
                }

                if (lexer.PeekChar() != '/')
                {
                    return(false);
                }

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

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

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

            parsedValue = new RangeConditionHeaderValue(
                new EntityTagHeaderValue()
            {
                Tag    = lexer.GetStringValue(t),
                IsWeak = is_weak
            });

            return(true);
        }
Example #3
0
        public static bool TryParse(string input, out RetryConditionHeaderValue parsedValue)
        {
            parsedValue = null;

            var lexer = new Lexer(input);
            var t     = lexer.Scan();

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

            var ts = lexer.TryGetTimeSpanValue(t);

            if (ts != null)
            {
                if (lexer.Scan() != Token.Type.End)
                {
                    return(false);
                }

                parsedValue = new RetryConditionHeaderValue(ts.Value);
            }
            else
            {
                DateTimeOffset date;
                if (!Lexer.TryGetDateValue(input, out date))
                {
                    return(false);
                }

                parsedValue = new RetryConditionHeaderValue(date);
            }

            return(true);
        }
Example #4
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);
        }
Example #5
0
 public static bool TryParse(string input, out DateTimeOffset result)
 {
     return(Lexer.TryGetDateValue(input, out result));
 }