LibURL/Pattern: Implement ability to generate a pattern string

Compiling a URLPattern component will generate a 'parts list' which
is used for generating the regular expression that is used for
matching against URLs.

This parts list is also used to generate (through this function) a
pattern string. The pattern string of a URL component is what is
exposed on the USVString getters of the URLPattern class itself.

As an example, the following:

```
let pattern = new URLPattern({ "pathname": "/foo/(.*)*" });
console.log(pattern.pathname);
```

Will log the pattern string of: '/foo/**'.
This commit is contained in:
Shannon Booth 2025-03-18 19:00:45 +13:00 committed by Tim Flynn
commit e3ef6d3aee
Notes: github-actions[bot] 2025-04-06 12:27:50 +00:00
2 changed files with 269 additions and 0 deletions

View file

@ -7,9 +7,17 @@
#pragma once
#include <AK/String.h>
#include <LibURL/Pattern/Options.h>
#include <LibURL/Pattern/Part.h>
namespace URL::Pattern {
// https://urlpattern.spec.whatwg.org/#full-wildcard-regexp-value
static inline constexpr auto full_wildcard_regexp_value = ".*"sv;
String escape_a_pattern_string(String const&);
String escape_a_regexp_string(String const&);
String generate_a_segment_wildcard_regexp(Options const&);
String generate_a_pattern_string(ReadonlySpan<Part>, Options const&);
}