@@ -57,7 +57,7 @@ struct NumberFormat : public Unicode::NumberFormat {
57
57
StringIndexType zero_format_index { 0 };
58
58
StringIndexType positive_format_index { 0 };
59
59
StringIndexType negative_format_index { 0 };
60
- StringIndexType compact_identifier_index { 0 };
60
+ StringIndexType identifier_index { 0 };
61
61
};
62
62
63
63
struct NumberSystem {
@@ -90,6 +90,46 @@ struct UnicodeLocaleData {
90
90
Vector<String> numeric_symbols;
91
91
};
92
92
93
+ static String parse_identifier (String pattern, StringView replacement, UnicodeLocaleData& locale_data, NumberFormat& format)
94
+ {
95
+ static Utf8View whitespace { " \u0020\u00a0 " sv };
96
+
97
+ Utf8View utf8_pattern { pattern };
98
+ Optional<size_t > start_index;
99
+ Optional<size_t > end_index;
100
+ bool inside_replacement = false ;
101
+
102
+ for (auto it = utf8_pattern.begin (); it != utf8_pattern.end (); ++it) {
103
+ if (*it == ' {' ) {
104
+ if (start_index.has_value ()) {
105
+ end_index = utf8_pattern.byte_offset_of (it);
106
+ break ;
107
+ }
108
+
109
+ inside_replacement = true ;
110
+ } else if (*it == ' }' ) {
111
+ inside_replacement = false ;
112
+ } else if (!inside_replacement && !start_index.has_value () && !whitespace.contains (*it)) {
113
+ start_index = utf8_pattern.byte_offset_of (it);
114
+ }
115
+ }
116
+
117
+ if (!start_index.has_value ())
118
+ return pattern;
119
+ end_index = end_index.value_or (pattern.length ());
120
+
121
+ utf8_pattern = utf8_pattern.substring_view (*start_index, *end_index - *start_index);
122
+ utf8_pattern = utf8_pattern.trim (whitespace);
123
+
124
+ auto identifier = utf8_pattern.as_string ().replace (" '.'" sv, " ." sv);
125
+ format.identifier_index = locale_data.unique_strings .ensure (move (identifier));
126
+
127
+ return String::formatted (" {}{}{}" ,
128
+ *start_index > 0 ? pattern.substring_view (0 , *start_index) : " " sv,
129
+ replacement,
130
+ pattern.substring_view (*start_index + utf8_pattern.byte_length ()));
131
+ }
132
+
93
133
static void parse_number_pattern (Vector<String> patterns, UnicodeLocaleData& locale_data, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr )
94
134
{
95
135
// https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
@@ -147,40 +187,8 @@ static void parse_number_pattern(Vector<String> patterns, UnicodeLocaleData& loc
147
187
pattern = pattern.replace (" 0" sv, " {scientificExponent}" sv);
148
188
}
149
189
150
- if (type == NumberFormatType::Compact) {
151
- static Utf8View whitespace { " \u0020\u00a0 " sv };
152
-
153
- Utf8View utf8_pattern { pattern };
154
- Optional<size_t > start_compact_index;
155
- Optional<size_t > end_compact_index;
156
- bool inside_replacement = false ;
157
-
158
- for (auto it = utf8_pattern.begin (); it != utf8_pattern.end (); ++it) {
159
- if (*it == ' {' ) {
160
- if (start_compact_index.has_value ()) {
161
- end_compact_index = utf8_pattern.byte_offset_of (it);
162
- break ;
163
- }
164
-
165
- inside_replacement = true ;
166
- } else if (*it == ' }' ) {
167
- inside_replacement = false ;
168
- } else if (!inside_replacement && !start_compact_index.has_value () && !whitespace.contains (*it)) {
169
- start_compact_index = utf8_pattern.byte_offset_of (it);
170
- }
171
- }
172
-
173
- if (!start_compact_index.has_value ())
174
- return pattern;
175
-
176
- utf8_pattern = utf8_pattern.substring_view (*start_compact_index, end_compact_index.value_or (pattern.length ()) - *start_compact_index);
177
- utf8_pattern = utf8_pattern.trim (whitespace);
178
-
179
- auto identifier = utf8_pattern.as_string ().replace (" '.'" sv, " ." sv);
180
- format.compact_identifier_index = locale_data.unique_strings .ensure (move (identifier));
181
-
182
- pattern = pattern.replace (utf8_pattern.as_string (), " {compactIdentifier}" );
183
- }
190
+ if (type == NumberFormatType::Compact)
191
+ return parse_identifier (move (pattern), " {compactIdentifier}" sv, locale_data, format);
184
192
185
193
return pattern;
186
194
};
@@ -429,7 +437,7 @@ struct NumberFormat {
429
437
number_format.zero_format = s_string_list[zero_format];
430
438
number_format.positive_format = s_string_list[positive_format];
431
439
number_format.negative_format = s_string_list[negative_format];
432
- number_format.compact_identifier = s_string_list[compact_identifier ];
440
+ number_format.identifier = s_string_list[identifier ];
433
441
434
442
return number_format;
435
443
}
@@ -440,7 +448,7 @@ struct NumberFormat {
440
448
@string_index_type@ zero_format { 0 };
441
449
@string_index_type@ positive_format { 0 };
442
450
@string_index_type@ negative_format { 0 };
443
- @string_index_type@ compact_identifier { 0 };
451
+ @string_index_type@ identifier { 0 };
444
452
};
445
453
446
454
struct NumberSystem {
@@ -471,8 +479,8 @@ struct NumberSystem {
471
479
generator.set (" zero_format" sv, String::number (number_format.zero_format_index ));
472
480
generator.set (" positive_format" sv, String::number (number_format.positive_format_index ));
473
481
generator.set (" negative_format" sv, String::number (number_format.negative_format_index ));
474
- generator.set (" compact_identifier " sv, String::number (number_format.compact_identifier_index ));
475
- generator.append (" { @magnitude@, @exponent@, @plurality@, @zero_format@, @positive_format@, @negative_format@, @compact_identifier @ }," );
482
+ generator.set (" identifier " sv, String::number (number_format.identifier_index ));
483
+ generator.append (" { @magnitude@, @exponent@, @plurality@, @zero_format@, @positive_format@, @negative_format@, @identifier @ }," );
476
484
};
477
485
478
486
auto append_number_formats = [&](String name, auto const & number_formats) {
0 commit comments