|
Upa URL C++ library
A WHATWG URL Standard implementation
|
URL pattern class template. More...
#include <upa/urlpattern.h>
Public Member Functions | |
| urlpattern (const urlpattern_init &init={}, urlpattern_options opt={}) | |
| Constructs urlpattern object from upa::urlpattern_init object. | |
| template<class T, class TB, upa::enable_if_str_arg_t< T > = 0, upa::enable_if_optional_str_arg_t< TB > = 0> | |
| urlpattern (const T &input, TB &&base_url, urlpattern_options opt={}) | |
| Constructs urlpattern object from URL pattern string and optional base URL string. | |
| template<class T, upa::enable_if_str_arg_t< T > = 0> | |
| urlpattern (const T &input, urlpattern_options opt={}) | |
| Constructs urlpattern object from URL pattern string. | |
| bool | test (const urlpattern_init &input) const |
| Test whether URL pattern matches the input. | |
| template<class T, class TB = std::nullopt_t, upa::enable_if_str_arg_t< T > = 0, upa::enable_if_optional_str_arg_t< TB > = 0> | |
| bool | test (const T &input, const TB &base_url_str=upa::nullopt) const |
| Test whether URL pattern matches the input URL string. | |
| bool | test (const upa::url &url) const |
| Test whether URL pattern matches the URL. | |
| template<class ResT = urlpattern_result, std::enable_if_t< std::is_base_of_v< urlpattern_result, ResT >, int > = 0> | |
| std::optional< ResT > | exec (const urlpattern_init &input) const |
| Executes the URL pattern against the input. | |
| template<class ResT = urlpattern_result, class T, class TB = std::nullopt_t, std::enable_if_t< std::is_base_of_v< urlpattern_result, ResT >, int > = 0, upa::enable_if_str_arg_t< T > = 0, upa::enable_if_optional_str_arg_t< TB > = 0> | |
| std::optional< ResT > | exec (const T &input, const TB &base_url_str=upa::nullopt) const |
| Executes the URL pattern against the input URL string. | |
| template<class ResT = urlpattern_result, std::enable_if_t< std::is_base_of_v< urlpattern_result, ResT >, int > = 0> | |
| std::optional< ResT > | exec (const upa::url &url) const |
| Executes the URL pattern against the URL. | |
| std::string_view | get_protocol () const noexcept |
| std::string_view | get_username () const noexcept |
| std::string_view | get_password () const noexcept |
| std::string_view | get_hostname () const noexcept |
| std::string_view | get_port () const noexcept |
| std::string_view | get_pathname () const noexcept |
| std::string_view | get_search () const noexcept |
| std::string_view | get_hash () const noexcept |
| bool | has_regexp_groups () const noexcept |
URL pattern class template.
It implemebts URLPattern class as specified in WHATWG URL Pattern specification: https://urlpattern.spec.whatwg.org/#urlpattern-class
To use it you need provide regex engine type which meets requirements specified in the is_regex_engine_v trait. The library itself provides two regex engines:
We recommend using upa::regex_engine_srell as it is compliant with latest ECMAScript standard, and using it lets pass all URLPattern tests. It depends on SRELL library that can be obtained from https://www.akenotsuki.com/misc/srell/en/. The SRELL 4.066 or later version is required.
In simple cases, upa::regex_engine_std can be used. However, std::regex conforms to the modified ECMAScript regular expression grammar based on the old (year 2011) ECMAScript standard. Therefore, some URLPattern tests will fail if it is used.
Example:
| regex_engine | Regular expression engine type |
Definition at line 623 of file urlpattern.h.
|
inline |
Constructs urlpattern object from upa::urlpattern_init object.
The init is an object containing separate patterns for each URL component; e.g. hostname, pathname, etc. Missing components will default to a wildcard pattern. In addition, init can contain a base_url property that provides static text patterns for any missing components.
The optional opt parameter has the ignore_case property which can be set to true to enable case-insensitive matching. Note that by default, that is in the absence of the opt argument, matching is always case-sensitive.
This constructor throws an upa::urlpattern_error exception if the init contains an invalid data.
| [in] | init | upa::urlpattern_init object |
| [in] | opt | optional upa::urlpattern_options struct |
Definition at line 894 of file urlpattern.h.
|
inline |
Constructs urlpattern object from URL pattern string and optional base URL string.
The input is a URL string containing pattern syntax for one or more components. If base_url is provided, then input can be relative. This constructor will always set at least an empty string value and does not default any components to wildcard patterns.
The optional opt parameter has the ignore_case property which can be set to true to enable case-insensitive matching. Note that by default, that is in the absence of the opt argument, matching is always case-sensitive.
This constructor throws an upa::urlpattern_error exception if the input or base_url are invalid.
| [in] | input | URL pattern string |
| [in] | base_url | optional base URL string |
| [in] | opt | optional upa::urlpattern_options struct |
Definition at line 661 of file urlpattern.h.
|
inline |
Constructs urlpattern object from URL pattern string.
The input is a URL string containing pattern syntax for one or more components.
The optional opt parameter has the ignore_case property which can be set to true to enable case-insensitive matching. Note that by default, that is in the absence of the opt argument, matching is always case-sensitive.
This constructor throws an upa::urlpattern_error exception if the input is invalid.
| [in] | input | URL pattern string |
| [in] | opt | optional upa::urlpattern_options struct |
Definition at line 677 of file urlpattern.h.
|
inlinenodiscard |
Executes the URL pattern against the input URL string.
If base_url_str is provided, then input URL string can be relative.
If URL pattern matches the input on a component-by-component basis then an object of type ResT is returned containing the results. Matched group values are contained in per-component group objects within the result object; e.g. res->pathname.groups["id"].
By default, the ResT result type is upa::urlpattern_result.
| ResT | Result type, must be derived from upa::urlpattern_result |
| [in] | input | URL string to match against URL pattern |
| [in] | base_url_str | optional base URL string |
Definition at line 1077 of file urlpattern.h.
|
inlinenodiscard |
Executes the URL pattern against the URL.
If URL pattern matches the url on a component-by-component basis then an object of type ResT is returned containing the results. Matched group values are contained in per-component group objects within the result object; e.g. res->pathname.groups["id"].
By default, the ResT result type is upa::urlpattern_result.
| ResT | Result type, must be derived from upa::urlpattern_result |
| [in] | url | URL to test |
Definition at line 1104 of file urlpattern.h.
|
inlinenodiscard |
Executes the URL pattern against the input.
The input is an object containing strings representing each URL component; e.g. hostname, pathname, etc. Missing components are treated as empty strings. In addition, input can contain a base_url property that provides values for any missing components.
If URL pattern matches the input on a component-by-component basis then an object of type ResT is returned containing the results. Matched group values are contained in per-component group objects within the result object; e.g. res->pathname.groups["id"].
By default, the result type is upa::urlpattern_result. It does not contain inputs field. If you need to have inputs field in the result, you can use upa::urlpattern_result_and_inputs as the result type. For example:
| ResT | Result type, must be derived from upa::urlpattern_result |
| [in] | input | upa::urlpattern_init object |
Definition at line 1052 of file urlpattern.h.
|
inlinenodiscardnoexcept |
Definition at line 986 of file urlpattern.h.
|
inlinenodiscardnoexcept |
Definition at line 970 of file urlpattern.h.
|
inlinenodiscardnoexcept |
Definition at line 966 of file urlpattern.h.
|
inlinenodiscardnoexcept |
Definition at line 978 of file urlpattern.h.
|
inlinenodiscardnoexcept |
Definition at line 974 of file urlpattern.h.
|
inlinenodiscardnoexcept |
Definition at line 958 of file urlpattern.h.
|
inlinenodiscardnoexcept |
Definition at line 982 of file urlpattern.h.
|
inlinenodiscardnoexcept |
Definition at line 962 of file urlpattern.h.
|
nodiscardnoexcept |
Definition at line 1209 of file urlpattern.h.
|
inlinenodiscard |
Test whether URL pattern matches the input URL string.
If base_url_str is provided, then input URL string can be relative.
| [in] | input | URL string to test |
| [in] | base_url_str | optional base URL string |
Definition at line 1010 of file urlpattern.h.
|
inlinenodiscard |
Test whether URL pattern matches the URL.
| [in] | url | URL to test |
Definition at line 1015 of file urlpattern.h.
|
inlinenodiscard |
Test whether URL pattern matches the input.
The input is an object containing strings representing each URL component; e.g. hostname, pathname, etc. Missing components are treated as empty strings. In addition, input can contain a base_url property that provides values for any missing components.
| [in] | input | upa::urlpattern_init object |
Definition at line 994 of file urlpattern.h.