summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-08-30 15:51:08 -0400
committerLinus Groh <mail@linusgroh.de>2021-09-01 14:14:47 +0100
commitf907a7dc386e7cee729b8d96b6287dd0f1af1b72 (patch)
tree5ff6660e14c3d915b2e164d8c9db5c9c467dbe27 /Userland
parent556374a904722eca9f068bdc8ac8fdc32b0ea361 (diff)
downloadserenity-f907a7dc386e7cee729b8d96b6287dd0f1af1b72.zip
LibUnicode: Canonicalize the subtag "yes" to "true"
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibUnicode/Locale.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibUnicode/Locale.cpp b/Userland/Libraries/LibUnicode/Locale.cpp
index 6cbeb241b1..dea0d692ed 100644
--- a/Userland/Libraries/LibUnicode/Locale.cpp
+++ b/Userland/Libraries/LibUnicode/Locale.cpp
@@ -480,6 +480,17 @@ Optional<LocaleID> parse_unicode_locale_id(StringView locale)
return locale_id;
}
+static void perform_hard_coded_key_value_substitutions(String& key, String& value)
+{
+ // FIXME: In the XML export of CLDR, there are some aliases defined in the following file:
+ // https://github.com/unicode-org/cldr-staging/blob/master/production/common/bcp47/collation.xml
+ //
+ // There doesn't seem to be a counterpart in the JSON export. Since there aren't many such
+ // aliases, until an XML parser is implemented, those aliases are implemented here.
+ if (key.is_one_of("kb"sv, "kc"sv, "kh"sv, "kk"sv, "kn"sv) && (value == "yes"sv))
+ value = "true"sv;
+}
+
static void transform_unicode_locale_id_to_canonical_syntax(LocaleID& locale_id)
{
auto canonicalize_language = [](LanguageID& language_id, bool force_lowercase) {
@@ -542,6 +553,7 @@ static void transform_unicode_locale_id_to_canonical_syntax(LocaleID& locale_id)
for (auto& value : raw_values) {
value = value.to_lowercase();
+ perform_hard_coded_key_value_substitutions(key, value);
// Note: The spec says to remove "true" type and tfield values but that is believed to be a bug in the spec
// because, for tvalues, that would result in invalid syntax: