2025-02-03 22:56:14 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
LibRegex: Add ECMAScriptRegex and migrate callers
Add `ECMAScriptRegex`, LibRegex's C++ facade for ECMAScript regexes.
The facade owns compilation, execution, captures, named groups, and
error translation for the Rust backend, which lets callers stop
depending on the legacy parser and matcher types directly. Use it in the
remaining non-LibJS callers: URLPattern, HTML input pattern handling,
and the places in LibHTTP that only needed token validation.
Where a full regex engine was unnecessary, replace those call sites with
direct character checks. Also update focused LibURL, LibHTTP, and WPT
coverage for the migrated callers and corrected surrogate handling.
2026-03-25 06:52:20 -03:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
#include <AK/Optional.h>
|
2025-02-03 22:56:14 -03:00
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
|
#include <AK/String.h>
|
LibRegex: Add ECMAScriptRegex and migrate callers
Add `ECMAScriptRegex`, LibRegex's C++ facade for ECMAScript regexes.
The facade owns compilation, execution, captures, named groups, and
error translation for the Rust backend, which lets callers stop
depending on the legacy parser and matcher types directly. Use it in the
remaining non-LibJS callers: URLPattern, HTML input pattern handling,
and the places in LibHTTP that only needed token validation.
Where a full regex engine was unnecessary, replace those call sites with
direct character checks. Also update focused LibURL, LibHTTP, and WPT
coverage for the migrated callers and corrected surrogate handling.
2026-03-25 06:52:20 -03:00
|
|
|
#include <LibRegex/ECMAScriptRegex.h>
|
2025-03-18 03:34:25 -03:00
|
|
|
#include <LibURL/Pattern/PatternParser.h>
|
2025-02-03 22:56:14 -03:00
|
|
|
|
|
|
|
|
namespace URL::Pattern {
|
|
|
|
|
|
|
|
|
|
// https://urlpattern.spec.whatwg.org/#component
|
|
|
|
|
struct Component {
|
2025-03-18 03:45:08 -03:00
|
|
|
static PatternErrorOr<Component> compile(Utf8View const& input, PatternParser::EncodingCallback, Options const&);
|
|
|
|
|
|
|
|
|
|
// https://urlpattern.spec.whatwg.org/#dictdef-urlpatterncomponentresult
|
|
|
|
|
struct Result {
|
|
|
|
|
String input;
|
|
|
|
|
OrderedHashMap<String, Variant<String, Empty>> groups;
|
|
|
|
|
};
|
|
|
|
|
|
LibRegex: Add ECMAScriptRegex and migrate callers
Add `ECMAScriptRegex`, LibRegex's C++ facade for ECMAScript regexes.
The facade owns compilation, execution, captures, named groups, and
error translation for the Rust backend, which lets callers stop
depending on the legacy parser and matcher types directly. Use it in the
remaining non-LibJS callers: URLPattern, HTML input pattern handling,
and the places in LibHTTP that only needed token validation.
Where a full regex engine was unnecessary, replace those call sites with
direct character checks. Also update focused LibURL, LibHTTP, and WPT
coverage for the migrated callers and corrected surrogate handling.
2026-03-25 06:52:20 -03:00
|
|
|
struct ExecutionResult {
|
|
|
|
|
bool success { false };
|
|
|
|
|
Vector<Optional<String>> captures;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Result create_match_result(String const& input, ExecutionResult const& exec_result) const;
|
|
|
|
|
ExecutionResult execute(String const& input) const;
|
|
|
|
|
bool matches(StringView input) const;
|
2025-03-18 03:45:08 -03:00
|
|
|
|
2025-02-03 22:56:14 -03:00
|
|
|
// https://urlpattern.spec.whatwg.org/#component-pattern-string
|
|
|
|
|
// pattern string, a well formed pattern string
|
|
|
|
|
String pattern_string;
|
|
|
|
|
|
|
|
|
|
// https://urlpattern.spec.whatwg.org/#component-regular-expression
|
|
|
|
|
// regular expression, a RegExp
|
LibRegex: Add ECMAScriptRegex and migrate callers
Add `ECMAScriptRegex`, LibRegex's C++ facade for ECMAScript regexes.
The facade owns compilation, execution, captures, named groups, and
error translation for the Rust backend, which lets callers stop
depending on the legacy parser and matcher types directly. Use it in the
remaining non-LibJS callers: URLPattern, HTML input pattern handling,
and the places in LibHTTP that only needed token validation.
Where a full regex engine was unnecessary, replace those call sites with
direct character checks. Also update focused LibURL, LibHTTP, and WPT
coverage for the migrated callers and corrected surrogate handling.
2026-03-25 06:52:20 -03:00
|
|
|
OwnPtr<regex::ECMAScriptRegex> regular_expression;
|
2025-02-03 22:56:14 -03:00
|
|
|
|
|
|
|
|
// https://urlpattern.spec.whatwg.org/#component-group-name-list
|
|
|
|
|
// group name list, a list of strings
|
|
|
|
|
Vector<String> group_name_list;
|
|
|
|
|
|
|
|
|
|
// https://urlpattern.spec.whatwg.org/#component-has-regexp-groups
|
|
|
|
|
// has regexp groups, a boolean
|
|
|
|
|
bool has_regexp_groups {};
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-18 03:36:35 -03:00
|
|
|
bool protocol_component_matches_a_special_scheme(Component const& protocol_component);
|
|
|
|
|
|
2025-02-03 22:56:14 -03:00
|
|
|
}
|