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

Lightweight URL struct. More...

#include <url_aggregator.h>

Inheritance diagram for ada::url_aggregator:
ada::url_base

Public Member Functions

 url_aggregator ()=default
 
 url_aggregator (const url_aggregator &u)=default
 
 url_aggregator (url_aggregator &&u) noexcept=default
 
url_aggregatoroperator= (url_aggregator &&u) noexcept=default
 
url_aggregatoroperator= (const url_aggregator &u)=default
 
 ~url_aggregator () override=default
 
bool set_href (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_username (std::string_view input)
 
bool set_password (std::string_view input)
 
bool set_port (std::string_view input)
 
bool set_pathname (std::string_view input)
 
void set_search (std::string_view input)
 
void set_hash (std::string_view input)
 
bool has_valid_domain () const noexcept override
 
std::string get_origin () const noexcept override
 
std::string_view get_href () const noexcept
 
std::string_view get_username () const noexcept
 
std::string_view get_password () const noexcept
 
std::string_view get_port () const noexcept
 
std::string_view get_hash () const noexcept
 
std::string_view get_host () const noexcept
 
std::string_view get_hostname () const noexcept
 
std::string_view get_pathname () const noexcept
 
ada_really_inline uint32_t get_pathname_length () const noexcept
 
std::string_view get_search () const noexcept
 
std::string_view get_protocol () const noexcept
 
ada_really_inline bool has_credentials () const noexcept
 
ada_really_inline const ada::url_componentsget_components () const noexcept
 
std::string to_string () const override
 
std::string to_diagram () const
 
bool validate () const noexcept
 
bool has_empty_hostname () const noexcept
 
bool has_hostname () const noexcept
 
bool has_non_empty_username () const noexcept
 
bool has_non_empty_password () const noexcept
 
bool has_port () const noexcept
 
bool has_password () const noexcept
 
bool has_hash () const noexcept override
 
bool has_search () const noexcept override
 
void clear_port ()
 
void clear_hash ()
 
void clear_search () override
 
- Public Member Functions inherited from ada::url_base
virtual ~url_base ()=default
 
ada_really_inline bool is_special () const noexcept
 

Friends

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_aggregator &url) noexcept
 

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

Lightweight URL struct.

The url_aggregator class aims to minimize temporary memory allocation while representing a parsed URL. Internally, it contains a single normalized URL (the href), and it makes available the components, mostly using std::string_view.

Definition at line 25 of file url_aggregator.h.

Constructor & Destructor Documentation

◆ url_aggregator() [1/3]

ada::url_aggregator::url_aggregator ( )
default

◆ url_aggregator() [2/3]

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

◆ url_aggregator() [3/3]

ada::url_aggregator::url_aggregator ( url_aggregator && u)
defaultnoexcept

◆ ~url_aggregator()

ada::url_aggregator::~url_aggregator ( )
overridedefault

Member Function Documentation

◆ clear_hash()

◆ clear_port()

◆ clear_search()

◆ get_components()

ada_really_inline const ada::url_components & ada::url_aggregator::get_components ( ) const
noexcept

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 constant reference to the underlying component attribute.
See also
https://github.com/servo/rust-url/blob/b65a45515c10713f6d212e6726719a020203cc98/url/src/quirks.rs#L31

Definition at line 731 of file url_aggregator-inl.h.

◆ get_hash()

std::string_view ada::url_aggregator::get_hash ( ) const
noexcept

Return U+0023 (#), followed by this's URL's fragment. This function does not allocate memory.

Returns
a lightweight std::string_view..
See also
https://url.spec.whatwg.org/#dom-url-hash

Definition at line 678 of file url_aggregator.cpp.

References ada::url_components::hash_start, ada::url_components::omitted, and ada::parse().

Referenced by clear_hash().

◆ get_host()

std::string_view ada::url_aggregator::get_host ( ) const
noexcept

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

Returns
a lightweight std::string_view.
See also
https://url.spec.whatwg.org/#dom-url-host

Definition at line 691 of file url_aggregator.cpp.

References ada::url_components::host_end, ada::url_components::host_start, ada::parse(), and ada::url_components::pathname_start.

Referenced by get_origin().

◆ get_hostname()

std::string_view ada::url_aggregator::get_hostname ( ) const
noexcept

Return this's URL's host, serialized. This function does not allocate memory. When there is no host, this function returns the empty view.

Returns
a lightweight std::string_view.
See also
https://url.spec.whatwg.org/#dom-url-hostname

Definition at line 709 of file url_aggregator.cpp.

References ada::url_components::host_end, ada::url_components::host_start, and ada::parse().

Referenced by has_valid_domain().

◆ get_href()

std::string_view ada::url_aggregator::get_href ( ) const
inlinenoexcept

Return the normalized string. This function does not allocate memory. It is highly efficient.

Returns
a constant reference to the underlying normalized URL.
See also
https://url.spec.whatwg.org/#dom-url-href
https://url.spec.whatwg.org/#concept-url-serializer

Definition at line 847 of file url_aggregator-inl.h.

References ada::parse().

◆ get_origin()

std::string ada::url_aggregator::get_origin ( ) const
overridevirtualnoexcept

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 624 of file url_aggregator.cpp.

References ada::scheme::FILE, get_host(), get_pathname(), get_protocol(), ada::scheme::HTTP, ada::scheme::HTTPS, ada::url_base::is_special(), and ada::parse().

◆ get_password()

std::string_view ada::url_aggregator::get_password ( ) const
noexcept

The password getter steps are to return this's URL's password. This function does not allocate memory.

Returns
a lightweight std::string_view.
See also
https://url.spec.whatwg.org/#dom-url-password

Definition at line 660 of file url_aggregator.cpp.

References has_non_empty_password(), ada::url_components::host_start, ada::parse(), and ada::url_components::username_end.

◆ get_pathname()

std::string_view ada::url_aggregator::get_pathname ( ) const
noexcept

The pathname getter steps are to return the result of URL path serializing this's URL. This function does not allocate memory.

Returns
a lightweight std::string_view.
See also
https://url.spec.whatwg.org/#dom-url-pathname

Definition at line 723 of file url_aggregator.cpp.

References ada::url_components::hash_start, ada::url_components::omitted, ada::parse(), ada::url_components::pathname_start, and ada::url_components::search_start.

Referenced by get_origin().

◆ get_pathname_length()

ada_really_inline uint32_t ada::url_aggregator::get_pathname_length ( ) const
noexcept

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 156 of file url_aggregator-inl.h.

References ada::url_components::hash_start, ada::url_components::omitted, ada::parse(), ada::url_components::pathname_start, and ada::url_components::search_start.

◆ get_port()

std::string_view ada::url_aggregator::get_port ( ) const
noexcept

Return this's URL's port, serialized. This function does not allocate memory.

Returns
a lightweight std::string_view.
See also
https://url.spec.whatwg.org/#dom-url-port

Definition at line 669 of file url_aggregator.cpp.

References ada::url_components::host_end, ada::url_components::omitted, ada::parse(), ada::url_components::pathname_start, and ada::url_components::port.

◆ get_protocol()

std::string_view ada::url_aggregator::get_protocol ( ) const
noexcept

The protocol getter steps are to return this's URL's scheme, followed by U+003A (:). This function does not allocate memory.

Returns
a lightweight std::string_view.
See also
https://url.spec.whatwg.org/#dom-url-protocol

Definition at line 754 of file url_aggregator.cpp.

References ada::parse(), and ada::url_components::protocol_end.

Referenced by get_origin().

◆ get_search()

std::string_view ada::url_aggregator::get_search ( ) const
noexcept

Return U+003F (?), followed by this's URL's query. This function does not allocate memory.

Returns
a lightweight std::string_view.
See also
https://url.spec.whatwg.org/#dom-url-search

Definition at line 737 of file url_aggregator.cpp.

References ada::url_components::hash_start, ada::url_components::omitted, ada::parse(), and ada::url_components::search_start.

Referenced by clear_search().

◆ get_username()

std::string_view ada::url_aggregator::get_username ( ) const
noexcept

The username getter steps are to return this's URL's username. This function does not allocate memory.

Returns
a lightweight std::string_view.
See also
https://url.spec.whatwg.org/#dom-url-username

Definition at line 651 of file url_aggregator.cpp.

References has_non_empty_username(), ada::parse(), ada::url_components::protocol_end, and ada::url_components::username_end.

◆ has_credentials()

ada_really_inline bool ada::url_aggregator::has_credentials ( ) const
noexcept

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

Definition at line 719 of file url_aggregator-inl.h.

References has_non_empty_password(), has_non_empty_username(), and ada::parse().

◆ has_empty_hostname()

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

Definition at line 791 of file url_aggregator-inl.h.

References has_hostname(), ada::url_components::host_end, ada::url_components::host_start, and ada::url_components::username_end.

◆ has_hash()

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

Implements ada::url_base.

Definition at line 709 of file url_aggregator-inl.h.

References ada::url_components::hash_start, ada::url_components::omitted, and ada::parse().

◆ has_hostname()

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

Definition at line 804 of file url_aggregator-inl.h.

Referenced by has_empty_hostname(), and has_port().

◆ has_non_empty_password()

bool ada::url_aggregator::has_non_empty_password ( ) const
inlinenoexcept
Returns
true if the URL has a non-empty password

Definition at line 779 of file url_aggregator-inl.h.

References ada::url_components::host_start, ada::parse(), and ada::url_components::username_end.

Referenced by get_password(), and has_credentials().

◆ has_non_empty_username()

bool ada::url_aggregator::has_non_empty_username ( ) const
inlinenoexcept
Returns
true if the URL has a non-empty username

Definition at line 774 of file url_aggregator-inl.h.

References ada::parse(), ada::url_components::protocol_end, and ada::url_components::username_end.

Referenced by get_username(), and has_credentials().

◆ has_password()

bool ada::url_aggregator::has_password ( ) const
inlinenoexcept
Returns
true if the URL has a password

Definition at line 784 of file url_aggregator-inl.h.

References ada::url_components::host_start, ada::parse(), and ada::url_components::username_end.

◆ has_port()

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

Definition at line 808 of file url_aggregator-inl.h.

References has_hostname(), ada::url_components::host_end, ada::parse(), and ada::url_components::pathname_start.

◆ has_search()

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

Implements ada::url_base.

Definition at line 714 of file url_aggregator-inl.h.

References ada::url_components::omitted, ada::parse(), and ada::url_components::search_start.

◆ has_valid_domain()

bool ada::url_aggregator::has_valid_domain ( ) const
overridevirtualnoexcept

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 852 of file url_aggregator.cpp.

References get_hostname(), ada::url_components::host_end, and ada::url_components::host_start.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ set_hash()

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

◆ set_host()

bool ada::url_aggregator::set_host ( std::string_view input)

Definition at line 610 of file url_aggregator.cpp.

References ADA_ASSERT_TRUE, ada::parse(), and validate().

◆ set_hostname()

bool ada::url_aggregator::set_hostname ( std::string_view input)

Definition at line 617 of file url_aggregator.cpp.

References ADA_ASSERT_TRUE, ada::parse(), and validate().

◆ set_href()

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

Definition at line 412 of file url_aggregator.cpp.

References ADA_ASSERT_TRUE, ada::parse(), and ada::parse< url_aggregator >().

◆ set_password()

bool ada::url_aggregator::set_password ( std::string_view input)

◆ set_pathname()

bool ada::url_aggregator::set_pathname ( std::string_view input)

◆ set_port()

bool ada::url_aggregator::set_port ( std::string_view input)

◆ set_protocol()

bool ada::url_aggregator::set_protocol ( std::string_view input)

◆ set_search()

◆ set_username()

bool ada::url_aggregator::set_username ( std::string_view input)

◆ to_diagram()

◆ to_string()

std::string ada::url_aggregator::to_string ( ) const
overridevirtual

Returns a string representation of this URL.

Implements ada::url_base.

Definition at line 759 of file url_aggregator.cpp.

References ada::url_components::omitted, and ada::parse().

◆ validate()

bool ada::url_aggregator::validate ( ) const
noexcept

Verifies that the parsed URL could be valid. Useful for debugging purposes.

Returns
true if the URL is valid, otherwise return true of the offsets are possible.

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

Definition at line 1374 of file url_aggregator.cpp.

References ada::url_components::check_offset_consistency(), ada::url_base::has_opaque_path, ada::url_components::hash_start, ada::url_components::host_end, ada::url_components::host_start, ada::url_base::is_valid, ada::url_components::omitted, ada::parse(), ada::url_components::pathname_start, ada::url_components::protocol_end, ada::url_components::search_start, to_diagram(), and ada::url_components::username_end.

Referenced by clear_hash(), clear_port(), clear_search(), set_hash(), set_host(), set_hostname(), set_password(), set_pathname(), set_port(), set_protocol(), set_search(), and set_username().

Friends And Related Symbol Documentation

◆ ada::helpers::strip_trailing_spaces_from_opaque_path

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

◆ ada::parser::parse_url


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