Browse Source

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.
Timothy Flynn 3 years ago
parent
commit
7c490d4da3

+ 24 - 0
Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h

@@ -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()
 {

+ 0 - 19
Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h

@@ -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);