|
Ada 3.4.0
Fast spec-compliant URL parser
|
Memory-efficient URL representation using a single buffer. More...
#include <url_aggregator.h>
Public Member Functions | |
| url_aggregator ()=default | |
| url_aggregator (const url_aggregator &u)=default | |
| url_aggregator (url_aggregator &&u) noexcept=default | |
| url_aggregator & | operator= (url_aggregator &&u) noexcept=default |
| url_aggregator & | operator= (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 |
| constexpr std::string_view | get_href () const noexcept ada_lifetime_bound |
| std::string_view | get_username () const noexcept ada_lifetime_bound |
| std::string_view | get_password () const noexcept ada_lifetime_bound |
| std::string_view | get_port () const noexcept ada_lifetime_bound |
| std::string_view | get_hash () const noexcept ada_lifetime_bound |
| std::string_view | get_host () const noexcept ada_lifetime_bound |
| std::string_view | get_hostname () const noexcept ada_lifetime_bound |
| constexpr std::string_view | get_pathname () const noexcept ada_lifetime_bound |
| ada_really_inline uint32_t | get_pathname_length () const noexcept |
| std::string_view | get_search () const noexcept ada_lifetime_bound |
| std::string_view | get_protocol () const noexcept ada_lifetime_bound |
| ada_really_inline constexpr bool | has_credentials () const noexcept |
| ada_really_inline const url_components & | get_components () const noexcept |
| std::string | to_string () const override |
| std::string | to_diagram () const |
| constexpr bool | validate () const noexcept |
| constexpr bool | has_empty_hostname () const noexcept |
| constexpr bool | has_hostname () const noexcept |
| constexpr bool | has_non_empty_username () const noexcept |
| constexpr bool | has_non_empty_password () const noexcept |
| constexpr bool | has_port () const noexcept |
| constexpr bool | has_password () const noexcept |
| constexpr bool | has_hash () const noexcept override |
| constexpr 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 constexpr bool | is_special () const noexcept |
Friends | |
| void | helpers::strip_trailing_spaces_from_opaque_path (url_aggregator &url) noexcept |
| url_aggregator | parser::parse_url (std::string_view, const url_aggregator *) |
| url_aggregator | parser::parse_url_impl (std::string_view, const url_aggregator *) |
| url_aggregator | parser::parse_url_impl (std::string_view, const 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 |
Memory-efficient URL representation using a single buffer.
The url_aggregator stores the entire normalized URL in a single string buffer and tracks component boundaries using offsets. This design minimizes memory allocations and is ideal for read-mostly access patterns.
Getter methods return std::string_view pointing into the internal buffer. These views are lightweight (no allocation) but become invalid if the url_aggregator is modified or destroyed.
get_pathname()) are invalidated when any setter is called. Do not use a getter's result as input to a setter on the same object without copying first.ada::parse().Definition at line 46 of file url_aggregator.h.
|
default |
|
default |
References url_aggregator().
|
defaultnoexcept |
References url_aggregator().
|
overridedefault |
References ada_lifetime_bound, ada_really_inline, clear_hash(), clear_port(), clear_search(), get_components(), get_hash(), get_host(), get_hostname(), get_href(), get_origin(), get_password(), get_pathname(), get_pathname_length(), get_port(), get_protocol(), get_search(), get_username(), has_credentials(), has_empty_hostname(), has_hash(), has_hostname(), has_non_empty_password(), has_non_empty_username(), has_password(), has_port(), has_search(), to_diagram(), to_string(), and validate().
|
inline |
Removes the hash/fragment from the URL.
Definition at line 615 of file url_aggregator-inl.h.
References ADA_ASSERT_EQUAL, ADA_ASSERT_TRUE, get_hash(), ada::url_components::omitted, to_diagram(), and validate().
Referenced by ~url_aggregator().
|
inline |
Removes the port from the URL.
Definition at line 566 of file url_aggregator-inl.h.
References ADA_ASSERT_TRUE, ada::url_components::omitted, and validate().
Referenced by set_port(), and ~url_aggregator().
|
inlineoverridevirtual |
Removes the query/search string from the URL.
Implements ada::url_base.
Definition at line 590 of file url_aggregator-inl.h.
References ADA_ASSERT_EQUAL, ADA_ASSERT_TRUE, get_search(), ada::url_components::omitted, to_diagram(), and validate().
Referenced by set_search(), and ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL component offsets for efficient serialization.
The components represent byte offsets into the serialized URL:
Definition at line 726 of file url_aggregator-inl.h.
Referenced by ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL's fragment prefixed with '#' (e.g., "#section"). Does not allocate memory. Returns empty view if no fragment is set. The returned view becomes invalid if this url_aggregator is modified.
Definition at line 738 of file url_aggregator.cpp.
References ada_lifetime_bound, and ada::url_components::omitted.
Referenced by clear_hash(), to_string(), and ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL's host and port (e.g., "example.com:8080"). Does not allocate memory. Returns empty view if no host is set. The returned view becomes invalid if this url_aggregator is modified.
Definition at line 752 of file url_aggregator.cpp.
References ada_lifetime_bound.
Referenced by get_origin(), to_string(), and ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL's hostname (without port). Does not allocate memory. Returns empty view if no host is set. The returned view becomes invalid if this url_aggregator is modified.
Definition at line 771 of file url_aggregator.cpp.
References ada_lifetime_bound.
Referenced by has_valid_domain(), and ~url_aggregator().
|
nodiscardconstexprnoexcept |
Returns the full serialized URL (the href) as a string_view. Does not allocate memory. The returned view becomes invalid if this url_aggregator is modified or destroyed.
Definition at line 843 of file url_aggregator-inl.h.
References ada_lifetime_bound.
Referenced by ~url_aggregator().
|
nodiscardoverridevirtualnoexcept |
Returns the URL's origin (scheme + host + port for special URLs).
Implements ada::url_base.
Definition at line 681 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().
Referenced by ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL's password component. Does not allocate memory. The returned view becomes invalid if this url_aggregator is modified or destroyed.
Definition at line 718 of file url_aggregator.cpp.
References ada_lifetime_bound, and has_non_empty_password().
Referenced by to_string(), and ~url_aggregator().
|
nodiscardconstexprnoexcept |
Returns the URL's path component. Does not allocate memory. The returned view becomes invalid if this url_aggregator is modified or destroyed.
Definition at line 1088 of file url_aggregator-inl.h.
References ada_lifetime_bound, and ada::url_components::omitted.
Referenced by get_origin(), set_pathname(), to_string(), and ~url_aggregator().
|
nodiscardnoexcept |
Returns the byte length of the pathname without creating a string.
Definition at line 154 of file url_aggregator-inl.h.
References ada::url_components::omitted.
Referenced by ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL's port as a string (e.g., "8080"). Does not allocate memory. Returns empty view if no port is set. The returned view becomes invalid if this url_aggregator is modified.
Definition at line 728 of file url_aggregator.cpp.
References ada_lifetime_bound, and ada::url_components::omitted.
Referenced by ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL's scheme followed by a colon (e.g., "https:"). Does not allocate memory. The returned view becomes invalid if this url_aggregator is modified or destroyed.
Definition at line 804 of file url_aggregator.cpp.
References ada_lifetime_bound.
Referenced by get_origin(), to_string(), and ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL's query string prefixed with '?' (e.g., "?foo=bar"). Does not allocate memory. Returns empty view if no query is set. The returned view becomes invalid if this url_aggregator is modified.
Definition at line 786 of file url_aggregator.cpp.
References ada_lifetime_bound, and ada::url_components::omitted.
Referenced by clear_search(), to_string(), and ~url_aggregator().
|
nodiscardnoexcept |
Returns the URL's username component. Does not allocate memory. The returned view becomes invalid if this url_aggregator is modified or destroyed.
Definition at line 708 of file url_aggregator.cpp.
References ada_lifetime_bound, and has_non_empty_username().
Referenced by to_string(), and ~url_aggregator().
|
nodiscardconstexprnoexcept |
Checks if the URL has credentials (non-empty username or password).
true if username or password is non-empty, false otherwise. Definition at line 714 of file url_aggregator-inl.h.
References has_non_empty_password(), and has_non_empty_username().
Referenced by to_string(), and ~url_aggregator().
|
nodiscardconstexprnoexcept |
Checks if the URL has an empty hostname (host is set but empty string).
true if host exists but is empty, false otherwise. Definition at line 787 of file url_aggregator-inl.h.
References has_hostname().
Referenced by ~url_aggregator().
|
nodiscardconstexproverridevirtualnoexcept |
Checks if the URL has a fragment/hash component.
true if hash is present, false otherwise. Implements ada::url_base.
Definition at line 704 of file url_aggregator-inl.h.
References ada::url_components::omitted.
Referenced by ~url_aggregator().
|
nodiscardconstexprnoexcept |
Checks if the URL has a hostname (including empty hostnames).
true if host is present, false otherwise. Definition at line 800 of file url_aggregator-inl.h.
Referenced by has_empty_hostname(), has_port(), and ~url_aggregator().
|
nodiscardconstexprnoexcept |
Checks if the URL has a non-empty password.
true if password is non-empty, false otherwise. Definition at line 775 of file url_aggregator-inl.h.
Referenced by get_password(), has_credentials(), and ~url_aggregator().
|
nodiscardconstexprnoexcept |
Checks if the URL has a non-empty username.
true if username is non-empty, false otherwise. Definition at line 770 of file url_aggregator-inl.h.
Referenced by get_username(), has_credentials(), and ~url_aggregator().
|
nodiscardconstexprnoexcept |
Checks if the URL has a password component (may be empty).
true if password is present, false otherwise. Definition at line 780 of file url_aggregator-inl.h.
Referenced by ~url_aggregator().
|
nodiscardconstexprnoexcept |
Checks if the URL has a non-default port explicitly specified.
true if a port is present, false otherwise. Definition at line 804 of file url_aggregator-inl.h.
References has_hostname().
Referenced by ~url_aggregator().
|
nodiscardconstexproverridevirtualnoexcept |
Checks if the URL has a query/search component.
true if query is present, false otherwise. Implements ada::url_base.
Definition at line 709 of file url_aggregator-inl.h.
References ada::url_components::omitted.
Referenced by ~url_aggregator().
|
nodiscardoverridevirtualnoexcept |
Validates whether the hostname is a valid domain according to RFC 1034.
true if the domain is valid, false otherwise. Implements ada::url_base.
Definition at line 903 of file url_aggregator.cpp.
References get_hostname().
|
default |
References url_aggregator().
|
defaultnoexcept |
References url_aggregator().
| void ada::url_aggregator::set_hash | ( | std::string_view | input | ) |
Definition at line 400 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, ada::url_components::omitted, and validate().
| bool ada::url_aggregator::set_host | ( | std::string_view | input | ) |
Definition at line 667 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, and validate().
| bool ada::url_aggregator::set_hostname | ( | std::string_view | input | ) |
Definition at line 674 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, and validate().
| bool ada::url_aggregator::set_href | ( | std::string_view | input | ) |
The setter functions follow the steps defined in the URL Standard.
The url_aggregator has a single buffer that contains the entire normalized URL. The various components are represented as offsets into that buffer. When you call get_pathname(), for example, you get a std::string_view that points into that buffer. If the url_aggregator is modified, the buffer may be reallocated, and the std::string_view you obtained earlier may become invalid. In particular, this implies that you cannot modify the URL using a setter function with a std::string_view that points into the url_aggregator E.g., the following is incorrect: url->set_hostname(url->get_pathname()). You must first copy the pathname to a separate string. std::string pathname(url->get_pathname()); url->set_hostname(pathname);
The caller is responsible for ensuring that the url_aggregator is not modified while any std::string_view obtained from it is in use.
Definition at line 420 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, and ada::parse< url_aggregator >().
| bool ada::url_aggregator::set_password | ( | std::string_view | input | ) |
Definition at line 257 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, ada::unicode::percent_encode_index(), ada::character_sets::USERINFO_PERCENT_ENCODE, and validate().
| bool ada::url_aggregator::set_pathname | ( | std::string_view | input | ) |
Definition at line 320 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, get_pathname(), ada::url_base::has_opaque_path, and validate().
| bool ada::url_aggregator::set_port | ( | std::string_view | input | ) |
Definition at line 277 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, clear_port(), ada::url_base::is_valid, and validate().
| bool ada::url_aggregator::set_protocol | ( | std::string_view | input | ) |
Definition at line 210 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, ada::checkers::is_alpha(), and validate().
| void ada::url_aggregator::set_search | ( | std::string_view | input | ) |
Definition at line 378 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, clear_search(), ada::url_base::is_special(), ada::character_sets::QUERY_PERCENT_ENCODE, ada::character_sets::SPECIAL_QUERY_PERCENT_ENCODE, and validate().
| bool ada::url_aggregator::set_username | ( | std::string_view | input | ) |
Definition at line 237 of file url_aggregator.cpp.
References ADA_ASSERT_TRUE, ada::unicode::percent_encode_index(), ada::character_sets::USERINFO_PERCENT_ENCODE, and validate().
|
nodiscard |
Returns a visual diagram showing component boundaries in the URL. Useful for debugging and understanding URL structure.
Definition at line 1267 of file url_aggregator.cpp.
References ada::url_base::is_valid, and ada::url_components::omitted.
Referenced by clear_hash(), clear_search(), validate(), and ~url_aggregator().
|
nodiscardoverridevirtual |
Returns a JSON string representation of this URL for debugging.
Implements ada::url_base.
Definition at line 810 of file url_aggregator.cpp.
References get_hash(), get_host(), get_password(), get_pathname(), get_protocol(), get_search(), get_username(), has_credentials(), ada::url_base::has_opaque_path, ada::url_base::is_valid, and ada::url_components::omitted.
Referenced by ada::operator<<(), and ~url_aggregator().
|
nodiscardconstexprnoexcept |
Validates internal consistency of component offsets (for debugging).
true if offsets are consistent, false if corrupted. https://user:[email protected]:1234/foo/bar?baz#quux | | | | ^^^^| | | | | | | | | | ----- hash_start | | | | | |------— search_start | | | | | ----------------- pathname_start | | | |------------------— port | | | ----------------------- host_end | |-------------------------------— host_start | --------------------------------------- username_end ------------------------------------------— protocol_end
Definition at line 918 of file url_aggregator-inl.h.
References ada::url_base::has_opaque_path, ada::url_base::is_valid, ada::url_components::omitted, and to_diagram().
Referenced by clear_hash(), clear_port(), clear_search(), set_hash(), set_host(), set_hostname(), set_password(), set_pathname(), set_port(), set_protocol(), set_search(), set_username(), and ~url_aggregator().
|
friend |
References helpers::strip_trailing_spaces_from_opaque_path, and url_aggregator().
Referenced by helpers::strip_trailing_spaces_from_opaque_path.
|
friend |
References parser::parse_url, and url_aggregator().
Referenced by parser::parse_url.
|
friend |
References parser::parse_url_impl, and url_aggregator().
Referenced by parser::parse_url_impl.
|
friend |
References parser::parse_url_impl, and url_aggregator().