std.url
rfc 3986 parsing, percent-encoding, query strings; parsed parts stay encoded
UrlError
Section titled “UrlError”pub UrlError :: errors { no_scheme, bad_port, bad_escape,}no_scheme: no valid scheme before “:”bad_port: a port that is not a number up to 65535bad_escape: a “%” without two hex digits after it
pub Url :: struct { scheme: []const u8, user: []const u8, host: []const u8, port: ?u16, path: []const u8, query: []const u8, fragment: []const u8, has_authority: bool,}parts are slices of the parsed text; missing ones empty, port null
user: before “@”, password includedhost: name, IPv4, or [IPv6]query: after the “?”, without itfragment: after the “#”, without ithas_authority: whether a “//” followed the scheme
Url.port_or
Section titled “Url.port_or”pub port_or :: fn(self: *Self, fallback: u16) -> u16fallback when there is no port
pub parse :: fn(text: []const u8) -> Url ! UrlErrorabsolute URL (scheme:...); splits and checks, doesn’t decode
pub Keep :: enum { component, path, form,}bytes encode keeps; others become %XX
encoded_len
Section titled “encoded_len”pub encoded_len :: fn(s: []const u8, keep: Keep) -> usizelength encode writes for s
encode
Section titled “encode”pub encode :: fn(out: []u8, s: []const u8, keep: Keep) -> usizeinto out (>= encoded_len); returns length written
encode_in
Section titled “encode_in”pub encode_in :: fn(a: *Arena, s: []const u8, keep: Keep) -> []u8in a
decode
Section titled “decode”pub decode :: fn(out: []u8, s: []const u8, plus_is_space: bool) -> usize ! UrlError%XX decoded into out (>= s.len); returns length; plus_is_space for form queries
decode_in
Section titled “decode_in”pub decode_in :: fn(a: *Arena, s: []const u8) -> []const u8 ! UrlErrorin a; returns s itself when there is no escape
decode_form_in
Section titled “decode_form_in”pub decode_form_in :: fn(a: *Arena, s: []const u8) -> []const u8 ! UrlErrordecode_in for form values: + is a space too
pub Pair :: struct { key: []const u8, value: []const u8,}both still encoded; no = means an empty value
pub Pairs :: struct { rest: []const u8,}query pairs in order; empty ones (a=1&&b=2) skipped
Pairs.next
Section titled “Pairs.next”pub next :: fn(self: *Self) -> ?Pairquery_pairs
Section titled “query_pairs”pub query_pairs :: fn(query: []const u8) -> Pairsquery_get
Section titled “query_get”pub query_get :: fn(query: []const u8, key: []const u8) -> ?[]const u8first pair named key (compared encoded), or null