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'.
This commit is contained in:
Shannon Booth 2025-01-13 22:24:18 +13:00 committed by Tim Ledbetter
commit dc2c62825b
Notes: github-actions[bot] 2025-02-10 17:06:41 +00:00

View file

@ -6,7 +6,10 @@
#pragma once
#include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
#include <LibURL/Pattern/Init.h>
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<String, Variant<String, Empty>> groups;
};
// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternresult
struct Result {
Vector<Input> inputs;
ComponentResult protocol;
ComponentResult username;
ComponentResult password;
ComponentResult hostname;
ComponentResult port;
ComponentResult pathname;
ComponentResult search;
ComponentResult hash;
};
}