From ea84c77b30fe33be69dc942be53faf33f9dddfa0 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 17 Mar 2025 16:25:50 +1300 Subject: [PATCH] LibURL/Pattern: Add representation of a URL Pattern 'options' struct These control how a pattern string is generated, which can vary for different components and is also impacted by the 'ignoreCase' option that can be provided in the URLPattern constructor. --- Libraries/LibURL/CMakeLists.txt | 1 + Libraries/LibURL/Pattern/Options.cpp | 41 ++++++++++++++++++++++++++++ Libraries/LibURL/Pattern/Options.h | 30 ++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 Libraries/LibURL/Pattern/Options.cpp create mode 100644 Libraries/LibURL/Pattern/Options.h diff --git a/Libraries/LibURL/CMakeLists.txt b/Libraries/LibURL/CMakeLists.txt index 2341cf265d2..3c097378f8d 100644 --- a/Libraries/LibURL/CMakeLists.txt +++ b/Libraries/LibURL/CMakeLists.txt @@ -10,6 +10,7 @@ set(SOURCES Pattern/Canonicalization.cpp Pattern/ConstructorStringParser.cpp Pattern/Init.cpp + Pattern/Options.cpp Pattern/Part.cpp Pattern/Pattern.cpp Pattern/String.cpp diff --git a/Libraries/LibURL/Pattern/Options.cpp b/Libraries/LibURL/Pattern/Options.cpp new file mode 100644 index 00000000000..dbeabc756e7 --- /dev/null +++ b/Libraries/LibURL/Pattern/Options.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace URL::Pattern { + +// https://urlpattern.spec.whatwg.org/#default-options +Options Options::default_() +{ + // The default options is an options struct with delimiter code point set to the empty string and prefix code point set to the empty string. + return { + .delimiter_code_point = {}, + .prefix_code_point = {}, + }; +} + +// https://urlpattern.spec.whatwg.org/#hostname-options +Options Options::hostname() +{ + // The hostname options is an options struct with delimiter code point set "." and prefix code point set to the empty string. + return { + .delimiter_code_point = '.', + .prefix_code_point = {}, + }; +} + +// https://urlpattern.spec.whatwg.org/#pathname-options +Options Options::pathname() +{ + // The pathname options is an options struct with delimiter code point set "/" and prefix code point set to "/". + return { + .delimiter_code_point = '/', + .prefix_code_point = '/', + }; +} + +} diff --git a/Libraries/LibURL/Pattern/Options.h b/Libraries/LibURL/Pattern/Options.h new file mode 100644 index 00000000000..47e2e4e695b --- /dev/null +++ b/Libraries/LibURL/Pattern/Options.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace URL::Pattern { + +// https://urlpattern.spec.whatwg.org/#options +struct Options { + // https://urlpattern.spec.whatwg.org/#options-delimiter-code-point + Optional delimiter_code_point; + + // https://urlpattern.spec.whatwg.org/#options-prefix-code-point + Optional prefix_code_point; + + // https://urlpattern.spec.whatwg.org/#options-ignore-case + bool ignore_case { false }; + + static Options default_(); + static Options hostname(); + static Options pathname(); +}; +; + +}