mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibUnicode: Add helper methods to convert a Style to and from a string
This conversion is duplicated a few times in our Intl implementation, so let's just define these once and be done with it.
This commit is contained in:
parent
7f6edb7976
commit
e261132e8b
2 changed files with 28 additions and 0 deletions
|
@ -741,6 +741,31 @@ bool is_locale_available(StringView locale)
|
||||||
return locale_from_string(locale).has_value();
|
return locale_from_string(locale).has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Style style_from_string(StringView style)
|
||||||
|
{
|
||||||
|
if (style == "narrow"sv)
|
||||||
|
return Style::Narrow;
|
||||||
|
if (style == "short"sv)
|
||||||
|
return Style::Short;
|
||||||
|
if (style == "long"sv)
|
||||||
|
return Style::Long;
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
StringView style_to_string(Style style)
|
||||||
|
{
|
||||||
|
switch (style) {
|
||||||
|
case Style::Narrow:
|
||||||
|
return "narrow"sv;
|
||||||
|
case Style::Short:
|
||||||
|
return "short"sv;
|
||||||
|
case Style::Long:
|
||||||
|
return "long"sv;
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Optional<Locale> __attribute__((weak)) locale_from_string(StringView) { return {}; }
|
Optional<Locale> __attribute__((weak)) locale_from_string(StringView) { return {}; }
|
||||||
Optional<Language> __attribute__((weak)) language_from_string(StringView) { return {}; }
|
Optional<Language> __attribute__((weak)) language_from_string(StringView) { return {}; }
|
||||||
Optional<Territory> __attribute__((weak)) territory_from_string(StringView) { return {}; }
|
Optional<Territory> __attribute__((weak)) territory_from_string(StringView) { return {}; }
|
||||||
|
|
|
@ -145,6 +145,9 @@ Optional<String> canonicalize_unicode_locale_id(LocaleID&);
|
||||||
String const& default_locale();
|
String const& default_locale();
|
||||||
bool is_locale_available(StringView locale);
|
bool is_locale_available(StringView locale);
|
||||||
|
|
||||||
|
Style style_from_string(StringView style);
|
||||||
|
StringView style_to_string(Style style);
|
||||||
|
|
||||||
Optional<Locale> locale_from_string(StringView locale);
|
Optional<Locale> locale_from_string(StringView locale);
|
||||||
Optional<Language> language_from_string(StringView language);
|
Optional<Language> language_from_string(StringView language);
|
||||||
Optional<Territory> territory_from_string(StringView territory);
|
Optional<Territory> territory_from_string(StringView territory);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue