|
Ada 4.1.1
Fast spec-compliant URL parser
|
Represents a parsed URL with individual string components. More...
#include <url.h>
Public Member Functions | |
| url ()=default | |
| url (const url &u)=default | |
| url (url &&u) noexcept=default | |
| url & | operator= (url &&u) noexcept=default |
| url & | operator= (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 |
| size_t | get_href_size () const noexcept |
| std::string | get_origin () const override |
| std::string | get_protocol () const |
| std::string | get_host () const |
| std::string | get_hostname () const |
| constexpr std::string_view | get_pathname () const noexcept |
| ada_really_inline size_t | get_pathname_length () const noexcept |
| std::string | get_search () const |
| 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 |
| std::string | get_hash () const |
| ada_really_inline bool | has_credentials () const noexcept |
| ada_really_inline ada::url_components | get_components () const |
| constexpr bool | has_hash () const noexcept override |
| constexpr bool | has_search () const noexcept override |
| Public Member Functions inherited from ada::url_base | |
| virtual | ~url_base ()=default |
| ada_really_inline constexpr 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) |
| 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_aggregator | ada::parser::parse_url_impl (std::string_view, const ada::url_aggregator *) |
| template<class result_type> | |
| bool | ada::parser::try_parse_simple_absolute (std::string_view, result_type &) |
| template<class result_type> | |
| bool | ada::parser::finish_simple_absolute_with_port (std::string_view, result_type &, ada::scheme::type, uint32_t, size_t, size_t, size_t, bool) |
| template<class result_type> | |
| bool | ada::parser::try_parse_simple_relative (std::string_view, const result_type &, result_type &) |
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 |
Represents a parsed URL with individual string components.
The url struct stores each URL component (scheme, username, password, host, port, path, query, fragment) as a separate std::string. This provides flexibility but incurs more memory allocations compared to url_aggregator.
When to use ada::url:
When to use ada::url_aggregator instead:
|
default |
|
default |
References url().
|
defaultnoexcept |
References url().
|
overridedefault |
|
nodiscard |
Returns the URL component offsets for efficient serialization.
The components represent byte offsets into the serialized URL:
Definition at line 55 of file url-inl.h.
References ada_really_inline, get_protocol(), get_search(), has_credentials(), ada::url_base::has_opaque_path, ada::url_components::hash_start, ada::url_components::host_end, ada::url_components::host_start, ada::url_components::pathname_start, ada::url_components::port, ada::url_components::protocol_end, ada::url_components::search_start, and ada::url_components::username_end.
Referenced by exercise_url_predicates().
|
nodiscard |
Returns the URL's fragment prefixed with '#' (e.g., "#section"). Returns empty string if no fragment is set.
Definition at line 609 of file url.cpp.
Referenced by check_components_agree(), and exercise_url_predicates().
|
nodiscard |
Returns the URL's host and port (e.g., "example.com:8080"). If no port is set, returns just the host. Returns empty string if no host.
Definition at line 573 of file url.cpp.
References get_port().
Referenced by check_components_agree(), exercise_url_predicates(), and get_origin().
|
nodiscard |
Returns the URL's hostname (without port). Returns empty string if no host is set.
Definition at line 587 of file url.cpp.
Referenced by check_components_agree(), exercise_url_predicates(), and ada::parser::parse_url_impl().
|
nodiscard |
Returns the full serialized URL (the href).
Definition at line 196 of file url-inl.h.
References ada_really_inline, get_href_size(), has_credentials(), ada::url_base::has_opaque_path, ada::url_base::is_special(), and ada::scheme::details::is_special_list.
Referenced by check_components_agree(), check_href_size(), check_href_size_invariant(), exercise_url_predicates(), LLVMFuzzerTestOneInput(), and ada::parser::parse_url_impl().
|
inlinenodiscardnoexcept |
Returns the byte length of the serialized URL without allocating a string.
Definition at line 283 of file url-inl.h.
References has_credentials(), ada::url_base::has_opaque_path, ada::url_base::is_special(), and ada::scheme::details::is_special_list.
Referenced by check_href_size(), check_href_size_invariant(), get_href(), ada::parser::parse_url_impl(), set_hash(), set_password(), set_pathname(), set_port(), set_protocol(), set_search(), and set_username().
|
nodiscardoverridevirtual |
Returns the URL's origin as a string (scheme + host + port for special URLs).
Implements ada::url_base.
Definition at line 539 of file url.cpp.
References ada::scheme::FILE, get_host(), get_protocol(), ada::scheme::HTTP, ada::scheme::HTTPS, ada::url_base::is_special(), and ada::parse().
Referenced by exercise_url_predicates().
|
nodiscardnoexcept |
Returns the URL's password component.
Definition at line 601 of file url.cpp.
Referenced by check_components_agree(), and exercise_url_predicates().
|
nodiscardconstexprnoexcept |
Returns the URL's path component.
Definition at line 51 of file url-inl.h.
Referenced by check_components_agree(), exercise_url_predicates(), and ada::parser::parse_url_impl().
|
nodiscardnoexcept |
Returns the byte length of the pathname without creating a string.
Definition at line 47 of file url-inl.h.
Referenced by exercise_url_predicates().
|
nodiscard |
Returns the URL's port as a string (e.g., "8080"). Returns empty string if no port is set.
Definition at line 605 of file url.cpp.
Referenced by check_components_agree(), exercise_url_predicates(), and get_host().
|
nodiscard |
Returns the URL's scheme followed by a colon (e.g., "https:").
Definition at line 565 of file url.cpp.
References ada::url_base::is_special(), and ada::scheme::details::is_special_list.
Referenced by check_components_agree(), exercise_url_predicates(), get_components(), get_origin(), ada::parser::parse_url_impl(), and to_string().
|
nodiscard |
Returns the URL's query string prefixed with '?' (e.g., "?foo=bar"). Returns empty string if no query is set.
Definition at line 591 of file url.cpp.
Referenced by check_components_agree(), exercise_url_predicates(), and get_components().
|
nodiscardnoexcept |
Returns the URL's username component.
Definition at line 597 of file url.cpp.
Referenced by check_components_agree(), and exercise_url_predicates().
|
nodiscardnoexcept |
Checks if the URL has credentials (non-empty username or password).
Definition at line 25 of file url-inl.h.
References ada_really_inline.
Referenced by exercise_url_predicates(), get_components(), get_href(), get_href_size(), and to_string().
|
inlinenodiscardnoexcept |
Checks if the URL has an empty hostname (host is set but empty string).
Definition at line 34 of file url-inl.h.
Referenced by exercise_url_predicates().
|
nodiscardconstexproverridevirtualnoexcept |
Checks if the URL has a fragment/hash component.
Implements ada::url_base.
Definition at line 168 of file url-inl.h.
Referenced by exercise_url_predicates().
|
inlinenodiscardnoexcept |
Checks if the URL has a hostname (including empty hostnames).
Definition at line 40 of file url-inl.h.
Referenced by exercise_url_predicates().
|
inlinenodiscardnoexcept |
Checks if the URL has a non-default port explicitly specified.
Definition at line 28 of file url-inl.h.
References ada_really_inline.
Referenced by exercise_url_predicates().
|
nodiscardconstexproverridevirtualnoexcept |
Checks if the URL has a query/search component.
Implements ada::url_base.
Definition at line 172 of file url-inl.h.
Referenced by exercise_url_predicates(), and to_string().
|
nodiscardoverridevirtualnoexcept |
Validates whether the hostname is a valid domain according to RFC 1034. Checks that the domain and its labels have valid lengths (max 255 octets total, max 63 octets per label).
Implements ada::url_base.
Definition at line 532 of file url.cpp.
Referenced by exercise_url_predicates().
| void ada::url::set_hash | ( | std::string_view | input | ) |
Sets the URL's fragment/hash (the part after '#').
| input | The new hash value (with or without leading '#'). |
Definition at line 826 of file url.cpp.
References ada::character_sets::FRAGMENT_PERCENT_ENCODE, get_href_size(), and ada::get_max_input_length().
| bool ada::url::set_host | ( | std::string_view | input | ) |
Sets the URL's host (hostname and optionally port).
| input | The new host value (e.g., "example.com:8080"). |
| bool ada::url::set_hostname | ( | std::string_view | input | ) |
Sets the URL's hostname (without port).
| input | The new hostname value. |
| bool ada::url::set_href | ( | std::string_view | input | ) |
Replaces the entire URL by parsing a new href string.
| input | The new URL string to parse. |
Definition at line 916 of file url.cpp.
References ada::get_max_input_length(), and ada::parse().
| bool ada::url::set_password | ( | std::string_view | input | ) |
Sets the URL's password, percent-encoding special characters.
| input | The new password value. |
Definition at line 766 of file url.cpp.
References get_href_size(), ada::get_max_input_length(), set_password(), and ada::character_sets::USERINFO_PERCENT_ENCODE.
Referenced by set_password().
| bool ada::url::set_pathname | ( | std::string_view | input | ) |
Sets the URL's pathname.
| input | The new path value. |
Definition at line 866 of file url.cpp.
References get_href_size(), ada::get_max_input_length(), ada::url_base::has_opaque_path, and set_pathname().
Referenced by set_pathname().
| bool ada::url::set_port | ( | std::string_view | input | ) |
Sets the URL's port from a string (e.g., "8080").
| input | The port string. Empty string removes the port. |
Definition at line 783 of file url.cpp.
References get_href_size(), ada::get_max_input_length(), and ada::url_base::is_valid.
| bool ada::url::set_protocol | ( | std::string_view | input | ) |
Sets the URL's protocol/scheme.
| input | The new protocol (with or without trailing ':'). |
Definition at line 883 of file url.cpp.
References get_href_size(), ada::get_max_input_length(), and ada::checkers::is_alpha().
| void ada::url::set_search | ( | std::string_view | input | ) |
Sets the URL's query string (the part after '?').
| input | The new query value (with or without leading '?'). |
Definition at line 844 of file url.cpp.
References get_href_size(), ada::get_max_input_length(), ada::url_base::is_special(), ada::character_sets::QUERY_PERCENT_ENCODE, and ada::character_sets::SPECIAL_QUERY_PERCENT_ENCODE.
| bool ada::url::set_username | ( | std::string_view | input | ) |
Sets the URL's username, percent-encoding special characters.
| input | The new username value. |
Definition at line 749 of file url.cpp.
References get_href_size(), ada::get_max_input_length(), set_username(), and ada::character_sets::USERINFO_PERCENT_ENCODE.
Referenced by set_username().
|
nodiscardoverridevirtual |
Returns a JSON string representation of this URL for debugging.
Implements ada::url_base.
Definition at line 482 of file url.cpp.
References get_protocol(), has_credentials(), ada::url_base::has_opaque_path, has_search(), and ada::url_base::is_valid.
Referenced by exercise_url_predicates(), and ada::operator<<().
|
friend |
References ada::helpers::strip_trailing_spaces_from_opaque_path, and url().
Referenced by ada::helpers::strip_trailing_spaces_from_opaque_path.
|
friend |
References ada::parser::finish_simple_absolute_with_port.
Referenced by ada::parser::finish_simple_absolute_with_port.
|
friend |
References ada::parser::parse_url, and url().
Referenced by ada::parser::parse_url, and ada::parser::parse_url.
|
friend |
References ada::parser::parse_url.
|
friend |
References ada::parser::parse_url_impl, and url().
Referenced by ada::parser::parse_url_impl, and ada::parser::parse_url_impl.
|
friend |
References ada::parser::parse_url_impl.
|
friend |
References ada::parser::parse_url_impl.
|
friend |
References ada::parser::try_parse_simple_absolute.
Referenced by ada::parser::try_parse_simple_absolute.
|
friend |
References ada::parser::try_parse_simple_relative.
Referenced by ada::parser::try_parse_simple_relative.