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(); +}; +; + +}