mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 10:34:58 +00:00

This commit is preemptive to upcoming commits which add more subtags to the CLDR generator. Rather than generating a giant HashMap containing all data, generate more (smaller) Array-based tables. This mimics the UCD generator. This also allows simpler lookups at runtime since we can generate index-based lookups into the smaller tables rather easily. Without this change, adding the remaining locale subtags would result in the generation and compilation of UnicodeLocale.cpp taking about 30s on my machine. With this change, it takes about half that. Additionally, the size of the generated file reduces by about 1.5MB.
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Optional.h>
|
|
#include <AK/String.h>
|
|
#include <AK/StringView.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibUnicode/Forward.h>
|
|
|
|
namespace Unicode {
|
|
|
|
struct LanguageID {
|
|
bool is_root { false };
|
|
Optional<StringView> language {};
|
|
Optional<StringView> script {};
|
|
Optional<StringView> region {};
|
|
Vector<StringView> variants {};
|
|
};
|
|
|
|
struct LocaleID {
|
|
LanguageID language_id {};
|
|
};
|
|
|
|
// 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);
|
|
|
|
Optional<LanguageID> parse_unicode_language_id(StringView);
|
|
Optional<LocaleID> parse_unicode_locale_id(StringView);
|
|
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 territory);
|
|
|
|
}
|