Skip to content

Commit 4317a1b

Browse files
trflynn89linusg
authored andcommitted
LibUnicode: Parse and generate compact currency formatting rules
1 parent 604a596 commit 4317a1b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct NumberSystem {
5656
HashMap<String, StringIndexType> symbols {};
5757
Vector<NumberFormat> decimal_long_formats {};
5858
Vector<NumberFormat> decimal_short_formats {};
59+
Vector<NumberFormat> currency_short_formats {};
5960
};
6061

6162
struct ListPatterns {
@@ -556,6 +557,7 @@ static void parse_number_systems(String locale_numbers_path, UnicodeLocaleData&
556557
locale_numbers_object.as_object().for_each_member([&](auto const& key, JsonValue const& value) {
557558
constexpr auto symbols_prefix = "symbols-numberSystem-"sv;
558559
constexpr auto decimal_formats_prefix = "decimalFormats-numberSystem-"sv;
560+
constexpr auto currency_formats_prefix = "currencyFormats-numberSystem-"sv;
559561

560562
if (key.starts_with(symbols_prefix)) {
561563
auto system = key.substring(symbols_prefix.length());
@@ -577,6 +579,14 @@ static void parse_number_systems(String locale_numbers_path, UnicodeLocaleData&
577579

578580
auto const& short_format = value.as_object().get("short"sv).as_object().get("decimalFormat"sv);
579581
number_system.decimal_short_formats = parse_number_format(short_format.as_object());
582+
} else if (key.starts_with(currency_formats_prefix)) {
583+
if (value.as_object().has("short"sv)) {
584+
auto system = key.substring(currency_formats_prefix.length());
585+
auto& number_system = ensure_number_system(system);
586+
587+
auto const& short_format = value.as_object().get("short"sv).as_object().get("standard"sv);
588+
number_system.currency_short_formats = parse_number_format(short_format.as_object());
589+
}
580590
}
581591
});
582592
}
@@ -899,6 +909,7 @@ struct NumberSystem {
899909
Array<@string_index_type@, @numeric_symbols_size@> symbols {};
900910
Span<NumberFormat const> decimal_long_formats {};
901911
Span<NumberFormat const> decimal_short_formats {};
912+
Span<NumberFormat const> currency_short_formats {};
902913
};
903914
)~~~");
904915

@@ -998,6 +1009,7 @@ static constexpr Array<NumberFormat, @size@> @name@ { {
9981009
for (auto const& number_system : number_systems) {
9991010
append_number_formats(format_name(number_system.key, "dl"sv), number_system.value.decimal_long_formats);
10001011
append_number_formats(format_name(number_system.key, "ds"sv), number_system.value.decimal_short_formats);
1012+
append_number_formats(format_name(number_system.key, "cs"sv), number_system.value.currency_short_formats);
10011013
}
10021014

10031015
generator.set("name", name);
@@ -1010,6 +1022,7 @@ static constexpr Array<NumberSystem, @size@> @name@ { {)~~~");
10101022
generator.set("system"sv, String::number(number_system.value.system));
10111023
generator.set("decimal_long_formats"sv, format_name(number_system.key, "dl"sv));
10121024
generator.set("decimal_short_formats"sv, format_name(number_system.key, "ds"sv));
1025+
generator.set("currency_short_formats"sv, format_name(number_system.key, "cs"sv));
10131026
generator.append(R"~~~(
10141027
{ @system@, {)~~~");
10151028

@@ -1019,7 +1032,7 @@ static constexpr Array<NumberSystem, @size@> @name@ { {)~~~");
10191032
generator.append(" @index@,");
10201033
}
10211034

1022-
generator.append(" }, @decimal_long_formats@.span(), @decimal_short_formats@.span() },");
1035+
generator.append(" }, @decimal_long_formats@.span(), @decimal_short_formats@.span(), @currency_short_formats@.span() },");
10231036
}
10241037

10251038
generator.append(R"~~~(
@@ -1401,6 +1414,9 @@ Vector<Unicode::NumberFormat> get_compact_number_system_formats(StringView local
14011414
case CompactNumberFormatType::DecimalShort:
14021415
number_formats = number_system->decimal_short_formats;
14031416
break;
1417+
case CompactNumberFormatType::CurrencyShort:
1418+
number_formats = number_system->currency_short_formats;
1419+
break;
14041420
}
14051421
14061422
formats.ensure_capacity(number_formats.size());

Userland/Libraries/LibUnicode/Locale.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct LocaleID {
8181
enum class CompactNumberFormatType : u8 {
8282
DecimalLong,
8383
DecimalShort,
84+
CurrencyShort,
8485
};
8586

8687
struct NumberFormat {

0 commit comments

Comments
 (0)