mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibJS: Remove unused PartitionPattern AO and related types
And move some headers around that are no longer needed in the AO header.
This commit is contained in:
parent
638a6c8c00
commit
1c51ac4763
Notes:
sideshowbarker
2024-07-16 21:39:23 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/1c51ac4763 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/193
4 changed files with 5 additions and 103 deletions
|
@ -5,16 +5,16 @@
|
|||
*/
|
||||
|
||||
#include <AK/AllOf.h>
|
||||
#include <AK/AnyOf.h>
|
||||
#include <AK/CharacterTypes.h>
|
||||
#include <AK/Find.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Intl/Locale.h>
|
||||
#include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibJS/Runtime/ValueInlines.h>
|
||||
#include <LibLocale/Locale.h>
|
||||
#include <LibLocale/UnicodeKeywords.h>
|
||||
|
@ -685,63 +685,4 @@ ThrowCompletionOr<Optional<int>> 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<PatternPartition> partition_pattern(StringView pattern)
|
||||
{
|
||||
// 1. Let result be a new empty List.
|
||||
Vector<PatternPartition> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,7 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Intl/DisplayNames.h>
|
||||
#include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
|
||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibLocale/Forward.h>
|
||||
|
||||
|
@ -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<typename ParentList>
|
||||
static Vector<PatternPartitionWithSource> create_from_parent_list(ParentList partitions)
|
||||
{
|
||||
Vector<PatternPartitionWithSource> 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<StringView, bool>;
|
||||
|
||||
bool is_structurally_valid_language_tag(StringView locale);
|
||||
|
@ -98,7 +57,6 @@ ThrowCompletionOr<Object*> coerce_options_to_object(VM&, Value options);
|
|||
ThrowCompletionOr<StringOrBoolean> get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, ReadonlySpan<StringView> string_values, StringOrBoolean fallback);
|
||||
ThrowCompletionOr<Optional<int>> default_number_option(VM&, Value value, int minimum, int maximum, Optional<int> fallback);
|
||||
ThrowCompletionOr<Optional<int>> get_number_option(VM&, Object const& options, PropertyKey const& property, int minimum, int maximum, Optional<int> fallback);
|
||||
Vector<PatternPartition> partition_pattern(StringView pattern);
|
||||
|
||||
template<size_t Size>
|
||||
ThrowCompletionOr<StringOrBoolean> get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, StringView const (&string_values)[Size], StringOrBoolean fallback)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/Temporal/Duration.h>
|
||||
#include <LibLocale/Locale.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
#include <LibJS/Runtime/Intl/PluralRulesConstructor.h>
|
||||
#include <LibJS/Runtime/Intl/RelativeTimeFormatConstructor.h>
|
||||
#include <LibJS/Runtime/Intl/SegmenterConstructor.h>
|
||||
#include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
|
||||
#include <LibJS/Runtime/Temporal/TimeZone.h>
|
||||
#include <LibLocale/DateTimeFormat.h>
|
||||
#include <LibLocale/Locale.h>
|
||||
#include <LibLocale/NumberFormat.h>
|
||||
#include <LibLocale/UnicodeKeywords.h>
|
||||
#include <LibTimeZone/TimeZone.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
|
|
Loading…
Reference in a new issue