From f4785e24685fcdf04305f353bbc372513505694f Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Thu, 30 Jun 2022 15:44:03 +0300 Subject: [PATCH] LibUnicode: Generate data about DurationFormat-required units as well --- .../LibUnicode/GenerateUnicodeNumberFormat.cpp | 5 ++++- Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp index 7f211bdf95a..6f60bbdbdb9 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp @@ -637,7 +637,10 @@ static ErrorOr parse_units(String locale_units_path, UnicodeLocaleData& lo // LibUnicode generally tries to avoid being directly dependent on ECMA-402, but this rather significantly reduces the amount // of data generated here, and ECMA-402 is currently the only consumer of this data. constexpr auto sanctioned_units = JS::Intl::sanctioned_single_unit_identifiers(); - return find(sanctioned_units.begin(), sanctioned_units.end(), unit_name) != sanctioned_units.end(); + if (find(sanctioned_units.begin(), sanctioned_units.end(), unit_name) != sanctioned_units.end()) + return true; + static constexpr auto extra_sanctioned_units = JS::Intl::extra_sanctioned_single_unit_identifiers(); + return find(extra_sanctioned_units.begin(), extra_sanctioned_units.end(), unit_name) != extra_sanctioned_units.end(); }; auto parse_units_object = [&](auto const& units_object, Unicode::Style style) { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h index 920b2088d63..561d909aefc 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h @@ -59,6 +59,12 @@ constexpr auto sanctioned_single_unit_identifiers() return AK::Array { "acre"sv, "bit"sv, "byte"sv, "celsius"sv, "centimeter"sv, "day"sv, "degree"sv, "fahrenheit"sv, "fluid-ounce"sv, "foot"sv, "gallon"sv, "gigabit"sv, "gigabyte"sv, "gram"sv, "hectare"sv, "hour"sv, "inch"sv, "kilobit"sv, "kilobyte"sv, "kilogram"sv, "kilometer"sv, "liter"sv, "megabit"sv, "megabyte"sv, "meter"sv, "mile"sv, "mile-scandinavian"sv, "milliliter"sv, "millimeter"sv, "millisecond"sv, "minute"sv, "month"sv, "ounce"sv, "percent"sv, "petabyte"sv, "pound"sv, "second"sv, "stone"sv, "terabit"sv, "terabyte"sv, "week"sv, "yard"sv, "year"sv }; } +// Additional single units used in ECMAScript required by the Intl.DurationFormat proposal +constexpr auto extra_sanctioned_single_unit_identifiers() +{ + return AK::Array { "microsecond"sv, "nanosecond"sv }; +} + Optional is_structurally_valid_language_tag(StringView locale); String canonicalize_unicode_locale_id(Unicode::LocaleID& locale); bool is_well_formed_currency_code(StringView currency);