1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:47:44 +00:00

LibUnicode: Add public accessors to generated locale data

This commit is contained in:
Timothy Flynn 2021-08-24 22:17:08 -04:00 committed by Linus Groh
parent b7a95cba65
commit 137e98cb6f
2 changed files with 41 additions and 0 deletions

View file

@ -11,6 +11,10 @@
#include <AK/StringBuilder.h>
#include <LibUnicode/Locale.h>
#if ENABLE_UNICODE_DATA
# include <LibUnicode/UnicodeLocale.h>
#endif
namespace Unicode {
bool is_unicode_language_subtag(StringView subtag)
@ -149,4 +153,36 @@ Optional<String> canonicalize_unicode_locale_id(LocaleID& locale_id)
return builder.build();
}
String const& default_locale()
{
static String locale = "en"sv;
return locale;
}
bool is_locale_available([[maybe_unused]] StringView locale)
{
#if ENABLE_UNICODE_DATA
static auto const& available_locales = Detail::available_locales();
return available_locales.contains(locale);
#else
return false;
#endif
}
Optional<StringView> get_locale_territory_mapping([[maybe_unused]] StringView locale, [[maybe_unused]] StringView code)
{
#if ENABLE_UNICODE_DATA
static auto const& available_locales = Detail::available_locales();
auto it = available_locales.find(locale);
if (it == available_locales.end())
return {};
if (auto territory = Detail::territory_from_string(code); territory.has_value())
return it->value.territories[to_underlying(*territory)];
#endif
return {};
}
}