EatChar() public méthode

public EatChar ( ) : void
Résultat void
        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);
        }
Exemple #2
0
        internal static bool TryParse(string input, int minimalCount, out List <ProductInfoHeaderValue> result)
        {
            var list  = new List <ProductInfoHeaderValue> ();
            var lexer = new Lexer(input);

            result = null;

            while (true)
            {
                ProductInfoHeaderValue element;
                if (!TryParseElement(lexer, out element))
                {
                    return(false);
                }

                if (element == null)
                {
                    if (list != null && minimalCount <= list.Count)
                    {
                        result = list;
                        return(true);
                    }

                    return(false);
                }

                list.Add(element);

                // Separator parsing
                switch (lexer.PeekChar())
                {
                case ' ':
                case '\t':
                    lexer.EatChar();
                    continue;

                case -1:
                    if (minimalCount <= list.Count)
                    {
                        result = list;
                        return(true);
                    }

                    break;
                }

                return(false);
            }
        }
        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);
        }
Exemple #4
0
		public static bool TryParse (string input, out WarningHeaderValue parsedValue)
		{
			parsedValue = null;

			var lexer = new Lexer (input);
			var 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 ();
			}

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

			parsedValue = value;
			return true;
		}
		internal static bool TryParse (string input, int minimalCount, out List<ProductInfoHeaderValue> result)
		{
			var list = new List<ProductInfoHeaderValue> ();
			var lexer = new Lexer (input);
			result = null;

			while (true) {
				ProductInfoHeaderValue element;
				if (!TryParseElement (lexer, out element))
					return false;

				if (element == null) {
					if (list != null && minimalCount <= list.Count) {
						result = list;
						return true;
					}

					return false;
				}

				list.Add (element);

				// Separator parsing
				switch (lexer.PeekChar ()) {
				case ' ':
				case '\t':
					lexer.EatChar ();
					continue;
				case -1:
					if (minimalCount <= list.Count) {
						result = list;
						return true;
					}

					break;
				}
					
				return false;
			}
		}
Exemple #6
0
		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;
		}
		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;
		}
Exemple #8
0
        public static bool TryParse(string input, out WarningHeaderValue parsedValue)
        {
            parsedValue = null;

            var lexer = new Lexer(input);
            var 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();
            }

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

            parsedValue = value;
            return(true);
        }
		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;
		}
Exemple #10
0
        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);
        }