summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-09-06 13:56:44 -0400
committerLinus Groh <mail@linusgroh.de>2021-09-06 23:49:56 +0100
commit3f64a14e0628051935c83a59da5e049a82610138 (patch)
treebb1bc7eb2c4847c0b75fa7bbf9ae2a7bdaae4519 /Userland/Libraries
parent9cd986d8c00da6737a531c240266872dc527560c (diff)
downloadserenity-3f64a14e0628051935c83a59da5e049a82610138.zip
LibUnicode: Parse and generate the Unicode locale list patterns dataset
This data informs consumers how to join lists of values. For example, in en-US, the list ["a", "b", "c"] formatted to a string should become "a, b, and c".
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibUnicode/Forward.h3
-rw-r--r--Userland/Libraries/LibUnicode/Locale.cpp9
-rw-r--r--Userland/Libraries/LibUnicode/Locale.h8
3 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibUnicode/Forward.h b/Userland/Libraries/LibUnicode/Forward.h
index 33a6991b31..5d9dde274e 100644
--- a/Userland/Libraries/LibUnicode/Forward.h
+++ b/Userland/Libraries/LibUnicode/Forward.h
@@ -13,6 +13,8 @@ namespace Unicode {
enum class Condition : u8;
enum class GeneralCategory : u8;
enum class Language : u8;
+enum class ListPatternStyle : u8;
+enum class ListPatternType : u8;
enum class Locale : u16;
enum class Property : u8;
enum class Script : u8;
@@ -21,6 +23,7 @@ enum class WordBreakProperty : u8;
struct Keyword;
struct LanguageID;
+struct ListPatterns;
struct LocaleExtension;
struct LocaleID;
struct OtherExtension;
diff --git a/Userland/Libraries/LibUnicode/Locale.cpp b/Userland/Libraries/LibUnicode/Locale.cpp
index d293e2c493..025d202458 100644
--- a/Userland/Libraries/LibUnicode/Locale.cpp
+++ b/Userland/Libraries/LibUnicode/Locale.cpp
@@ -798,6 +798,15 @@ Optional<StringView> get_locale_currency_mapping([[maybe_unused]] StringView loc
#endif
}
+Optional<ListPatterns> get_locale_list_patterns([[maybe_unused]] StringView locale, [[maybe_unused]] StringView type, [[maybe_unused]] StringView style)
+{
+#if ENABLE_UNICODE_DATA
+ return Detail::get_locale_list_pattern_mapping(locale, type, style);
+#else
+ return {};
+#endif
+}
+
Optional<StringView> resolve_language_alias(StringView language)
{
#if ENABLE_UNICODE_DATA
diff --git a/Userland/Libraries/LibUnicode/Locale.h b/Userland/Libraries/LibUnicode/Locale.h
index 0a388fd16e..428d84714b 100644
--- a/Userland/Libraries/LibUnicode/Locale.h
+++ b/Userland/Libraries/LibUnicode/Locale.h
@@ -78,6 +78,13 @@ struct LocaleID {
Vector<String> private_use_extensions {};
};
+struct ListPatterns {
+ StringView start;
+ StringView middle;
+ StringView end;
+ StringView pair;
+};
+
// Note: These methods only verify that the provided strings match the EBNF grammar of the
// Unicode identifier subtag (i.e. no validation is done that the tags actually exist).
constexpr bool is_unicode_language_subtag(StringView subtag)
@@ -130,6 +137,7 @@ Optional<StringView> get_locale_language_mapping(StringView locale, StringView l
Optional<StringView> get_locale_territory_mapping(StringView locale, StringView territory);
Optional<StringView> get_locale_script_mapping(StringView locale, StringView script);
Optional<StringView> get_locale_currency_mapping(StringView locale, StringView currency);
+Optional<ListPatterns> get_locale_list_patterns(StringView locale, StringView type, StringView style);
Optional<StringView> resolve_language_alias(StringView language);
Optional<StringView> resolve_territory_alias(StringView territory);