mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
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:
parent
d873dc0744
commit
dc2c62825b
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user