std.uri
URI references as RFC 3986 defines them, strictly; section numbers below are RFC 3986's. Uri
holds the five parts of a reference — scheme, authority (user information, host, port), path,
query, fragment —; Uri.parse reads them and refuses what the grammar refuses (a space, a
character beyond ASCII, a % without two hex digits, a host in brackets that is not an IPv6
address), show writes them back (§5.3), Uri.resolve resolves a reference against a base
(§5.2), and Uri.normalize normalizes the case, the percent-encoding and the dot segments
(§6.2). Percent.encode and Percent.decode encode a text for a Component and decode it
again; Query holds the pairs of a query in their order.
Examples
import std.io { println };
import std.core { ParseError };
import std.uri { Uri, Query };
fn main(): void throws ParseError {
let base = try Uri.parse("https://example.com/docs/guide/");
let page = base.resolve(try Uri.parse("../api/index.html?lang=en"));
println(page.show());
let q = try Query.parse("a=1&b=two&a=3");
println(q.all("a").length());
}
https://example.com/docs/api/index.html?lang=en
2
Types
% and two hex digits.key=value joined by &, in the order written; a key may appear more than once.Functions
pub fn removeDotSegments(path: string): string
Returns path with its . and .. segments resolved, following the algorithm of §5.2.4.