LibJS+LibUnicode: Fully implement currency number formatting

Currencies are a bit strange; the layout of currency data in the CLDR is
not particularly compatible with what ECMA-402 expects. For example, the
currency format in the "en" and "ar" locales for the Latin script are:

    en: "¤#,##0.00"
    ar: "¤\u00A0#,##0.00"

Note how the "ar" locale has a non-breaking space after the currency
symbol (¤), but "en" does not. This does not mean that this space will
appear in the "ar"-formatted string, nor does it mean that a space won't
appear in the "en"-formatted string. This is a runtime decision based on
the currency display chosen by the user ("$" vs. "USD" vs. "US dollar")
and other rules in the Unicode TR-35 spec.

ECMA-402 shies away from the nuances here with "implementation-defined"
steps. LibUnicode will store the data parsed from the CLDR however it is
presented; making decisions about spacing, etc. will occur at runtime
based on user input.
This commit is contained in:
Timothy Flynn 2021-11-12 23:16:37 -05:00 committed by Linus Groh
parent e9493a2cd5
commit a701ed52fc
Notes: sideshowbarker 2024-07-18 08:59:31 +09:00
6 changed files with 454 additions and 30 deletions

View file

@ -94,7 +94,7 @@ static void parse_number_pattern(String pattern, UnicodeLocaleData& locale_data,
{ "%"sv, "{percentSign}"sv },
{ "+"sv, "{plusSign}"sv },
{ "-"sv, "{minusSign}"sv },
{ "¤"sv, "{currencyCode}"sv }, // U+00A4 Currency Sign
{ "¤"sv, "{currency}"sv }, // U+00A4 Currency Sign
};
if (auto start_number_index = pattern.find_any_of("#0"sv, String::SearchDirection::Forward); start_number_index.has_value()) {