diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-08-31 09:40:24 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-01 14:14:47 +0100 |
commit | 1fbc5dba08062e6d5702e49cf24fc869a7de304d (patch) | |
tree | e2079d2ab855099bbd68a3f75be0da7a9256eb97 /Userland | |
parent | 72f49e42b49536dca912202aa7e779ea10133c90 (diff) | |
download | serenity-1fbc5dba08062e6d5702e49cf24fc869a7de304d.zip |
LibUnicode: Generate Unicode locale likely subtag data
CLDR contains a set of likely subtag data where, given a locale, you can
resolve what is the most likely language, script, or territory of that
locale. This data is needed for resolving territory aliases. These
aliases might contain multiple territories, and we need to resolve which
of those territories is most likely correct for a locale.
Note that the likely subtag data is quite huge (a few thousand entries).
As an optimization encouraged by the spec, we only generate the smallest
subset of this data that we actually need (about 150 entries).
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibUnicode/Locale.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibUnicode/Locale.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibUnicode/Locale.cpp b/Userland/Libraries/LibUnicode/Locale.cpp index 291b6f0782..88e86ce7f6 100644 --- a/Userland/Libraries/LibUnicode/Locale.cpp +++ b/Userland/Libraries/LibUnicode/Locale.cpp @@ -860,4 +860,19 @@ Optional<StringView> resolve_subdivision_alias(StringView subdivision) #endif } +String resolve_most_likely_territory([[maybe_unused]] LanguageID const& language_id, StringView territory_alias) +{ + auto aliases = territory_alias.split_view(' '); + +#if ENABLE_UNICODE_DATA + if (aliases.size() > 1) { + auto territory = Detail::resolve_most_likely_territory(language_id); + if (territory.has_value() && aliases.contains_slow(*territory)) + return territory.release_value(); + } +#endif + + return aliases[0].to_string(); +} + } diff --git a/Userland/Libraries/LibUnicode/Locale.h b/Userland/Libraries/LibUnicode/Locale.h index de5bcb0b8b..7cff3ad5f4 100644 --- a/Userland/Libraries/LibUnicode/Locale.h +++ b/Userland/Libraries/LibUnicode/Locale.h @@ -81,4 +81,6 @@ Optional<StringView> resolve_script_tag_alias(StringView script_tag); Optional<StringView> resolve_variant_alias(StringView variant); Optional<StringView> resolve_subdivision_alias(StringView subdivision); +String resolve_most_likely_territory(LanguageID const& language_id, StringView territory_alias); + } |