Namespaces | |
| namespace | detail |
| The library's Public Suffix List matcher. | |
| namespace | idna |
| IDNA (Internationalized Domain Names in Applications) support. | |
| namespace | percent_codec |
| Percent-encoding (RFC 3986 "quote") / percent-decoding ("unquote"). | |
Classes | |
| class | host |
| hostname, ipv4, or ipv6: whatever a URL's host actually is (RFC 3986's host grammar), wrapped in a uniform API that matches hostname/ipv4/ipv6/url themselves: a constructor that just parses, plus from_url() and str(). More... | |
| class | hostname |
| A domain name used as a URL's host, e.g. "www.example.com". More... | |
| class | ipv4 |
| An IPv4 address used as a URL's host, e.g. "192.0.2.1". More... | |
| class | ipv6 |
| An IPv6 address used as a URL's host, e.g. "2001:db8::1". More... | |
| class | psl |
| class | scp_url |
| Parses an SSH "scp-like" address - user@host:path (what scp, rsync, sshfs, and git all accept, e.g. "git@github.com:user/repo.git") - by normalizing it to a standard ssh://user@host/path URI and handing that to url. Not URI syntax per RFC 3986 (that colon is a path separator, not a port), so plain url() either misparses it or throws. More... | |
| class | url |
| Represents a URL. More... | |
| class | version |
| Exposes the library version (from the URLPARSER_VERSION_* macros) at runtime, without needing to #include the macros directly. More... | |
Typedefs | |
| using | git_url = scp_url |
| Alias for scp_url. Most callers reaching for this class are parsing a git remote specifically (its most common real-world use, e.g. "git@github.com:user/repo.git") - scp_url itself is named for the underlying address syntax (shared with scp/rsync/sshfs too), not tied to git, so this alias exists purely so the name at a git-focused call site can say what it's for. | |
| using | query_params = std::vector<std::string> |
| A vector of strings representing query parameters in a URL. | |
Functions | |
| URLPARSER_API std::string_view | bare_host (std::string_view host_text) noexcept |
| A host without the brackets of an IPv6 literal: "::1" for "[::1]". Any other text comes back unchanged. | |
| URLPARSER_API std::string | build_search_params (const std::vector< std::pair< std::string, std::string > > &pairs) |
| Build an application/x-www-form-urlencoded query string from ordered key/value pairs - the inverse of url::get_search_params() (url::search_params). Matches WHATWG's own query-serialization rules, verified against ada_url.replace_search_params(): a space becomes '+' (not "%20"), the safe/unescaped set is ASCII alphanumeric plus * - . _ only - narrower than percent_codec::unreserved_set(), which also leaves '~' unescaped; a query string does not. A repeated key (multiple pairs with the same first element) writes multiple "key=value" entries, in the order given - this never deduplicates or reorders. | |
| URLPARSER_API std::string | build_search_params (const url::search_params ¶ms) |
| Convenience overload: build from a url::search_params map (url::get_search_params()'s return type) instead of an ordered pair list. Each key's values are written out in their own vector order, but the keys themselves follow std::unordered_map's iteration order - unspecified, and not guaranteed to match the original query string's key order. Use the vector<pair> overload above when order matters. | |
| std::string | normalize (std::string_view input) |
| Convenience wrapper: url(input).normalized(). Prefer calling .normalized() directly on a url you already have parsed - this just parses one and immediately normalizes it, so it's no faster than doing that yourself, only more convenient for a one-off string-in/string-out call. | |
| URLPARSER_API std::string | resolve (std::string_view base, std::string_view ref) |
| Resolve a URL reference (possibly relative) against a base URL, per RFC 3986 §5 ("Reference Resolution"): the same algorithm behind new URL(ref, base) in JavaScript / ada_url.join_url(base, ref) / urllib.parse.urljoin(base, ref). | |
Variables | |
| constexpr bool | DEFAULT_IGNORE_WWW = false |
| using urlparser::git_url = scp_url |
Alias for scp_url. Most callers reaching for this class are parsing a git remote specifically (its most common real-world use, e.g. "git@github.com:user/repo.git") - scp_url itself is named for the underlying address syntax (shared with scp/rsync/sshfs too), not tied to git, so this alias exists purely so the name at a git-focused call site can say what it's for.
| using urlparser::query_params = std::vector<std::string> |
A vector of strings representing query parameters in a URL.
|
noexcept |
A host without the brackets of an IPv6 literal: "::1" for "[::1]". Any other text comes back unchanged.
For a host that is held as text: a connection's target, a Host: value, a no_proxy entry; for the host of a url, bare_host(u.host_text()). host_text() is the raw text and keeps the brackets. The brackets belong to the URL syntax (a Host: header and a rebuilt URL need them), not to the address: a resolver, a TLS server name and a SOCKS5 request want it bare. Only a matching pair around the whole text is removed; the text is not validated, so "[example.com]" gives "example.com". Returns a view into host_text.
| URLPARSER_API std::string urlparser::build_search_params | ( | const std::vector< std::pair< std::string, std::string > > & | pairs | ) |
Build an application/x-www-form-urlencoded query string from ordered key/value pairs - the inverse of url::get_search_params() (url::search_params). Matches WHATWG's own query-serialization rules, verified against ada_url.replace_search_params(): a space becomes '+' (not "%20"), the safe/unescaped set is ASCII alphanumeric plus * - . _ only - narrower than percent_codec::unreserved_set(), which also leaves '~' unescaped; a query string does not. A repeated key (multiple pairs with the same first element) writes multiple "key=value" entries, in the order given - this never deduplicates or reorders.
| pairs | Key/value pairs, in the order they should appear. |
| URLPARSER_API std::string urlparser::build_search_params | ( | const url::search_params & | params | ) |
Convenience overload: build from a url::search_params map (url::get_search_params()'s return type) instead of an ordered pair list. Each key's values are written out in their own vector order, but the keys themselves follow std::unordered_map's iteration order - unspecified, and not guaranteed to match the original query string's key order. Use the vector<pair> overload above when order matters.
|
inline |
Convenience wrapper: url(input).normalized(). Prefer calling .normalized() directly on a url you already have parsed - this just parses one and immediately normalizes it, so it's no faster than doing that yourself, only more convenient for a one-off string-in/string-out call.
| URLPARSER_API std::string urlparser::resolve | ( | std::string_view | base, |
| std::string_view | ref ) |
Resolve a URL reference (possibly relative) against a base URL, per RFC 3986 §5 ("Reference Resolution"): the same algorithm behind new URL(ref, base) in JavaScript / ada_url.join_url(base, ref) / urllib.parse.urljoin(base, ref).
liburlparser had no equivalent at all before this: url::abspath() only resolves '.'/'..' segments within a single already-parsed URL's own path - it has no notion of a second, separate reference to merge in. Concretely, before this a caller who had "https://example.com/a/b/c" and wanted to follow a link to "../d" found in that page had nothing in liburlparser to reach for.
| base | An absolute URL (must have a scheme and, for the schemes this covers, an authority - e.g. "https://example.com/a/b/c"). |
| ref | A URL reference, absolute or relative (e.g. "../d", "/x", "?q=1", "#frag", or another absolute URL). |
Verified against ada_url.join_url() (WHATWG-compliant) across a broad randomized case set; one known, narrow divergence remains: when base has no path at all (e.g. "https://example.com", not even a bare "/"), this returns that path as empty, where WHATWG defaults it to "/" - a liburlparser-wide URL-parsing characteristic (url::path() itself already returns "" for such input), not something specific to resolve() itself, so it's left as-is here rather than special-cased.
|
constexpr |