mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibUnicode: Add public accessors to generated locale data
This commit is contained in:
parent
b7a95cba65
commit
137e98cb6f
2 changed files with 41 additions and 0 deletions
|
@ -11,6 +11,10 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibUnicode/Locale.h>
|
#include <LibUnicode/Locale.h>
|
||||||
|
|
||||||
|
#if ENABLE_UNICODE_DATA
|
||||||
|
# include <LibUnicode/UnicodeLocale.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Unicode {
|
namespace Unicode {
|
||||||
|
|
||||||
bool is_unicode_language_subtag(StringView subtag)
|
bool is_unicode_language_subtag(StringView subtag)
|
||||||
|
@ -149,4 +153,36 @@ Optional<String> canonicalize_unicode_locale_id(LocaleID& locale_id)
|
||||||
return builder.build();
|
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 {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,9 @@ Optional<LanguageID> parse_unicode_language_id(StringView);
|
||||||
Optional<LocaleID> parse_unicode_locale_id(StringView);
|
Optional<LocaleID> parse_unicode_locale_id(StringView);
|
||||||
Optional<String> canonicalize_unicode_locale_id(LocaleID&);
|
Optional<String> canonicalize_unicode_locale_id(LocaleID&);
|
||||||
|
|
||||||
|
String const& default_locale();
|
||||||
|
bool is_locale_available(StringView locale);
|
||||||
|
|
||||||
|
Optional<StringView> get_locale_territory_mapping(StringView locale, StringView code);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue