From dc2c62825be834cbd3b9c238cb6287d2b573c031 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 13 Jan 2025 22:24:18 +1300 Subject: [PATCH] LibURL: Add a representation of a URL Pattern 'result' This is the return value of a URLPattern after `exec` is called on it. It conveys information about the named (or unammed) regex groups matched for each component of the URL. For example, ``` let p = new URLPattern({ hostname: "{:subdomain.}*example.com" }); const result = pattern.exec({ hostname: "foo.bar.example.com" }); console.log(result.hostname.groups.subdomain); ``` Will log 'foo.bar'. --- Libraries/LibURL/Pattern/Pattern.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Libraries/LibURL/Pattern/Pattern.h b/Libraries/LibURL/Pattern/Pattern.h index 7378517a920..8b367849856 100644 --- a/Libraries/LibURL/Pattern/Pattern.h +++ b/Libraries/LibURL/Pattern/Pattern.h @@ -6,7 +6,10 @@ #pragma once +#include +#include #include +#include #include namespace URL::Pattern { @@ -19,4 +22,24 @@ struct Options { bool ignore_case { false }; }; +// https://urlpattern.spec.whatwg.org/#dictdef-urlpatterncomponentresult +struct ComponentResult { + String input; + OrderedHashMap> groups; +}; + +// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternresult +struct Result { + Vector inputs; + + ComponentResult protocol; + ComponentResult username; + ComponentResult password; + ComponentResult hostname; + ComponentResult port; + ComponentResult pathname; + ComponentResult search; + ComponentResult hash; +}; + }