diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp index b56fd660b2a..2518814fbbf 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp @@ -5,16 +5,16 @@ */ #include -#include #include #include -#include #include #include #include #include #include #include +#include +#include #include #include #include @@ -685,63 +685,4 @@ ThrowCompletionOr> get_number_option(VM& vm, Object const& options return default_number_option(vm, value, minimum, maximum, move(fallback)); } -// 9.2.17 PartitionPattern ( pattern ), https://tc39.es/ecma402/#sec-partitionpattern -Vector partition_pattern(StringView pattern) -{ - // 1. Let result be a new empty List. - Vector result; - - // 2. Let beginIndex be StringIndexOf(pattern, "{", 0). - auto begin_index = pattern.find('{', 0); - - // 3. Let endIndex be 0. - size_t end_index = 0; - - // 4. Let nextIndex be 0. - size_t next_index = 0; - - // 5. Let length be the number of code units in pattern. - // 6. Repeat, while beginIndex is an integer index into pattern, - while (begin_index.has_value()) { - // a. Set endIndex to StringIndexOf(pattern, "}", beginIndex). - end_index = pattern.find('}', *begin_index).value(); - - // b. Assert: endIndex is greater than beginIndex. - VERIFY(end_index > *begin_index); - - // c. If beginIndex is greater than nextIndex, then - if (*begin_index > next_index) { - // i. Let literal be a substring of pattern from position nextIndex, inclusive, to position beginIndex, exclusive. - auto literal = pattern.substring_view(next_index, *begin_index - next_index); - - // ii. Append a new Record { [[Type]]: "literal", [[Value]]: literal } as the last element of the list result. - result.append({ "literal"sv, MUST(String::from_utf8(literal)) }); - } - - // d. Let p be the substring of pattern from position beginIndex, exclusive, to position endIndex, exclusive. - auto partition = pattern.substring_view(*begin_index + 1, end_index - *begin_index - 1); - - // e. Append a new Record { [[Type]]: p, [[Value]]: undefined } as the last element of the list result. - result.append({ partition, {} }); - - // f. Set nextIndex to endIndex + 1. - next_index = end_index + 1; - - // g. Set beginIndex to StringIndexOf(pattern, "{", nextIndex). - begin_index = pattern.find('{', next_index); - } - - // 7. If nextIndex is less than length, then - if (next_index < pattern.length()) { - // a. Let literal be the substring of pattern from position nextIndex, inclusive, to position length, exclusive. - auto literal = pattern.substring_view(next_index); - - // b. Append a new Record { [[Type]]: "literal", [[Value]]: literal } as the last element of the list result. - result.append({ "literal"sv, MUST(String::from_utf8(literal)) }); - } - - // 8. Return result. - return result; -} - } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h index 71998734d61..43f20e25440 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h @@ -12,10 +12,7 @@ #include #include #include -#include -#include #include -#include #include #include @@ -45,44 +42,6 @@ struct LocaleResult { LocaleKey nu; // [[NumberingSystem]] }; -struct PatternPartition { - PatternPartition() = default; - - PatternPartition(StringView type_string, String value_string) - : type(type_string) - , value(move(value_string)) - { - } - - StringView type; - String value; -}; - -struct PatternPartitionWithSource : public PatternPartition { - template - static Vector create_from_parent_list(ParentList partitions) - { - Vector result; - result.ensure_capacity(partitions.size()); - - for (auto& partition : partitions) { - PatternPartitionWithSource partition_with_source {}; - partition_with_source.type = partition.type; - partition_with_source.value = move(partition.value); - result.unchecked_append(move(partition_with_source)); - } - - return result; - } - - bool operator==(PatternPartitionWithSource const& other) const - { - return (type == other.type) && (value == other.value) && (source == other.source); - } - - StringView source; -}; - using StringOrBoolean = Variant; bool is_structurally_valid_language_tag(StringView locale); @@ -98,7 +57,6 @@ ThrowCompletionOr coerce_options_to_object(VM&, Value options); ThrowCompletionOr get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, ReadonlySpan string_values, StringOrBoolean fallback); ThrowCompletionOr> default_number_option(VM&, Value value, int minimum, int maximum, Optional fallback); ThrowCompletionOr> get_number_option(VM&, Object const& options, PropertyKey const& property, int minimum, int maximum, Optional fallback); -Vector partition_pattern(StringView pattern); template ThrowCompletionOr get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, StringView const (&string_values)[Size], StringOrBoolean fallback) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h index 1d994ee5317..622432225e3 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace JS::Intl { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp index 4ba47eb587e..fb369cf48f3 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp @@ -19,11 +19,13 @@ #include #include #include +#include #include #include #include #include #include +#include namespace JS::Intl {