structured_fields/parser

Values

pub fn parse_dictionary(
  value: String,
) -> Result(List(#(String, types.Element)), errors.ParseError)

Parses a Structured Fields Dictionary header value (RFC 9651 §4.2.2).

A dictionary is an ordered map represented as a comma-separated sequence of key=value pairs (or bare key for a boolean-true shorthand). Keys must follow parameter-key syntax. Returns the entries in the order they appear in the header.

Example:

parse_dictionary("en=\"Foo\", de=\"Bar\"")
// -> Ok([
//   #("en", Item(BareString("Foo"), [])),
//   #("de", Item(BareString("Bar"), [])),
// ])
pub fn parse_item(
  value: String,
) -> Result(
  #(types.BareItem, List(types.Parameter)),
  errors.ParseError,
)

Parses a single Structured Fields Item (RFC 9651 §4.2.3).

An item is a bare item value followed by an optional semicolon-delimited parameter list. Returns the bare value and the parameters as a tuple.

Example:

parse_item("42;q=0.9")
// -> Ok(#(Integer(42), [Parameter("q", Decimal(0.9))]))
pub fn parse_list(
  value: String,
) -> Result(List(types.Element), errors.ParseError)

Parses a Structured Fields List header value (RFC 9651 §4.2.1).

A list is a comma-separated sequence of items and inner lists. Whitespace around commas is ignored. Returns Ok([]) for an empty string.

Example:

parse_list("sugar, tea, rum")
// -> Ok([
//   Item(Token("sugar"), []),
//   Item(Token("tea"), []),
//   Item(Token("rum"), []),
// ])
Search Document