System.Net.Http.Headers.Lexer.Scan C# (CSharp) Method

Scan() public method

public Scan ( bool recognizeDash = false ) : Token
recognizeDash bool
return Token
		public Token Scan (bool recognizeDash = false)
		{
			int start = pos;
			if (s == null)
				return new Token (Token.Type.Error, 0, 0);

			Token.Type ttype;
			if (pos >= s.Length) {
				ttype = Token.Type.End;
			} else {
				ttype = Token.Type.Error;
			start:
				char ch = s[pos++];
				switch (ch) {
				case ' ':
				case '\t':
					if (pos == s.Length) {
						ttype = Token.Type.End;
						break;
					}

					goto start;
				case '=':
					ttype = Token.Type.SeparatorEqual;
					break;
				case ';':
					ttype = Token.Type.SeparatorSemicolon;
					break;
				case '/':
					ttype = Token.Type.SeparatorSlash;
					break;
				case '-':
					if (recognizeDash) {
						ttype = Token.Type.SeparatorDash;
						break;
					}

					goto default;
				case ',':
					ttype = Token.Type.SeparatorComma;
					break;
				case '"':
					// Quoted string
					start = pos - 1;
					while (pos < s.Length) {
						ch = s [pos++];
						if (ch == '"') {
							ttype = Token.Type.QuotedString;
							break;
						}
					}

					break;
				case '(':
					start = pos - 1;
					ttype = Token.Type.OpenParens;
					break;
				default:
					if (ch < last_token_char && token_chars[ch]) {
						start = pos - 1;

						ttype = Token.Type.Token;
						while (pos < s.Length) {
							ch = s[pos];
							if (ch >= last_token_char || !token_chars[ch]) {
								break;
							}

							++pos;
						}
					}

					break;
				}
			}

			return new Token (ttype, start, pos);
		}
	}

Usage Example

        static bool TryParseElement(Lexer lexer, out TransferCodingWithQualityHeaderValue parsedValue, out Token t)
        {
            parsedValue = null;

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

            var result = new TransferCodingWithQualityHeaderValue();

            result.value = lexer.GetStringValue(t);

            t = lexer.Scan();

            // Parameters parsing
            if (t == Token.Type.SeparatorSemicolon && (!NameValueHeaderValue.TryParseParameters(lexer, out result.parameters, out t) || t != Token.Type.End))
            {
                return(false);
            }

            parsedValue = result;
            return(true);
        }
All Usage Examples Of System.Net.Http.Headers.Lexer::Scan