LibJS: Move PatternPartitionWithSource structure to AbstractOperations.h

This struct will be needed by more than just the DateTimeFormat object.
Also add an equality operator, which will be needed by NumberFormat.
This commit is contained in:
Timothy Flynn 2022-07-20 13:57:04 -04:00 committed by Linus Groh
parent 0a6363d3e9
commit 7c490d4da3
Notes: sideshowbarker 2024-07-17 08:44:17 +09:00
2 changed files with 24 additions and 19 deletions

View file

@ -53,6 +53,30 @@ struct PatternPartition {
String value;
};
struct PatternPartitionWithSource : public PatternPartition {
static Vector<PatternPartitionWithSource> create_from_parent_list(Vector<PatternPartition> 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.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;
};
// Table 2: Single units sanctioned for use in ECMAScript, https://tc39.es/ecma402/#table-sanctioned-single-unit-identifiers
constexpr auto sanctioned_single_unit_identifiers()
{

View file

@ -180,25 +180,6 @@ struct LocalTime {
u16 millisecond { 0 }; // [[Millisecond]]
};
struct PatternPartitionWithSource : public PatternPartition {
static Vector<PatternPartitionWithSource> create_from_parent_list(Vector<PatternPartition> 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.append(move(partition_with_source));
}
return result;
}
StringView source;
};
ThrowCompletionOr<Object*> to_date_time_options(GlobalObject& global_object, Value options_value, OptionRequired, OptionDefaults);
Optional<Unicode::CalendarPattern> date_time_style_format(StringView data_locale, DateTimeFormat& date_time_format);
Optional<Unicode::CalendarPattern> basic_format_matcher(Unicode::CalendarPattern const& options, Vector<Unicode::CalendarPattern> formats);