Upa URL C++ library
A WHATWG URL Standard implementation
Loading...
Searching...
No Matches
upa::url Class Reference

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.
urloperator= (const url &other)=default
 Copy assignment.
urloperator= (url &&other) noexcept
 Move assignment.
urlsafe_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_paramssearch_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.

Detailed Description

URL class.

Follows specification in https://url.spec.whatwg.org/#url-class

Definition at line 84 of file url.h.

Member Enumeration Documentation

◆ 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 

Definition at line 88 of file url.h.

Constructor & Destructor Documentation

◆ url() [1/6]

upa::url::url ( )
default

Default constructor.

Constructs empty URL.

◆ url() [2/6]

upa::url::url ( const url & other)
default

Copy constructor.

Parameters
[in]otherURL to copy from

◆ url() [3/6]

upa::url::url ( url && other)
inlinenoexcept

Move constructor.

Constructs the URL with the contents of other using move semantics.

Parameters
[in,out]otherURL to move to this object

Definition at line 1118 of file url.h.

◆ url() [4/6]

template<class T, enable_if_str_arg_t< T > = 0>
upa::url::url ( const T & str_url,
const url * pbase = nullptr )
inlineexplicit

Parsing constructor.

Throws url_error exception on parse error.

Parameters
[in]str_urlURL string to parse
[in]pbasepointer to base URL, may be nullptr

Definition at line 150 of file url.h.

◆ url() [5/6]

template<class T, enable_if_str_arg_t< T > = 0>
upa::url::url ( const T & str_url,
const url & base )
inlineexplicit

Parsing constructor.

Throws url_error exception on parse error.

Parameters
[in]str_urlURL string to parse
[in]basebase URL

Definition at line 161 of file url.h.

◆ url() [6/6]

template<class T, class TB, enable_if_str_arg_t< T > = 0, enable_if_str_arg_t< TB > = 0>
upa::url::url ( const T & str_url,
const TB & str_base )
inlineexplicit

Parsing constructor.

Throws url_error exception on parse error.

Parameters
[in]str_urlURL string to parse
[in]str_basebase URL string

Definition at line 172 of file url.h.

◆ ~url()

upa::url::~url ( )
default

destructor

Member Function Documentation

◆ can_parse() [1/3]

template<class T, class TB, enable_if_str_arg_t< T > = 0, enable_if_str_arg_t< TB > = 0>
bool upa::url::can_parse ( const T & str_url,
const TB & str_base )
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

Parameters
[in]str_urlURL string to parse
[in]str_basebase URL string
Returns
true if given str_url can be parsed against str_base URL string

Definition at line 265 of file url.h.

◆ can_parse() [2/3]

template<class T, enable_if_str_arg_t< T > = 0>
bool upa::url::can_parse ( const T & str_url,
const url & base )
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

Parameters
[in]str_urlURL string to parse
[in]basebase URL
Returns
true if given str_url can be parsed against base URL

Definition at line 251 of file url.h.

◆ can_parse() [3/3]

template<class T, enable_if_str_arg_t< T > = 0>
bool upa::url::can_parse ( const T & str_url,
const url * pbase = nullptr )
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

Parameters
[in]str_urlURL string to parse
[in]pbasepointer to base URL, may be nullptr
Returns
true if given str_url can be parsed against *pbase

Definition at line 237 of file url.h.

◆ clear()

void upa::url::clear ( )
inline

Clears URL.

Makes URL empty.

Definition at line 1419 of file url.h.

◆ empty()

bool upa::url::empty ( ) const
inlinenodiscardnoexcept

Checks whether the URL is empty.

Returns
true if URL is empty, false otherwise

Definition at line 1315 of file url.h.

◆ get_hash()

std::string_view upa::url::get_hash ( ) const
inlinenodiscard

Equivalent to hash() const .

Definition at line 525 of file url.h.

◆ get_host()

std::string_view upa::url::get_host ( ) const
inlinenodiscard

Equivalent to host() const .

Definition at line 459 of file url.h.

◆ get_hostname()

std::string_view upa::url::get_hostname ( ) const
inlinenodiscard

Equivalent to hostname() const .

Definition at line 468 of file url.h.

◆ get_href()

std::string_view upa::url::get_href ( ) const
inlinenodiscard

Equivalent to href() const .

Definition at line 413 of file url.h.

◆ get_part_pos()

UPA_API std::pair< std::size_t, std::size_t > upa::url::get_part_pos ( PartType t,
bool with_sep = false ) 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.

  • get_part_pos(upa::url::SCHEME) - get a URL's scheme position
  • get_part_pos(upa::url::USERNAME) - get a URL's username position
  • get_part_pos(upa::url::PASSWORD) - get a URL's password position
  • get_part_pos(upa::url::HOST) - get a URL's host position
  • get_part_pos(upa::url::PORT) - get a URL's port position
  • get_part_pos(upa::url::PATH) - get a URL's path position
  • get_part_pos(upa::url::QUERY) - get a URL's query position
  • get_part_pos(upa::url::FRAGMENT) - get a URL's fragment position

If with_sep is true, then:

  • get_part_pos(upa::url::SCHEME, true) - gets position of URL's scheme along with : (corresponds to the return value of protocol())
  • get_part_pos(upa::url::QUERY, true) - gets position of URL's query along with ? (corresponds to the return value of search())
  • get_part_pos(upa::url::FRAGMENT, true) - gets position of URL's fragment along with # (corresponds to the return value of hash())

For other t values, the with_sep has no effect.

Parameters
[in]tURL's part
[in]with_sep
Returns
the start and end position of the specified URL part

◆ get_part_view()

std::string_view upa::url::get_part_view ( PartType t) const
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

  • get_part_view(upa::url::SCHEME) - get a URL's scheme string
  • get_part_view(upa::url::USERNAME) - get a URL's username string
  • get_part_view(upa::url::PASSWORD) - get a URL's password string
  • get_part_view(upa::url::HOST) - get a URL's host serialized to string
  • get_part_view(upa::url::PORT) - get a URL's port serialized to string
  • get_part_view(upa::url::PATH) - get a URL's path serialized to string
  • get_part_view(upa::url::QUERY) - get a URL's query string
  • get_part_view(upa::url::FRAGMENT) - get a URL's fragment string
Parameters
[in]tURL's part
Returns
URL's part string; it is empty if part is empty or null

Definition at line 1323 of file url.h.

◆ get_password()

std::string_view upa::url::get_password ( ) const
inlinenodiscard

Equivalent to password() const .

Definition at line 450 of file url.h.

◆ get_path()

std::string_view upa::url::get_path ( ) const
inlinenodiscard

Equivalent to path() const .

Definition at line 498 of file url.h.

◆ get_pathname()

std::string_view upa::url::get_pathname ( ) const
inlinenodiscard

Equivalent to pathname() const .

Definition at line 507 of file url.h.

◆ get_port()

std::string_view upa::url::get_port ( ) const
inlinenodiscard

Equivalent to port() const .

Definition at line 482 of file url.h.

◆ get_protocol()

std::string_view upa::url::get_protocol ( ) const
inlinenodiscard

Equivalent to protocol() const .

Definition at line 432 of file url.h.

◆ get_search()

std::string_view upa::url::get_search ( ) const
inlinenodiscard

Equivalent to search() const .

Definition at line 516 of file url.h.

◆ get_username()

std::string_view upa::url::get_username ( ) const
inlinenodiscard

Equivalent to username() const .

Definition at line 441 of file url.h.

◆ has_credentials()

bool upa::url::has_credentials ( ) const
inlinenodiscard
Returns
true if URL includes credentials (username, password), false otherwise

Definition at line 1357 of file url.h.

◆ has_opaque_path()

bool upa::url::has_opaque_path ( ) const
inlinenodiscardnoexcept

see: https://url.spec.whatwg.org/#url-opaque-path

Returns
true if URL's path is a URL path segment, false otherwise

Definition at line 1391 of file url.h.

◆ hash() [1/2]

std::string_view upa::url::hash ( ) const
inlinenodiscard

The hash getter.

More info: https://url.spec.whatwg.org/#dom-url-hash

Returns
empty string or U+0023 (#), followed by URL’s fragment

Definition at line 1275 of file url.h.

◆ hash() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::hash ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - on failure (URL's fragment unchanged)

Definition at line 1626 of file url.h.

◆ host() [1/2]

std::string_view upa::url::host ( ) const
inlinenodiscard

The host getter.

More info: https://url.spec.whatwg.org/#dom-url-host

Returns
URL’s host, serialized, followed by U+003A (:) and URL’s port, serialized

Definition at line 1218 of file url.h.

◆ host() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::host ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - on failure (URL's host and port unchanged)

Definition at line 1549 of file url.h.

◆ host_type()

HostType upa::url::host_type ( ) const
inlinenodiscardnoexcept

The host_type getter.

Returns
URL’s host type as HostType enumeration value

Definition at line 1231 of file url.h.

◆ hostname() [1/2]

std::string_view upa::url::hostname ( ) const
inlinenodiscard

The hostname getter.

More info: https://url.spec.whatwg.org/#dom-url-hostname

Returns
URL’s host, serialized

Definition at line 1227 of file url.h.

◆ hostname() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::hostname ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - on failure (URL's host unchanged)

Definition at line 1560 of file url.h.

◆ href() [1/2]

std::string_view upa::url::href ( ) const
inlinenodiscard

The href getter.

More info: https://url.spec.whatwg.org/#dom-url-href

Returns
serialized URL

Definition at line 1167 of file url.h.

◆ href() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::href ( const StrT & str)
inline

The href setter.

Parses given URL string, and in the case of success assigns parsed URL value. On parse failure leaves URL value unchanged.

Parameters
[in]strURL string to parse
Returns
true - on success; false - on failure

Definition at line 1494 of file url.h.

◆ is_empty()

bool upa::url::is_empty ( PartType t) const
inlinenodiscard

Checks whether the URL's part (URL record member) is empty or null.

Parameters
[in]tURL's part
Returns
true if URL's part t is empty or null, false otherwise

Definition at line 1332 of file url.h.

◆ is_file_scheme()

bool upa::url::is_file_scheme ( ) const
inlinenodiscardnoexcept
Returns
true if URL's scheme is "file", false otherwise

Definition at line 1349 of file url.h.

◆ is_http_scheme()

bool upa::url::is_http_scheme ( ) const
inlinenodiscardnoexcept
Returns
true if URL's scheme is "http" or "https", false otherwise

Definition at line 1353 of file url.h.

◆ is_null()

bool upa::url::is_null ( PartType t) const
inlinenodiscardnoexcept

Checks whether the URL's part (URL record member) is null.

Only the following URL record members can be null:

  • host - check with is_null(upa::url::HOST)
  • port - check with is_null(upa::url::PORT)
  • query - check with is_null(upa::url::QUERY)
  • fragment - check with is_null(upa::url::FRAGMENT)
Parameters
[in]tURL's part
Returns
true if URL's part t is null, false otherwise

Definition at line 1341 of file url.h.

◆ is_special_scheme()

bool upa::url::is_special_scheme ( ) const
inlinenodiscardnoexcept
Returns
true if URL's scheme is special ("ftp", "file", "http", "https", "ws", or "wss"), false otherwise; see: https://url.spec.whatwg.org/#special-scheme

Definition at line 1345 of file url.h.

◆ is_valid()

bool upa::url::is_valid ( ) const
inlinenodiscardnoexcept

Returns whether the URL is valid.

URL is valid if it is not empty, and contains a successfully parsed URL.

Returns
true if URL is valid, false otherwise

Definition at line 1319 of file url.h.

◆ operator=() [1/2]

url & upa::url::operator= ( const url & other)
default

Copy assignment.

Parameters
[in]otherURL to copy from
Returns
*this

◆ operator=() [2/2]

url & upa::url::operator= ( url && other)
inlinenoexcept

Move assignment.

Replaces the contents with those of other using move semantics.

Parameters
[in,out]otherURL to move to this object
Returns
*this

Definition at line 1129 of file url.h.

◆ origin()

std::string upa::url::origin ( ) const
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).

Returns
ASCII serialized URL's origin

Definition at line 1180 of file url.h.

◆ parse() [1/3]

template<class T, class TB, enable_if_str_arg_t< T > = 0, enable_if_str_arg_t< TB > = 0>
validation_errc upa::url::parse ( const T & str_url,
const TB & str_base )
inline

Parses given URL string against base URL.

Parameters
[in]str_urlURL string to parse
[in]str_basebase URL string
Returns
error code (validation_errc::ok on success)

Definition at line 220 of file url.h.

◆ parse() [2/3]

template<class T, enable_if_str_arg_t< T > = 0>
validation_errc upa::url::parse ( const T & str_url,
const url & base )
inline

Parses given URL string against base URL.

Parameters
[in]str_urlURL string to parse
[in]basebase URL
Returns
error code (validation_errc::ok on success)

Definition at line 210 of file url.h.

◆ parse() [3/3]

template<class T, enable_if_str_arg_t< T > = 0>
validation_errc upa::url::parse ( const T & str_url,
const url * base = nullptr )
inline

Parses given URL string against base URL.

Parameters
[in]str_urlURL string to parse
[in]basepointer to base URL, may be nullptr
Returns
error code (validation_errc::ok on success)

Definition at line 199 of file url.h.

◆ password() [1/2]

std::string_view upa::url::password ( ) const
inlinenodiscard

The password getter.

More info: https://url.spec.whatwg.org/#dom-url-password

Returns
URL’s password

Definition at line 1214 of file url.h.

◆ password() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::password ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - if password can not be set

Definition at line 1533 of file url.h.

◆ path()

std::string_view upa::url::path ( ) const
inlinenodiscard

The path getter.

Returns
URL's path, serialized, followed by U+003F (?) and URL’s query

Definition at line 1252 of file url.h.

◆ pathname() [1/2]

std::string_view upa::url::pathname ( ) const
inlinenodiscard

The pathname getter.

More info: https://url.spec.whatwg.org/#dom-url-pathname

Returns
URL’s path, serialized

Definition at line 1259 of file url.h.

◆ pathname() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::pathname ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - on failure (URL's path unchanged)

Definition at line 1589 of file url.h.

◆ port() [1/2]

std::string_view upa::url::port ( ) const
inlinenodiscard

The port getter.

More info: https://url.spec.whatwg.org/#dom-url-port

Returns
URL’s port, serialized, if URL’s port is not null, otherwise empty string

Definition at line 1235 of file url.h.

◆ port() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::port ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - on failure (URL's port unchanged)

Definition at line 1571 of file url.h.

◆ port_int()

int upa::url::port_int ( ) const
inlinenodiscard
Returns
URL’s port, converted to int value, if URL’s port is not null, otherwise -1

Definition at line 1239 of file url.h.

◆ protocol() [1/2]

std::string_view upa::url::protocol ( ) const
inlinenodiscard

The protocol getter.

More info: https://url.spec.whatwg.org/#dom-url-protocol

Returns
URL's scheme, followed by U+003A (:)

Definition at line 1205 of file url.h.

◆ protocol() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::protocol ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - on failure (URL protocol unchanged)

Definition at line 1506 of file url.h.

◆ real_port_int()

int upa::url::real_port_int ( ) const
inlinenodiscard
Returns
URL’s port, converted to int value, if URL’s port is not null, otherwise default port, if URL's scheme has default port, otherwise -1

Definition at line 1244 of file url.h.

◆ safe_assign()

url & upa::url::safe_assign ( url && other)
inline

Safe move assignment.

Replaces the contents with those of other using move semantics. Preserves original url_search_params object.

Parameters
[in,out]otherURL to move to this object
Returns
*this

Definition at line 1140 of file url.h.

◆ search() [1/2]

std::string_view upa::url::search ( ) const
inlinenodiscard

The search getter.

More info: https://url.spec.whatwg.org/#dom-url-search

Returns
empty string or U+003F (?), followed by URL’s query

Definition at line 1265 of file url.h.

◆ search() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::search ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - on failure (URL's query unchanged)

Definition at line 1600 of file url.h.

◆ search_params() [1/2]

url_search_params & upa::url::search_params ( ) &
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).

Returns
reference to this’s query object (url_search_params class)

Definition at line 1285 of file url.h.

◆ search_params() [2/2]

url_search_params upa::url::search_params ( ) &&
inlinenodiscard

The searchParams getter for rvalue url.

Returns
the move constructed copy of this’s query object (url_search_params class)
See also
search_params()&

Definition at line 1291 of file url.h.

◆ serialize()

std::string_view upa::url::serialize ( bool exclude_fragment = false) const
inlinenodiscard

URL serializer.

Returns serialized URL in a std::string_view as defined here: https://url.spec.whatwg.org/#concept-url-serializer

Parameters
[in]exclude_fragmentexclude fragment when serializing
Returns
serialized URL as std::string_view

Definition at line 1307 of file url.h.

◆ set_hash()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_hash ( const StrT & str)
inline

Equivalent to hash(const StrT& str).

Definition at line 402 of file url.h.

◆ set_host()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_host ( const StrT & str)
inline

Equivalent to host(const StrT& str).

Definition at line 337 of file url.h.

◆ set_hostname()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_hostname ( const StrT & str)
inline

Equivalent to hostname(const StrT& str).

Definition at line 350 of file url.h.

◆ set_href()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_href ( const StrT & str)
inline

Equivalent to href(const StrT& str).

Definition at line 285 of file url.h.

◆ set_password()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_password ( const StrT & str)
inline

Equivalent to password(const StrT& str).

Definition at line 324 of file url.h.

◆ set_pathname()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_pathname ( const StrT & str)
inline

Equivalent to pathname(const StrT& str).

Definition at line 376 of file url.h.

◆ set_port()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_port ( const StrT & str)
inline

Equivalent to port(const StrT& str).

Definition at line 363 of file url.h.

◆ set_protocol()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_protocol ( const StrT & str)
inline

Equivalent to protocol(const StrT& str).

Definition at line 298 of file url.h.

◆ set_search()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_search ( const StrT & str)
inline

Equivalent to search(const StrT& str).

Definition at line 389 of file url.h.

◆ set_username()

template<class StrT, enable_if_str_arg_t< StrT > = 0>
bool upa::url::set_username ( const StrT & str)
inline

Equivalent to username(const StrT& str).

Definition at line 311 of file url.h.

◆ swap()

void upa::url::swap ( url & other)
inlinenoexcept

Swaps the contents of two URLs.

Parameters
[in,out]otherURL to exchange the contents with

Definition at line 1428 of file url.h.

◆ to_string()

std::string upa::url::to_string ( ) const
inlinenodiscard
Returns
serialized URL as std::string

Definition at line 1171 of file url.h.

◆ username() [1/2]

std::string_view upa::url::username ( ) const
inlinenodiscard

The username getter.

More info: https://url.spec.whatwg.org/#dom-url-username

Returns
URL’s username

Definition at line 1210 of file url.h.

◆ username() [2/2]

template<class StrT, enable_if_str_arg_t< StrT >>
bool upa::url::username ( const StrT & str)
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

Parameters
[in]strstring to parse
Returns
true - on success; false - if username can not be set

Definition at line 1517 of file url.h.

◆ detail::url_parser

friend class detail::url_parser
friend

Definition at line 734 of file url.h.

◆ detail::url_serializer

friend class detail::url_serializer
friend

Definition at line 732 of file url.h.

◆ detail::url_setter

friend class detail::url_setter
friend

Definition at line 733 of file url.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const url & url )
friend

Performs stream output on URL.

Outputs URL serialized to ASCII string

Parameters
[in]osthe output stream to write to
[in]urlthe url object to serialize and output
Returns
a reference to the output stream
See also
https://url.spec.whatwg.org/#url-serializing

Definition at line 3152 of file url.h.

◆ operator==

bool operator== ( const url & lhs,
const url & rhs )
friend

Lexicographically compares two URL's.

Definition at line 3140 of file url.h.

◆ std::hash< url >

friend struct std::hash< url >
friend

Definition at line 730 of file url.h.

◆ url_search_params

friend class url_search_params
friend

Definition at line 735 of file url.h.


The documentation for this class was generated from the following file: