/* * Copyright (c) 2021, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Unicode { struct LanguageID { String to_string() const; bool is_root { false }; Optional language {}; Optional script {}; Optional region {}; Vector variants {}; }; struct Keyword { String key {}; Vector types {}; }; struct LocaleExtension { Vector attributes {}; Vector keywords {}; }; struct TransformedField { String key; Vector values {}; }; struct TransformedExtension { Optional language {}; Vector fields {}; }; struct OtherExtension { char key {}; Vector values {}; }; using Extension = Variant; struct LocaleID { String to_string() const; template void remove_extension_type() { auto tmp_extensions = move(extensions); for (auto& extension : tmp_extensions) { if (!extension.has()) extensions.append(move(extension)); } } LanguageID language_id {}; Vector extensions {}; Vector private_use_extensions {}; }; // 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). bool is_unicode_language_subtag(StringView); bool is_unicode_script_subtag(StringView); bool is_unicode_region_subtag(StringView); bool is_unicode_variant_subtag(StringView); bool is_type_identifier(StringView); Optional parse_unicode_language_id(StringView); Optional parse_unicode_locale_id(StringView); Optional canonicalize_unicode_locale_id(LocaleID&); String const& default_locale(); bool is_locale_available(StringView locale); Optional get_locale_language_mapping(StringView locale, StringView language); Optional get_locale_territory_mapping(StringView locale, StringView territory); Optional get_locale_script_mapping(StringView locale, StringView script); Optional get_locale_currency_mapping(StringView locale, StringView currency); Optional resolve_language_alias(StringView language); Optional resolve_territory_alias(StringView territory); Optional resolve_script_tag_alias(StringView script_tag); Optional resolve_variant_alias(StringView variant); Optional resolve_subdivision_alias(StringView subdivision); String resolve_most_likely_territory(LanguageID const& language_id, StringView territory_alias); }