Pārlūkot izejas kodu

LibUnicode: Generate per-locale approximately & range separator symbols

Timothy Flynn 3 gadi atpakaļ
vecāks
revīzija
b2709f161e

+ 19 - 0
Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp

@@ -489,6 +489,8 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
     };
     };
 
 
     auto numeric_symbol_from_string = [&](StringView numeric_symbol) -> Optional<Unicode::NumericSymbol> {
     auto numeric_symbol_from_string = [&](StringView numeric_symbol) -> Optional<Unicode::NumericSymbol> {
+        if (numeric_symbol == "approximatelySign"sv)
+            return Unicode::NumericSymbol::ApproximatelySign;
         if (numeric_symbol == "decimal"sv)
         if (numeric_symbol == "decimal"sv)
             return Unicode::NumericSymbol::Decimal;
             return Unicode::NumericSymbol::Decimal;
         if (numeric_symbol == "exponential"sv)
         if (numeric_symbol == "exponential"sv)
@@ -516,6 +518,7 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
         constexpr auto currency_formats_prefix = "currencyFormats-numberSystem-"sv;
         constexpr auto currency_formats_prefix = "currencyFormats-numberSystem-"sv;
         constexpr auto percent_formats_prefix = "percentFormats-numberSystem-"sv;
         constexpr auto percent_formats_prefix = "percentFormats-numberSystem-"sv;
         constexpr auto scientific_formats_prefix = "scientificFormats-numberSystem-"sv;
         constexpr auto scientific_formats_prefix = "scientificFormats-numberSystem-"sv;
+        constexpr auto misc_patterns_prefix = "miscPatterns-numberSystem-"sv;
 
 
         if (key.starts_with(symbols_prefix)) {
         if (key.starts_with(symbols_prefix)) {
             auto system = key.substring(symbols_prefix.length());
             auto system = key.substring(symbols_prefix.length());
@@ -535,6 +538,22 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
                 symbols[to_underlying(*numeric_symbol)] = symbol_index;
                 symbols[to_underlying(*numeric_symbol)] = symbol_index;
             });
             });
 
 
+            // The range separator does not appear in the symbols list, we have to extract it from
+            // the range pattern.
+            auto misc_patterns_key = String::formatted("{}{}", misc_patterns_prefix, system);
+            auto misc_patterns = locale_numbers_object.as_object().get(misc_patterns_key);
+            auto range_separator = misc_patterns.as_object().get("range"sv).as_string();
+
+            auto begin_index = range_separator.find("{0}"sv).value() + "{0}"sv.length();
+            auto end_index = range_separator.find("{1}"sv).value();
+            range_separator = range_separator.substring(begin_index, end_index - begin_index);
+
+            if (to_underlying(Unicode::NumericSymbol::RangeSeparator) >= symbols.size())
+                symbols.resize(to_underlying(Unicode::NumericSymbol::RangeSeparator) + 1);
+
+            auto symbol_index = locale_data.unique_strings.ensure(move(range_separator));
+            symbols[to_underlying(Unicode::NumericSymbol::RangeSeparator)] = symbol_index;
+
             number_system.symbols = locale_data.unique_symbols.ensure(move(symbols));
             number_system.symbols = locale_data.unique_symbols.ensure(move(symbols));
         } else if (key.starts_with(decimal_formats_prefix)) {
         } else if (key.starts_with(decimal_formats_prefix)) {
             auto system = key.substring(decimal_formats_prefix.length());
             auto system = key.substring(decimal_formats_prefix.length());

+ 2 - 0
Userland/Libraries/LibUnicode/NumberFormat.h

@@ -47,6 +47,7 @@ struct NumberFormat {
 };
 };
 
 
 enum class NumericSymbol : u8 {
 enum class NumericSymbol : u8 {
+    ApproximatelySign,
     Decimal,
     Decimal,
     Exponential,
     Exponential,
     Group,
     Group,
@@ -55,6 +56,7 @@ enum class NumericSymbol : u8 {
     NaN,
     NaN,
     PercentSign,
     PercentSign,
     PlusSign,
     PlusSign,
+    RangeSeparator,
     TimeSeparator,
     TimeSeparator,
 };
 };