|
| class | urlparser::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 | urlparser::hostname |
| | A domain name used as a URL's host, e.g. "www.example.com". More...
|
| |
| class | urlparser::ipv4 |
| | An IPv4 address used as a URL's host, e.g. "192.0.2.1". More...
|
| |
| class | urlparser::ipv6 |
| | An IPv6 address used as a URL's host, e.g. "2001:db8::1". More...
|
| |
| class | urlparser::psl |
| |
| class | urlparser::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 | urlparser::url |
| | Represents a URL. More...
|
| |
| class | urlparser::version |
| | Exposes the library version (from the URLPARSER_VERSION_* macros) at runtime, without needing to #include the macros directly. More...
|
| |
|
| 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.
|
| |
| std::string | urlparser::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 | urlparser::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.
|
| |
| std::ostream & | operator<< (std::ostream &os, const urlparser::host &dt) |
| | Output stream operator for the host variant (hostname/ipv4/ipv6).
|
| |
| std::ostream & | operator<< (std::ostream &os, const urlparser::hostname &dt) |
| | Output stream operator for hostname.
|
| |
| std::ostream & | operator<< (std::ostream &os, const urlparser::ipv4 &dt) |
| | Output stream operator for ipv4.
|
| |
| std::ostream & | operator<< (std::ostream &os, const urlparser::ipv6 &dt) |
| | Output stream operator for ipv6.
|
| |
| std::ostream & | operator<< (std::ostream &os, const urlparser::query_params &dt) |
| | Output stream operator for query_params.
|
| |
| std::ostream & | operator<< (std::ostream &os, const urlparser::url &dt) |
| | Output stream operator for url.
|
| |
Types for parsing URLs and classifying/handling their host part.
RFC 3986 defines a URL's host grammar as:
host = IP-literal / IPv4address / reg-name
i.e. a host is either an IP address or a domain name - never both, never something in between. This library's types mirror that split directly:
hostname is a domain name ("www.example.com"): subdomain, domain, and suffix, via a lazily-computed Public Suffix List lookup.
ipv4 / ipv6 are IP addresses: no PSL, no subdomain/domain/suffix (those concepts don't apply to "192.0.2.1"), but arithmetic (++, –, +=, -=), comparisons, and integer conversions instead.
host = std::variant<hostname, ipv4, ipv6> is whichever of the three a given URL's host actually is - what url::host() returns, and what parse_host()/parse_host_from_url() build directly.
All are plain value types: no PIMPL, no heap allocation for the object itself beyond what a std::string/std::variant already needs. The only deferred work is the PSL-dependent domain/suffix split (hostname) and, for url, building/classifying its host at all - both are computed once, on first access, and cached in mutable members.
Example usage:
std::cout << "protocol: " << u.protocol() << "\n";
if (auto* h = std::get_if<urlparser::hostname>(&u.host())) {
std::cout << "domain: " << h->domain() << ", suffix: " << h->suffix() << "\n";
}
if (auto* v4 = std::get_if<urlparser::ipv4>(&ipurl.host())) {
std::cout << "IP as int: " << v4->to_uint32() << "\n";
std::cout << "next IP: " << (*v4 + 1).str() << "\n";
}
Represents a URL.
Definition urlparser.h:673