diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-11-16 13:53:45 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-16 23:14:09 +0000 |
commit | 04b8b87c17ba21d3969c0e5c52dc1b01eddd8b80 (patch) | |
tree | 9deb75b20fb22e85b85d6e1e7556ae9da426f948 /Userland/Libraries | |
parent | 3b68370212cb33c1146a57b5cabee730fcfdc5a3 (diff) | |
download | serenity-04b8b87c17ba21d3969c0e5c52dc1b01eddd8b80.zip |
LibJS+LibUnicode: Support multiple identifiers within format pattern
This wasn't the case for compact patterns, but unit patterns can contain
multiple (up to 2, really) identifiers that must each be recognized by
LibJS.
Each generated NumberFormat object now stores an array of identifiers
parsed. The format pattern itself is encoded with the index into this
array for that identifier, e.g. the compact format string "0K" will
become "{number}{compactIdentifier:0}".
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibUnicode/Locale.h | 2 |
2 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index f2bfecefd9..9373105fa4 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -962,11 +962,14 @@ Vector<PatternPartition> partition_notation_sub_pattern(NumberFormat& number_for } // iv. Else if p is equal to "compactSymbol", then // v. Else if p is equal to "compactName", then - else if (part == "compactIdentifier"sv) { + else if (part.starts_with("compactIdentifier:"sv)) { // Note: Our implementation combines "compactSymbol" and "compactName" into one field, "compactIdentifier". + auto identifier_index = part.substring_view("compactIdentifier:"sv.length()).to_uint(); + VERIFY(identifier_index.has_value()); + // 1. Let compactSymbol be an ILD string representing exponent in short form, which may depend on x in languages having different plural forms. The implementation must be able to provide this string, or else the pattern would not have a "{compactSymbol}" placeholder. - auto compact_identifier = number_format.compact_format().identifier; + auto compact_identifier = number_format.compact_format().identifiers[*identifier_index]; // 2. Append a new Record { [[Type]]: "compact", [[Value]]: compactSymbol } as the last element of result. result.append({ "compact"sv, compact_identifier }); diff --git a/Userland/Libraries/LibUnicode/Locale.h b/Userland/Libraries/LibUnicode/Locale.h index a82856b3e6..0979e4851f 100644 --- a/Userland/Libraries/LibUnicode/Locale.h +++ b/Userland/Libraries/LibUnicode/Locale.h @@ -122,7 +122,7 @@ struct NumberFormat { StringView zero_format {}; StringView positive_format {}; StringView negative_format {}; - StringView identifier {}; + Vector<StringView> identifiers {}; }; struct ListPatterns { |