#include <icy/http/url.h>An RFC 3986 based URL parser. Constructors and assignment operators will throw a SyntaxException if the URL is invalid.
| Return | Name | Description |
|---|---|---|
URL | Creates an empty URL. | |
URL | Parses the URL from a null-terminated string. | |
URL | Parses the URL from a std::string. | |
URL | Constructs a URL from scheme and authority components. | |
URL | Constructs a URL from scheme, authority, and path+query+fragment. | |
URL | Constructs a URL from individual components. | |
URL | Defaulted constructor. | |
URL & | operator= | Assigns a URL from another URL instance. |
URL & | operator= | Assigns a URL from a null-terminated string. |
URL & | operator= | Assigns a URL from a std::string. |
bool | parse | Parses and assigns a URL from the given string view, resetting all components first. |
std::string | scheme const | Returns the URL scheme (e.g. "http", "https", "ws"). Always lowercase. |
std::string | userInfo const | Returns the user info component (e.g. "user:pass" from "http://user:pass@host/"). Returns an empty string if not present. |
std::string | host const | Returns the host component (e.g. "example.com"). Returns an empty string if not present. |
uint16_t | port const | Returns the port number. If no explicit port was in the URL, returns the default port for the scheme (80 for http, 443 for https), or 0 if the scheme is unknown. |
std::string | authority const | Returns the authority component (userinfo@host:port). Only includes components that are present. |
std::string | path const | Returns the path component (e.g. "/index.html"). Returns an empty string if not present. |
std::string | pathEtc const | Returns the path, query and fragment combined (e.g. "/path?q=1#frag"). |
std::string | query const | Returns the query string without the leading '?' (e.g. "key=value&foo=bar"). Returns an empty string if not present. |
std::string | fragment const | Returns the fragment identifier without the leading '#'. Returns an empty string if not present. |
bool | hasSchema const | Returns true if the URL has a scheme component. |
bool | hasUserInfo const | Returns true if the URL has a user info component. |
bool | hasHost const | Returns true if the URL has a host component. |
bool | hasPort const | Returns true if an explicit port was specified in the URL. |
bool | hasPath const | Returns true if the URL has a path component. |
bool | hasQuery const | Returns true if the URL has a query component. |
bool | hasFragment const | Returns true if the URL has a fragment component. |
bool | valid const | Returns true if the URL is non-empty and was successfully parsed. |
std::string | str const | Returns the original URL string as parsed. |
URL()Creates an empty URL.
URL(const char * url)Parses the URL from a null-terminated string.
url Null-terminated URL string to parse.URL(const std::string & url)Parses the URL from a std::string.
url URL string to parse.URL(const std::string & scheme, const std::string & authority)Constructs a URL from scheme and authority components.
scheme URL scheme (e.g. "http", "https").
authority Host and optional port (e.g. "example.com:8080").
URL(const std::string & scheme, const std::string & authority, const std::string & pathEtc)Constructs a URL from scheme, authority, and path+query+fragment.
scheme URL scheme (e.g. "http").
authority Host and optional port.
pathEtc Path, query and fragment combined (e.g. "/path?q=1#frag").
URL(const std::string & scheme, const std::string & authority, const std::string & path, const std::string & query, const std::string & fragment)Constructs a URL from individual components.
scheme URL scheme (e.g. "http").
authority Host and optional port.
path URL path (e.g. "/index.html").
query Query string without leading '?' (e.g. "key=value").
fragment Fragment identifier without leading '#'.
URL(const URL &) = defaultDefaulted constructor.
URL & operator=(const URL & uri)Assigns a URL from another URL instance.
uri Source URL to copy from.Reference to this URL.
URL & operator=(const char * uri)Assigns a URL from a null-terminated string.
uri Null-terminated URL string to parse.Reference to this URL.
URL & operator=(const std::string & uri)Assigns a URL from a std::string.
uri URL string to parse.Reference to this URL.
bool parse(std::string_view url, bool whiny)Parses and assigns a URL from the given string view, resetting all components first.
url URL string to parse.
whiny If true, throws std::runtime_error on an invalid URL; otherwise returns false.
true if the URL was parsed successfully; false if invalid and whiny is false.
const
std::string scheme() constReturns the URL scheme (e.g. "http", "https", "ws"). Always lowercase.
const
std::string userInfo() constReturns the user info component (e.g. "user:pass" from "http://user:pass@host/"). Returns an empty string if not present.
const
std::string host() constReturns the host component (e.g. "example.com"). Returns an empty string if not present.
const
uint16_t port() constReturns the port number. If no explicit port was in the URL, returns the default port for the scheme (80 for http, 443 for https), or 0 if the scheme is unknown.
const
std::string authority() constReturns the authority component (userinfo@host:port). Only includes components that are present.
const
std::string path() constReturns the path component (e.g. "/index.html"). Returns an empty string if not present.
const
std::string pathEtc() constReturns the path, query and fragment combined (e.g. "/path?q=1#frag").
const
std::string query() constReturns the query string without the leading '?' (e.g. "key=value&foo=bar"). Returns an empty string if not present.
const
std::string fragment() constReturns the fragment identifier without the leading '#'. Returns an empty string if not present.
const
bool hasSchema() constReturns true if the URL has a scheme component.
const
bool hasUserInfo() constReturns true if the URL has a user info component.
const
bool hasHost() constReturns true if the URL has a host component.
const
bool hasPort() constReturns true if an explicit port was specified in the URL.
const
bool hasPath() constReturns true if the URL has a path component.
const
bool hasQuery() constReturns true if the URL has a query component.
const
bool hasFragment() constReturns true if the URL has a fragment component.
const
bool valid() constReturns true if the URL is non-empty and was successfully parsed.
const
std::string str() constReturns the original URL string as parsed.
| Return | Name | Description |
|---|---|---|
std::string | encode static | Percent-encodes a string per RFC 3986, preserving unreserved characters (A-Z, a-z, 0-9, '-', '_', '.', '~'). Equivalent to JavaScript's encodeURIComponent(). |
std::string | decode static | Decodes a percent-encoded string per RFC 3986. Equivalent to JavaScript's decodeURIComponent(). |
static
static std::string encode(std::string_view str)Percent-encodes a string per RFC 3986, preserving unreserved characters (A-Z, a-z, 0-9, '-', '_', '.', '~'). Equivalent to JavaScript's encodeURIComponent().
str Input string to encode.Percent-encoded string.
static
static std::string decode(std::string_view str)Decodes a percent-encoded string per RFC 3986. Equivalent to JavaScript's decodeURIComponent().
str Percent-encoded input string.Decoded string.
| Return | Name | Description |
|---|---|---|
std::string | _buf | |
std::string | _scheme | |
std::string | _userInfo | |
std::string | _host | |
uint16_t | _port | |
std::string | _path | |
std::string | _query | |
std::string | _fragment | |
bool | _hasPort |
std::string _bufstd::string _schemestd::string _userInfostd::string _hostuint16_t _portstd::string _pathstd::string _querystd::string _fragmentbool _hasPort