Ada 2.9.0
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
ada::url Struct Reference

Generic URL struct reliant on std::string instantiation. More...

#include <url.h>

Inheritance diagram for ada::url:
ada::url_base ada::url_base

Public Member Functions

 url ()=default
 
 url (const url &u)=default
 
 url (url &&u) noexcept=default
 
urloperator= (url &&u) noexcept=default
 
urloperator= (const url &u)=default
 
 ~url () override=default
 
bool has_empty_hostname () const noexcept
 
bool has_port () const noexcept
 
bool has_hostname () const noexcept
 
bool has_valid_domain () const noexcept override
 
std::string to_string () const override
 
ada_really_inline std::string get_href () const noexcept
 
std::string get_origin () const noexcept override
 
std::string get_protocol () const noexcept
 
std::string get_host () const noexcept
 
std::string get_hostname () const noexcept
 
std::string_view get_pathname () const noexcept
 
ada_really_inline size_t get_pathname_length () const noexcept
 
std::string get_search () const noexcept
 
const std::string & get_username () const noexcept
 
bool set_username (std::string_view input)
 
bool set_password (std::string_view input)
 
bool set_port (std::string_view input)
 
void set_hash (std::string_view input)
 
void set_search (std::string_view input)
 
bool set_pathname (std::string_view input)
 
bool set_host (std::string_view input)
 
bool set_hostname (std::string_view input)
 
bool set_protocol (std::string_view input)
 
bool set_href (std::string_view input)
 
const std::string & get_password () const noexcept
 
std::string get_port () const noexcept
 
std::string get_hash () const noexcept
 
ada_really_inline bool has_credentials () const noexcept
 
ada_really_inline ada::url_components get_components () const noexcept
 
bool has_hash () const noexcept override
 
bool has_search () const noexcept override
 
 url ()=default
 
 url (const url &u)=default
 
 url (url &&u) noexcept=default
 
urloperator= (url &&u) noexcept=default
 
urloperator= (const url &u)=default
 
 ~url () override=default
 
bool has_empty_hostname () const noexcept
 
bool has_port () const noexcept
 
bool has_hostname () const noexcept
 
bool has_valid_domain () const noexcept override
 
std::string to_string () const override
 
ada_really_inline std::string get_href () const noexcept
 
std::string get_origin () const noexcept override
 
std::string get_protocol () const noexcept
 
std::string get_host () const noexcept
 
std::string get_hostname () const noexcept
 
std::string_view get_pathname () const noexcept
 
ada_really_inline size_t get_pathname_length () const noexcept
 
std::string get_search () const noexcept
 
const std::string & get_username () const noexcept
 
bool set_username (std::string_view input)
 
bool set_password (std::string_view input)
 
bool set_port (std::string_view input)
 
void set_hash (std::string_view input)
 
void set_search (std::string_view input)
 
bool set_pathname (std::string_view input)
 
bool set_host (std::string_view input)
 
bool set_hostname (std::string_view input)
 
bool set_protocol (std::string_view input)
 
bool set_href (std::string_view input)
 
const std::string & get_password () const noexcept
 
std::string get_port () const noexcept
 
std::string get_hash () const noexcept
 
ada_really_inline bool has_credentials () const noexcept
 
ada_really_inline ada::url_components get_components () const noexcept
 
bool has_hash () const noexcept override
 
bool has_search () const noexcept override
 
- Public Member Functions inherited from ada::url_base
virtual ~url_base ()=default
 
ada_really_inline bool is_special () const noexcept
 
virtual ~url_base ()=default
 
ada_really_inline bool is_special () const noexcept
 

Friends

ada::url ada::parser::parse_url (std::string_view, const ada::url *)
 
ada::url_aggregator ada::parser::parse_url (std::string_view, const ada::url_aggregator *)
 
void ada::helpers::strip_trailing_spaces_from_opaque_path (ada::url &url) noexcept
 
ada::url ada::parser::parse_url_impl (std::string_view, const ada::url *)
 
ada::url_aggregator ada::parser::parse_url_impl (std::string_view, const ada::url_aggregator *)
 
ada::url ada::parser::parse_url (std::string_view, const ada::url *)
 
ada::url_aggregator ada::parser::parse_url (std::string_view, const ada::url_aggregator *)
 
void ada::helpers::strip_trailing_spaces_from_opaque_path (ada::url &url) noexcept
 
ada::url ada::parser::parse_url_impl (std::string_view, const ada::url *)
 
ada::url_aggregator ada::parser::parse_url_impl (std::string_view, const ada::url_aggregator *)
 

Additional Inherited Members

- Public Attributes inherited from ada::url_base
bool is_valid {true}
 
bool has_opaque_path {false}
 
url_host_type host_type = url_host_type::DEFAULT
 

Detailed Description

Generic URL struct reliant on std::string instantiation.

To disambiguate from a valid URL string it can also be referred to as a URL record. A URL is a struct that represents a universal identifier. Unlike the url_aggregator, the ada::url represents the different components of a parsed URL as independent std::string instances. This makes the structure heavier and more reliant on memory allocations. When getting components from the parsed URL, a new std::string is typically constructed.

See also
https://url.spec.whatwg.org/#url-representation

Definition at line 5258 of file ada.h.

Constructor & Destructor Documentation

◆ url() [1/6]

ada::url::url ( )
default

◆ url() [2/6]

ada::url::url ( const url & u)
default

◆ url() [3/6]

ada::url::url ( url && u)
defaultnoexcept

◆ ~url() [1/2]

ada::url::~url ( )
overridedefault

◆ url() [4/6]

ada::url::url ( )
default

◆ url() [5/6]

ada::url::url ( const url & u)
default

◆ url() [6/6]

ada::url::url ( url && u)
defaultnoexcept

◆ ~url() [2/2]

ada::url::~url ( )
overridedefault

Member Function Documentation

◆ get_components() [1/2]

ada_really_inline ada::url_components ada::url::get_components ( ) const
nodiscardnoexcept

Useful for implementing efficient serialization for the URL.

https://user:pass@example.com:1234/foo/bar?baz#quux | | | | ^^^^| | | | | | | | | | ----- hash_start | | | | | |------— search_start | | | | | ----------------- pathname_start | | | |------------------— port | | | ----------------------- host_end | |-------------------------------— host_start | --------------------------------------- username_end ------------------------------------------— protocol_end

Inspired after servo/url

Returns
a newly constructed component.
See also
https://github.com/servo/rust-url/blob/b65a45515c10713f6d212e6726719a020203cc98/url/src/quirks.rs#L31

Definition at line 46 of file url-inl.h.

References ada::checkers::begins_with(), get_protocol(), get_search(), has_credentials(), ada::url_base::has_opaque_path, and ada::url_components::protocol_end.

◆ get_components() [2/2]

ada_really_inline ada::url_components ada::url::get_components ( ) const
nodiscardnoexcept

Useful for implementing efficient serialization for the URL.

https://user:pass@example.com:1234/foo/bar?baz#quux | | | | ^^^^| | | | | | | | | | ----- hash_start | | | | | |------— search_start | | | | | ----------------- pathname_start | | | |------------------— port | | | ----------------------- host_end | |-------------------------------— host_start | --------------------------------------- username_end ------------------------------------------— protocol_end

Inspired after servo/url

Returns
a newly constructed component.
See also
https://github.com/servo/rust-url/blob/b65a45515c10713f6d212e6726719a020203cc98/url/src/quirks.rs#L31

◆ get_hash() [1/2]

std::string ada::url::get_hash ( ) const
nodiscardnoexcept

Return U+0023 (#), followed by this's URL's fragment.

Returns
a newly constructed string representing the hash.
See also
https://url.spec.whatwg.org/#dom-url-hash

Definition at line 11891 of file ada.cpp.

◆ get_hash() [2/2]

std::string ada::url::get_hash ( ) const
nodiscardnoexcept

Return U+0023 (#), followed by this's URL's fragment.

Returns
a newly constructed string representing the hash.
See also
https://url.spec.whatwg.org/#dom-url-hash

◆ get_host() [1/2]

std::string ada::url::get_host ( ) const
nodiscardnoexcept

Return url's host, serialized, followed by U+003A (:) and url's port, serialized. When there is no host, this function returns the empty string.

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-host

Definition at line 11850 of file ada.cpp.

◆ get_host() [2/2]

std::string ada::url::get_host ( ) const
nodiscardnoexcept

Return url's host, serialized, followed by U+003A (:) and url's port, serialized. When there is no host, this function returns the empty string.

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-host

◆ get_hostname() [1/2]

std::string ada::url::get_hostname ( ) const
nodiscardnoexcept

Return this's URL's host, serialized. When there is no host, this function returns the empty string.

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-hostname

Definition at line 11864 of file ada.cpp.

Referenced by ada::parser::parse_url_impl().

◆ get_hostname() [2/2]

std::string ada::url::get_hostname ( ) const
nodiscardnoexcept

Return this's URL's host, serialized. When there is no host, this function returns the empty string.

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-hostname

◆ get_href() [1/2]

◆ get_href() [2/2]

◆ get_origin() [1/2]

std::string ada::url::get_origin ( ) const
nodiscardoverridevirtualnoexcept

The origin getter steps are to return the serialization of this's URL's origin. [HTML]

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#concept-url-origin

Implements ada::url_base.

Definition at line 11816 of file ada.cpp.

References ada::parse().

◆ get_origin() [2/2]

std::string ada::url::get_origin ( ) const
nodiscardoverridevirtualnoexcept

The origin getter steps are to return the serialization of this's URL's origin. [HTML]

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#concept-url-origin

Implements ada::url_base.

◆ get_password() [1/2]

const std::string & ada::url::get_password ( ) const
nodiscardnoexcept

The password getter steps are to return this's URL's password.

Returns
a constant reference to the underlying string.
See also
https://url.spec.whatwg.org/#dom-url-password

Definition at line 11883 of file ada.cpp.

Referenced by get_href().

◆ get_password() [2/2]

const std::string & ada::url::get_password ( ) const
nodiscardnoexcept

The password getter steps are to return this's URL's password.

Returns
a constant reference to the underlying string.
See also
https://url.spec.whatwg.org/#dom-url-password

◆ get_pathname() [1/2]

std::string_view ada::url::get_pathname ( ) const
nodiscardnoexcept

The pathname getter steps are to return the result of URL path serializing this's URL.

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-pathname

Definition at line 11868 of file ada.cpp.

Referenced by ada::parser::parse_url_impl().

◆ get_pathname() [2/2]

std::string_view ada::url::get_pathname ( ) const
nodiscardnoexcept

The pathname getter steps are to return the result of URL path serializing this's URL.

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-pathname

◆ get_pathname_length() [1/2]

size_t ada::url::get_pathname_length ( ) const
nodiscardnoexcept

Compute the pathname length in bytes without instantiating a view or a string.

Returns
size of the pathname in bytes
See also
https://url.spec.whatwg.org/#dom-url-pathname

Definition at line 42 of file url-inl.h.

◆ get_pathname_length() [2/2]

ada_really_inline size_t ada::url::get_pathname_length ( ) const
nodiscardnoexcept

Compute the pathname length in bytes without instantiating a view or a string.

Returns
size of the pathname in bytes
See also
https://url.spec.whatwg.org/#dom-url-pathname

◆ get_port() [1/2]

std::string ada::url::get_port ( ) const
nodiscardnoexcept

Return this's URL's port, serialized.

Returns
a newly constructed string representing the port.
See also
https://url.spec.whatwg.org/#dom-url-port

Definition at line 11887 of file ada.cpp.

Referenced by get_href().

◆ get_port() [2/2]

std::string ada::url::get_port ( ) const
nodiscardnoexcept

Return this's URL's port, serialized.

Returns
a newly constructed string representing the port.
See also
https://url.spec.whatwg.org/#dom-url-port

◆ get_protocol() [1/2]

std::string ada::url::get_protocol ( ) const
nodiscardnoexcept

The protocol getter steps are to return this's URL's scheme, followed by U+003A (:).

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-protocol

Definition at line 11842 of file ada.cpp.

References ada::scheme::details::is_special_list.

Referenced by get_components(), get_href(), and ada::parser::parse_url_impl().

◆ get_protocol() [2/2]

std::string ada::url::get_protocol ( ) const
nodiscardnoexcept

The protocol getter steps are to return this's URL's scheme, followed by U+003A (:).

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-protocol

◆ get_search() [1/2]

std::string ada::url::get_search ( ) const
nodiscardnoexcept

Return U+003F (?), followed by this's URL's query.

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-search

Definition at line 11872 of file ada.cpp.

Referenced by get_components().

◆ get_search() [2/2]

std::string ada::url::get_search ( ) const
nodiscardnoexcept

Return U+003F (?), followed by this's URL's query.

Returns
a newly allocated string.
See also
https://url.spec.whatwg.org/#dom-url-search

◆ get_username() [1/2]

const std::string & ada::url::get_username ( ) const
nodiscardnoexcept

The username getter steps are to return this's URL's username.

Returns
a constant reference to the underlying string.
See also
https://url.spec.whatwg.org/#dom-url-username

Definition at line 11879 of file ada.cpp.

◆ get_username() [2/2]

const std::string & ada::url::get_username ( ) const
nodiscardnoexcept

The username getter steps are to return this's URL's username.

Returns
a constant reference to the underlying string.
See also
https://url.spec.whatwg.org/#dom-url-username

◆ has_credentials() [1/2]

ada_really_inline bool ada::url::has_credentials ( ) const
nodiscardnoexcept

A URL includes credentials if its username or password is not the empty string.

Definition at line 19 of file url-inl.h.

Referenced by get_components(), and get_href().

◆ has_credentials() [2/2]

ada_really_inline bool ada::url::has_credentials ( ) const
nodiscardnoexcept

A URL includes credentials if its username or password is not the empty string.

◆ has_empty_hostname() [1/2]

bool ada::url::has_empty_hostname ( ) const
inlinenodiscardnoexcept
Returns
true if it has an host but it is the empty string

Definition at line 29 of file url-inl.h.

◆ has_empty_hostname() [2/2]

bool ada::url::has_empty_hostname ( ) const
inlinenodiscardnoexcept
Returns
true if it has an host but it is the empty string

◆ has_hash() [1/2]

bool ada::url::has_hash ( ) const
inlinenodiscardoverridevirtualnoexcept
Returns
true if the URL has a hash component

Implements ada::url_base.

Definition at line 155 of file url-inl.h.

◆ has_hash() [2/2]

bool ada::url::has_hash ( ) const
inlinenodiscardoverridevirtualnoexcept
Returns
true if the URL has a hash component

Implements ada::url_base.

◆ has_hostname() [1/2]

bool ada::url::has_hostname ( ) const
inlinenodiscardnoexcept
Returns
true if it has a host (included an empty host)

Definition at line 35 of file url-inl.h.

◆ has_hostname() [2/2]

bool ada::url::has_hostname ( ) const
inlinenodiscardnoexcept
Returns
true if it has a host (included an empty host)

◆ has_port() [1/2]

ada_really_inline bool ada::url::has_port ( ) const
inlinenodiscardnoexcept
Returns
true if the URL has a (non default) port

Definition at line 22 of file url-inl.h.

◆ has_port() [2/2]

bool ada::url::has_port ( ) const
inlinenodiscardnoexcept
Returns
true if the URL has a (non default) port

◆ has_search() [1/2]

bool ada::url::has_search ( ) const
inlinenodiscardoverridevirtualnoexcept
Returns
true if the URL has a search component

Implements ada::url_base.

Definition at line 159 of file url-inl.h.

◆ has_search() [2/2]

bool ada::url::has_search ( ) const
inlinenodiscardoverridevirtualnoexcept
Returns
true if the URL has a search component

Implements ada::url_base.

◆ has_valid_domain() [1/2]

bool ada::url::has_valid_domain ( ) const
nodiscardoverridevirtualnoexcept

Returns true if this URL has a valid domain as per RFC 1034 and corresponding specifications. Among other things, it requires that the domain string has fewer than 255 octets.

Implements ada::url_base.

Definition at line 11798 of file ada.cpp.

◆ has_valid_domain() [2/2]

bool ada::url::has_valid_domain ( ) const
nodiscardoverridevirtualnoexcept

Returns true if this URL has a valid domain as per RFC 1034 and corresponding specifications. Among other things, it requires that the domain string has fewer than 255 octets.

Implements ada::url_base.

◆ operator=() [1/4]

url & ada::url::operator= ( const url & u)
default

◆ operator=() [2/4]

url & ada::url::operator= ( const url & u)
default

◆ operator=() [3/4]

url & ada::url::operator= ( url && u)
defaultnoexcept

◆ operator=() [4/4]

url & ada::url::operator= ( url && u)
defaultnoexcept

◆ set_hash() [1/2]

void ada::url::set_hash ( std::string_view input)

This function always succeeds.

See also
https://url.spec.whatwg.org/#dom-url-hash

Definition at line 12049 of file ada.cpp.

References ada::character_sets::FRAGMENT_PERCENT_ENCODE.

◆ set_hash() [2/2]

void ada::url::set_hash ( std::string_view input)

This function always succeeds.

See also
https://url.spec.whatwg.org/#dom-url-hash

◆ set_host() [1/2]

bool ada::url::set_host ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-host

Definition at line 11993 of file ada.cpp.

Referenced by ada::parser::parse_url_impl().

◆ set_host() [2/2]

bool ada::url::set_host ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-host

◆ set_hostname() [1/2]

bool ada::url::set_hostname ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-hostname

Definition at line 11997 of file ada.cpp.

Referenced by ada::parser::parse_url_impl().

◆ set_hostname() [2/2]

bool ada::url::set_hostname ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-hostname

◆ set_href() [1/2]

bool ada::url::set_href ( std::string_view input)

◆ set_href() [2/2]

bool ada::url::set_href ( std::string_view input)

◆ set_password() [1/2]

bool ada::url::set_password ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-password

Definition at line 12010 of file ada.cpp.

◆ set_password() [2/2]

bool ada::url::set_password ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-password

◆ set_pathname() [1/2]

bool ada::url::set_pathname ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-search

Definition at line 12082 of file ada.cpp.

◆ set_pathname() [2/2]

bool ada::url::set_pathname ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-search

◆ set_port() [1/2]

bool ada::url::set_port ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-port

Definition at line 12019 of file ada.cpp.

◆ set_port() [2/2]

bool ada::url::set_port ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-port

◆ set_protocol() [1/2]

bool ada::url::set_protocol ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-protocol

Definition at line 12091 of file ada.cpp.

◆ set_protocol() [2/2]

bool ada::url::set_protocol ( std::string_view input)
Returns
Returns true on success.
See also
https://url.spec.whatwg.org/#dom-url-protocol

◆ set_search() [1/2]

void ada::url::set_search ( std::string_view input)

◆ set_search() [2/2]

void ada::url::set_search ( std::string_view input)

This function always succeeds.

See also
https://url.spec.whatwg.org/#dom-url-search

◆ set_username() [1/2]

bool ada::url::set_username ( std::string_view input)
Returns
Returns true on successful operation.
See also
https://url.spec.whatwg.org/#dom-url-username

Definition at line 12001 of file ada.cpp.

◆ set_username() [2/2]

bool ada::url::set_username ( std::string_view input)
Returns
Returns true on successful operation.
See also
https://url.spec.whatwg.org/#dom-url-username

◆ to_string() [1/2]

std::string ada::url::to_string ( ) const
nodiscardoverridevirtual

Returns a JSON string representation of this URL.

Implements ada::url_base.

Definition at line 11749 of file ada.cpp.

Referenced by ada::operator<<().

◆ to_string() [2/2]

std::string ada::url::to_string ( ) const
nodiscardoverridevirtual

Returns a JSON string representation of this URL.

Implements ada::url_base.

Friends And Related Symbol Documentation

◆ ada::helpers::strip_trailing_spaces_from_opaque_path [1/2]

void ada::helpers::strip_trailing_spaces_from_opaque_path ( ada::url & url)
friend

◆ ada::helpers::strip_trailing_spaces_from_opaque_path [2/2]

void ada::helpers::strip_trailing_spaces_from_opaque_path ( ada::url & url)
friend

◆ ada::parser::parse_url [1/4]

ada::url ada::parser::parse_url ( std::string_view ,
const ada::url *  )
friend

◆ ada::parser::parse_url [2/4]

ada::url ada::parser::parse_url ( std::string_view ,
const ada::url *  )
friend

◆ ada::parser::parse_url [3/4]

ada::url_aggregator ada::parser::parse_url ( std::string_view ,
const ada::url_aggregator *  )
friend

◆ ada::parser::parse_url [4/4]

ada::url_aggregator ada::parser::parse_url ( std::string_view ,
const ada::url_aggregator *  )
friend

◆ ada::parser::parse_url_impl [1/4]

ada::url ada::parser::parse_url_impl ( std::string_view ,
const ada::url *  )
friend

◆ ada::parser::parse_url_impl [2/4]

ada::url ada::parser::parse_url_impl ( std::string_view ,
const ada::url *  )
friend

◆ ada::parser::parse_url_impl [3/4]

ada::url_aggregator ada::parser::parse_url_impl ( std::string_view ,
const ada::url_aggregator *  )
friend

◆ ada::parser::parse_url_impl [4/4]

ada::url_aggregator ada::parser::parse_url_impl ( std::string_view ,
const ada::url_aggregator *  )
friend

The documentation for this struct was generated from the following files: