LibURL/Pattern: Add a representation of a URL Pattern

This is the core object behind a URL pattern which when constructed
can be used for matching the pattern against URLs.

However, the implementation here is missing key functions such as
the constructor and the 'test'/'exec' functions as that relies on
a significant amount of supporting URLPattern infrastructure such
as two different parsers and a tokenizer.

However, this is enough for us to implement some more of the IDL
wrapper layer of this specification.
This commit is contained in:
Shannon Booth 2025-02-04 15:10:14 +13:00 committed by Tim Flynn
commit f3662c6f88
Notes: github-actions[bot] 2025-02-18 00:11:40 +00:00
3 changed files with 100 additions and 0 deletions

View file

@ -10,6 +10,7 @@
#include <AK/String.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
#include <LibURL/Pattern/Component.h>
#include <LibURL/Pattern/Init.h>
namespace URL::Pattern {
@ -42,4 +43,52 @@ struct Result {
ComponentResult hash;
};
// https://urlpattern.spec.whatwg.org/#url-pattern
class Pattern {
public:
bool has_regexp_groups() const;
Component const& protocol_component() const { return m_protocol_component; }
Component const& username_component() const { return m_username_component; }
Component const& password_component() const { return m_password_component; }
Component const& hostname_component() const { return m_hostname_component; }
Component const& port_component() const { return m_port_component; }
Component const& pathname_component() const { return m_pathname_component; }
Component const& search_component() const { return m_search_component; }
Component const& hash_component() const { return m_hash_component; }
private:
// https://urlpattern.spec.whatwg.org/#url-pattern-protocol-component
// protocol component, a component
Component m_protocol_component;
// https://urlpattern.spec.whatwg.org/#url-pattern-username-component
// username component, a component
Component m_username_component;
// https://urlpattern.spec.whatwg.org/#url-pattern-password-component
// password component, a component
Component m_password_component;
// https://urlpattern.spec.whatwg.org/#url-pattern-hostname-component
// hostname component, a component
Component m_hostname_component;
// https://urlpattern.spec.whatwg.org/#url-pattern-port-component
// port component, a component
Component m_port_component;
// https://urlpattern.spec.whatwg.org/#url-pattern-pathname-component
// pathname component, a component
Component m_pathname_component;
// https://urlpattern.spec.whatwg.org/#url-pattern-search-component
// search component, a component
Component m_search_component;
// https://urlpattern.spec.whatwg.org/#url-pattern-hash-component
// hash component, a component
Component m_hash_component;
};
}