|
Upa URL C++ library
A WHATWG URL Standard implementation
|
URL class. More...
#include <upa/url.h>
Public Types | |
| enum | PartType { SCHEME = 0 , SCHEME_SEP , USERNAME , PASSWORD , HOST_START , HOST , PORT , PATH_PREFIX , PATH , QUERY , FRAGMENT , PART_COUNT } |
Public Member Functions | |
| url ()=default | |
| Default constructor. | |
| url (const url &other)=default | |
| Copy constructor. | |
| url (url &&other) noexcept | |
| Move constructor. | |
| url & | operator= (const url &other)=default |
| Copy assignment. | |
| url & | operator= (url &&other) noexcept |
| Move assignment. | |
| url & | safe_assign (url &&other) |
| Safe move assignment. | |
| template<class T, enable_if_str_arg_t< T > = 0> | |
| url (const T &str_url, const url *pbase=nullptr) | |
| Parsing constructor. | |
| template<class T, enable_if_str_arg_t< T > = 0> | |
| url (const T &str_url, const url &base) | |
| Parsing constructor. | |
| template<class T, class TB, enable_if_str_arg_t< T > = 0, enable_if_str_arg_t< TB > = 0> | |
| url (const T &str_url, const TB &str_base) | |
| Parsing constructor. | |
| ~url ()=default | |
| destructor | |
| void | clear () |
| Clears URL. | |
| void | swap (url &other) noexcept |
| Swaps the contents of two URLs. | |
| template<class T, enable_if_str_arg_t< T > = 0> | |
| validation_errc | parse (const T &str_url, const url *base=nullptr) |
| Parses given URL string against base URL. | |
| template<class T, enable_if_str_arg_t< T > = 0> | |
| validation_errc | parse (const T &str_url, const url &base) |
| Parses given URL string against base URL. | |
| template<class T, class TB, enable_if_str_arg_t< T > = 0, enable_if_str_arg_t< TB > = 0> | |
| validation_errc | parse (const T &str_url, const TB &str_base) |
| Parses given URL string against base URL. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | href (const StrT &str) |
| The href setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_href (const StrT &str) |
| Equivalent to href(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | protocol (const StrT &str) |
| The protocol setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_protocol (const StrT &str) |
| Equivalent to protocol(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | username (const StrT &str) |
| The username setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_username (const StrT &str) |
| Equivalent to username(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | password (const StrT &str) |
| The password setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_password (const StrT &str) |
| Equivalent to password(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | host (const StrT &str) |
| The host setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_host (const StrT &str) |
| Equivalent to host(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | hostname (const StrT &str) |
| The hostname setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_hostname (const StrT &str) |
| Equivalent to hostname(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | port (const StrT &str) |
| The port setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_port (const StrT &str) |
| Equivalent to port(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | pathname (const StrT &str) |
| The pathname setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_pathname (const StrT &str) |
| Equivalent to pathname(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | search (const StrT &str) |
| The search setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_search (const StrT &str) |
| Equivalent to search(const StrT& str). | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | hash (const StrT &str) |
| The hash setter. | |
| template<class StrT, enable_if_str_arg_t< StrT > = 0> | |
| bool | set_hash (const StrT &str) |
| Equivalent to hash(const StrT& str). | |
| std::string_view | href () const |
| The href getter. | |
| std::string_view | get_href () const |
| Equivalent to href() const . | |
| std::string | origin () const |
| The origin getter. | |
| std::string_view | protocol () const |
| The protocol getter. | |
| std::string_view | get_protocol () const |
| Equivalent to protocol() const . | |
| std::string_view | username () const |
| The username getter. | |
| std::string_view | get_username () const |
| Equivalent to username() const . | |
| std::string_view | password () const |
| The password getter. | |
| std::string_view | get_password () const |
| Equivalent to password() const . | |
| std::string_view | host () const |
| The host getter. | |
| std::string_view | get_host () const |
| Equivalent to host() const . | |
| std::string_view | hostname () const |
| The hostname getter. | |
| std::string_view | get_hostname () const |
| Equivalent to hostname() const . | |
| HostType | host_type () const noexcept |
| The host_type getter. | |
| std::string_view | port () const |
| The port getter. | |
| std::string_view | get_port () const |
| Equivalent to port() const . | |
| int | port_int () const |
| int | real_port_int () const |
| std::string_view | path () const |
| The path getter. | |
| std::string_view | get_path () const |
| Equivalent to path() const . | |
| std::string_view | pathname () const |
| The pathname getter. | |
| std::string_view | get_pathname () const |
| Equivalent to pathname() const . | |
| std::string_view | search () const |
| The search getter. | |
| std::string_view | get_search () const |
| Equivalent to search() const . | |
| std::string_view | hash () const |
| The hash getter. | |
| std::string_view | get_hash () const |
| Equivalent to hash() const . | |
| url_search_params & | search_params () & |
| The searchParams getter. | |
| url_search_params | search_params () && |
| The searchParams getter for rvalue url. | |
| std::string_view | serialize (bool exclude_fragment=false) const |
| URL serializer. | |
| bool | empty () const noexcept |
| Checks whether the URL is empty. | |
| bool | is_valid () const noexcept |
| Returns whether the URL is valid. | |
| UPA_API std::pair< std::size_t, std::size_t > | get_part_pos (PartType t, bool with_sep=false) const |
| Gets the start and end position of the specified URL part. | |
| std::string_view | get_part_view (PartType t) const |
| Gets URL's part (URL record member) as string. | |
| bool | is_empty (PartType t) const |
| Checks whether the URL's part (URL record member) is empty or null. | |
| bool | is_null (PartType t) const noexcept |
| Checks whether the URL's part (URL record member) is null. | |
| bool | is_special_scheme () const noexcept |
| bool | is_file_scheme () const noexcept |
| bool | is_http_scheme () const noexcept |
| bool | has_credentials () const |
| bool | has_opaque_path () const noexcept |
| std::string | to_string () const |
Static Public Member Functions | |
| template<class T, enable_if_str_arg_t< T > = 0> | |
| static bool | can_parse (const T &str_url, const url *pbase=nullptr) |
| Checks if a given URL string can be successfully parsed. | |
| template<class T, enable_if_str_arg_t< T > = 0> | |
| static bool | can_parse (const T &str_url, const url &base) |
| Checks if a given URL string can be successfully parsed. | |
| template<class T, class TB, enable_if_str_arg_t< T > = 0, enable_if_str_arg_t< TB > = 0> | |
| static bool | can_parse (const T &str_url, const TB &str_base) |
| Checks if a given URL string can be successfully parsed. | |
Friends | |
| struct | std::hash< url > |
| class | detail::url_serializer |
| class | detail::url_setter |
| class | detail::url_parser |
| class | url_search_params |
| bool | operator== (const url &lhs, const url &rhs) |
| Lexicographically compares two URL's. | |
| std::ostream & | operator<< (std::ostream &os, const url &url) |
| Performs stream output on URL. | |
URL class.
Follows specification in https://url.spec.whatwg.org/#url-class
| enum upa::url::PartType |
Enumeration to identify URL's parts (URL record members) defined here: https://url.spec.whatwg.org/#url-representation
| Enumerator | |
|---|---|
| SCHEME | |
| SCHEME_SEP | |
| USERNAME | |
| PASSWORD | |
| HOST_START | |
| HOST | |
| PORT | |
| PATH_PREFIX | |
| PATH | |
| QUERY | |
| FRAGMENT | |
| PART_COUNT | |
|
default |
Default constructor.
Constructs empty URL.
|
default |
Copy constructor.
| [in] | other | URL to copy from |
|
inlinenoexcept |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
default |
destructor
|
inlinestaticnodiscard |
Checks if a given URL string can be successfully parsed.
First try to parse str_base URL string, if it succeed, then try to parse str_url against base URL. More info: https://url.spec.whatwg.org/#dom-url-canparse
| [in] | str_url | URL string to parse |
| [in] | str_base | base URL string |
|
inlinestaticnodiscard |
Checks if a given URL string can be successfully parsed.
Try to parse against base URL. More info: https://url.spec.whatwg.org/#dom-url-canparse
| [in] | str_url | URL string to parse |
| [in] | base | base URL |
|
inlinestaticnodiscard |
Checks if a given URL string can be successfully parsed.
If pbase is not nullptr, then try to parse against *pbase URL. More info: https://url.spec.whatwg.org/#dom-url-canparse
| [in] | str_url | URL string to parse |
| [in] | pbase | pointer to base URL, may be nullptr |
|
inlinenodiscardnoexcept |
|
inlinenodiscard |
Equivalent to hash() const .
|
inlinenodiscard |
Equivalent to host() const .
|
inlinenodiscard |
Equivalent to hostname() const .
|
inlinenodiscard |
Equivalent to href() const .
|
nodiscard |
Gets the start and end position of the specified URL part.
Returns the start and end position of the part (as defined in https://url.spec.whatwg.org/#url-representation) in the string returned by the get_href(), href() or to_string() functions.
If with_sep is true, then:
For other t values, the with_sep has no effect.
| [in] | t | URL's part |
| [in] | with_sep |
|
inlinenodiscard |
Gets URL's part (URL record member) as string.
Function to get ASCII string of any URL's part (URL record member) defined here: https://url.spec.whatwg.org/#url-representation
| [in] | t | URL's part |
|
inlinenodiscard |
Equivalent to password() const .
|
inlinenodiscard |
Equivalent to path() const .
|
inlinenodiscard |
Equivalent to pathname() const .
|
inlinenodiscard |
Equivalent to port() const .
|
inlinenodiscard |
Equivalent to protocol() const .
|
inlinenodiscard |
Equivalent to search() const .
|
inlinenodiscard |
Equivalent to username() const .
|
inlinenodiscard |
|
inlinenodiscardnoexcept |
see: https://url.spec.whatwg.org/#url-opaque-path
|
inlinenodiscard |
The hash getter.
More info: https://url.spec.whatwg.org/#dom-url-hash
|
inline |
The hash setter.
Parses given string and on succes sets the URL's fragment. More info: https://url.spec.whatwg.org/#dom-url-hash
| [in] | str | string to parse |
|
inlinenodiscard |
The host getter.
More info: https://url.spec.whatwg.org/#dom-url-host
|
inline |
The host setter.
Parses given string and on succes sets the URL's host and port. More info: https://url.spec.whatwg.org/#dom-url-host
| [in] | str | string to parse |
|
inlinenodiscardnoexcept |
|
inlinenodiscard |
The hostname getter.
More info: https://url.spec.whatwg.org/#dom-url-hostname
|
inline |
The hostname setter.
Parses given string and on succes sets the URL's host. More info: https://url.spec.whatwg.org/#dom-url-hostname
| [in] | str | string to parse |
|
inlinenodiscard |
|
inline |
|
inlinenodiscard |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Checks whether the URL's part (URL record member) is null.
Only the following URL record members can be null:
| [in] | t | URL's part |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Copy assignment.
| [in] | other | URL to copy from |
|
inlinenodiscard |
The origin getter.
More info: https://url.spec.whatwg.org/#dom-url-origin
Note: For file URLs, this implementation returns a serialized opaque origin (null).
|
inline |
Parses given URL string against base URL.
| [in] | str_url | URL string to parse |
| [in] | str_base | base URL string |
|
inline |
Parses given URL string against base URL.
| [in] | str_url | URL string to parse |
| [in] | base | base URL |
|
inline |
Parses given URL string against base URL.
| [in] | str_url | URL string to parse |
| [in] | base | pointer to base URL, may be nullptr |
|
inlinenodiscard |
|
inline |
The password setter.
Parses given string and on succes sets the URL's password. More info: https://url.spec.whatwg.org/#dom-url-password
| [in] | str | string to parse |
|
inlinenodiscard |
|
inlinenodiscard |
The pathname getter.
More info: https://url.spec.whatwg.org/#dom-url-pathname
|
inline |
The pathname setter.
Parses given string and on succes sets the URL's path. More info: https://url.spec.whatwg.org/#dom-url-pathname
| [in] | str | string to parse |
|
inlinenodiscard |
The port getter.
More info: https://url.spec.whatwg.org/#dom-url-port
|
inline |
The port setter.
Parses given string and on succes sets the URL's port. More info: https://url.spec.whatwg.org/#dom-url-port
| [in] | str | string to parse |
|
inlinenodiscard |
|
inlinenodiscard |
The protocol getter.
More info: https://url.spec.whatwg.org/#dom-url-protocol
|
inline |
The protocol setter.
Parses given string and on succes sets the URL's protocol. More info: https://url.spec.whatwg.org/#dom-url-protocol
| [in] | str | string to parse |
|
inlinenodiscard |
Safe move assignment.
Replaces the contents with those of other using move semantics. Preserves original url_search_params object.
| [in,out] | other | URL to move to this object |
|
inlinenodiscard |
The search getter.
More info: https://url.spec.whatwg.org/#dom-url-search
|
inline |
The search setter.
Parses given string and on succes sets the URL's query. More info: https://url.spec.whatwg.org/#dom-url-search
| [in] | str | string to parse |
|
inline |
The searchParams getter.
More info: https://url.spec.whatwg.org/#dom-url-searchparams
Returned reference is valid thru lifetime of url, or until url's move assignment operation (except safe_assign, which preserves reference validity).
|
inlinenodiscard |
The searchParams getter for rvalue url.
|
inlinenodiscard |
URL serializer.
Returns serialized URL in a std::string_view as defined here: https://url.spec.whatwg.org/#concept-url-serializer
| [in] | exclude_fragment | exclude fragment when serializing |
|
inline |
Equivalent to hash(const StrT& str).
|
inline |
Equivalent to host(const StrT& str).
|
inline |
Equivalent to hostname(const StrT& str).
|
inline |
Equivalent to href(const StrT& str).
|
inline |
Equivalent to password(const StrT& str).
|
inline |
Equivalent to pathname(const StrT& str).
|
inline |
Equivalent to port(const StrT& str).
|
inline |
Equivalent to protocol(const StrT& str).
|
inline |
Equivalent to search(const StrT& str).
|
inline |
Equivalent to username(const StrT& str).
|
inlinenoexcept |
|
inlinenodiscard |
|
inlinenodiscard |
|
inline |
The username setter.
Parses given string and on succes sets the URL's username. More info: https://url.spec.whatwg.org/#dom-url-username
| [in] | str | string to parse |
|
friend |
Performs stream output on URL.
Outputs URL serialized to ASCII string