|
Ada 3.4.3
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 |
| 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 noexcept |
| 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 *) |
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 |
|
nodiscardnoexcept |
Returns the URL component offsets for efficient serialization.
The components represent byte offsets into the serialized URL:
Definition at line 50 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.
|
nodiscard |
Returns the URL's fragment prefixed with '#' (e.g., "#section"). Returns empty string if no fragment is set.
|
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 641 of file url.cpp.
References get_port().
Referenced by get_origin().
|
nodiscard |
Returns the URL's hostname (without port). Returns empty string if no host is set.
Definition at line 655 of file url.cpp.
Referenced by ada::parser::parse_url_impl().
|
nodiscard |
Returns the full serialized URL (the href).
Definition at line 188 of file url-inl.h.
References ada_really_inline, get_password(), get_port(), get_protocol(), has_credentials(), and ada::url_base::has_opaque_path.
Referenced by ada::parser::parse_url_impl().
|
nodiscardoverridevirtual |
Returns the URL's origin as a string (scheme + host + port for special URLs).
Implements ada::url_base.
Definition at line 607 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().
|
nodiscardnoexcept |
Returns the URL's password component.
Definition at line 670 of file url.cpp.
Referenced by get_href().
|
nodiscardconstexprnoexcept |
Returns the URL's path component.
Definition at line 46 of file url-inl.h.
Referenced by ada::parser::parse_url_impl().
|
nodiscardnoexcept |
Returns the byte length of the pathname without creating a string.
|
nodiscard |
Returns the URL's port as a string (e.g., "8080"). Returns empty string if no port is set.
Definition at line 674 of file url.cpp.
Referenced by get_host(), and get_href().
|
nodiscard |
Returns the URL's scheme followed by a colon (e.g., "https:").
Definition at line 633 of file url.cpp.
References ada::url_base::is_special(), and ada::scheme::details::is_special_list.
Referenced by get_components(), get_href(), 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 659 of file url.cpp.
Referenced by get_components().
|
nodiscardnoexcept |
Returns the URL's username component.
|
nodiscardnoexcept |
Checks if the URL has credentials (non-empty username or password).
Definition at line 19 of file url-inl.h.
References ada_really_inline.
Referenced by get_components(), get_href(), and to_string().
|
inlinenodiscardnoexcept |
|
nodiscardconstexproverridevirtualnoexcept |
Checks if the URL has a fragment/hash component.
Implements ada::url_base.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Checks if the URL has a non-default port explicitly specified.
Definition at line 22 of file url-inl.h.
References ada_really_inline.
|
nodiscardconstexproverridevirtualnoexcept |
Checks if the URL has a query/search component.
Implements ada::url_base.
Definition at line 164 of file url-inl.h.
Referenced by 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.
| 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 864 of file url.cpp.
References ada::character_sets::FRAGMENT_PERCENT_ENCODE.
| 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 929 of file url.cpp.
References 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 816 of file url.cpp.
References ada::character_sets::USERINFO_PERCENT_ENCODE.
| bool ada::url::set_pathname | ( | std::string_view | input | ) |
Sets the URL's pathname.
| input | The new path value. |
Definition at line 896 of file url.cpp.
References ada::url_base::has_opaque_path.
| 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 825 of file url.cpp.
References 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 905 of file url.cpp.
References 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 878 of file url.cpp.
References 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 807 of file url.cpp.
References ada::character_sets::USERINFO_PERCENT_ENCODE.
|
nodiscardoverridevirtual |
Returns a JSON string representation of this URL for debugging.
Implements ada::url_base.
Definition at line 550 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 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::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.