HeaderScanner class final
A cursor-based scanner for HTTP header field values.
Provides the lexer primitives every typed header parser needs:
- RFC 9110
OWSskipping (skipOws). tokenreading (readToken, tryReadToken).quoted-stringreading withquoted-pairunescaping (readQuotedString, tryReadQuotedString).- The canonical
token / quoted-stringalternation (readTokenOrQuotedString, tryReadTokenOrQuotedString). - Quote-aware top-level scanning (indexOfTopLevel, splitTopLevel) so
list and parameter separators inside a
quoted-stringare not treated as structural delimiters.
All methods throw FormatException on malformed input, reporting the scanner's current position within source.
Constructors
- HeaderScanner(String source)
-
Creates a scanner positioned at the start of
source.
Properties
- atEnd → bool
-
True when the cursor has reached the end of source.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- position ↔ int
-
The current cursor position (0-based, inclusive).
getter/setter pair
- remaining → int
-
Number of code units remaining after the cursor.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- source → String
-
The full source string being scanned.
final
Methods
-
expect(
int char) → void -
Consumes
charat the cursor, otherwise throws FormatException. -
indexOfTopLevel(
int char) → int -
Returns the offset of the next occurrence of
charat the top level (i.e. not inside aquoted-string), or-1if not found before the end of source. Does not advance the cursor. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
peek(
) → int -
Returns the code unit at the cursor, or
-1if at end. -
readQuotedString(
) → String -
Reads a
quoted-string, throwing FormatException if the cursor is not at". -
readToken(
) → String -
Reads a
token, throwing FormatException if notcharis at the cursor. -
readTokenOrQuotedString(
) → String - Like tryReadTokenOrQuotedString but throws if neither is present.
-
skipOws(
) → void -
Skips RFC 9110
OWS = *( SP / HTAB )at the cursor. -
splitTopLevel(
int separator) → Iterable< String> -
Yields the top-level substrings of source (from the cursor to end)
separated by
separator, skipping overquoted-strings and trimming surroundingOWSfrom each yielded element. -
toString(
) → String -
A string representation of this object.
inherited
-
tryConsume(
int char) → bool -
Consumes
charif it is at the cursor. Returns true if consumed. -
tryReadQuotedString(
) → String? -
Reads a
quoted-string(RFC 9110 5.6.4) starting at the cursor and returns its unescaped contents (interiorquoted-pairs decoded). -
tryReadToken(
) → String? -
Reads a
token(RFC 9110 5.6.2) starting at the cursor and advances past it. Returns the token characters, ornullif notcharis at the cursor. -
tryReadTokenOrQuotedString(
) → String? -
Reads either a
quoted-string(preferred when the cursor is at") or atoken. This is the RFC 9110token / quoted-stringalternation used pervasively for parameter values.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited