mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibUnicode: Use BCP 47 data to filter valid numbering system names
There isn't too much of an effective difference here other than that the BCP 47 data contains some aliases we would otherwise not handle.
This commit is contained in:
parent
63c3437274
commit
71d86261c3
Notes:
sideshowbarker
2024-07-17 18:43:19 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/71d86261c3 Pull-request: https://github.com/SerenityOS/serenity/pull/12558
4 changed files with 27 additions and 16 deletions
|
@ -803,6 +803,7 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::Buffer
|
|||
#include <AK/Vector.h>
|
||||
#include <LibUnicode/Locale.h>
|
||||
#include <LibUnicode/NumberFormat.h>
|
||||
#include <LibUnicode/UnicodeLocale.h>
|
||||
#include <LibUnicode/UnicodeNumberFormat.h>
|
||||
|
||||
namespace Unicode {
|
||||
|
@ -911,22 +912,31 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
|||
generate_mapping(generator, locale_data.locales, s_number_system_index_type, "s_locale_number_systems"sv, "s_number_systems_{}", nullptr, [&](auto const& name, auto const& value) { append_map(name, s_number_system_index_type, value.number_systems); });
|
||||
generate_mapping(generator, locale_data.locales, s_unit_index_type, "s_locale_units"sv, "s_units_{}", nullptr, [&](auto const& name, auto const& value) { append_map(name, s_unit_index_type, value.units); });
|
||||
|
||||
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values) {
|
||||
HashValueMap<String> hashes;
|
||||
hashes.ensure_capacity(values.size());
|
||||
generator.append(R"~~~(
|
||||
static Optional<NumberSystem> keyword_to_number_system(KeywordNumbers keyword)
|
||||
{
|
||||
switch (keyword) {)~~~");
|
||||
|
||||
for (auto const& value : values)
|
||||
hashes.set(value.hash(), format_identifier(enum_title, value));
|
||||
|
||||
generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
|
||||
};
|
||||
|
||||
append_from_string("NumberSystem"sv, "number_system"sv, locale_data.number_systems);
|
||||
for (auto const& number_system : locale_data.number_systems) {
|
||||
generator.set("name"sv, format_identifier({}, number_system));
|
||||
generator.append(R"~~~(
|
||||
case KeywordNumbers::@name@:
|
||||
return NumberSystem::@name@;)~~~");
|
||||
}
|
||||
|
||||
generator.append(R"~~~(
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Optional<Span<u32 const>> get_digits_for_number_system(StringView system)
|
||||
{
|
||||
auto number_system_value = number_system_from_string(system);
|
||||
auto number_system_keyword = keyword_nu_from_string(system);
|
||||
if (!number_system_keyword.has_value())
|
||||
return {};
|
||||
|
||||
auto number_system_value = keyword_to_number_system(*number_system_keyword);
|
||||
if (!number_system_value.has_value())
|
||||
return {};
|
||||
|
||||
|
@ -940,9 +950,13 @@ static NumberSystemData const* find_number_system(StringView locale, StringView
|
|||
if (!locale_value.has_value())
|
||||
return nullptr;
|
||||
|
||||
auto number_system_value = number_system_from_string(system);
|
||||
auto number_system_keyword = keyword_nu_from_string(system);
|
||||
if (!number_system_keyword.has_value())
|
||||
return {};
|
||||
|
||||
auto number_system_value = keyword_to_number_system(*number_system_keyword);
|
||||
if (!number_system_value.has_value())
|
||||
return nullptr;
|
||||
return {};
|
||||
|
||||
auto locale_index = to_underlying(*locale_value) - 1; // Subtract 1 because 0 == Locale::None.
|
||||
auto number_system_index = to_underlying(*number_system_value);
|
||||
|
|
|
@ -35,7 +35,6 @@ enum class ListPatternStyle : u8;
|
|||
enum class ListPatternType : u8;
|
||||
enum class Locale : u16;
|
||||
enum class Month : u8;
|
||||
enum class NumberSystem : u8;
|
||||
enum class NumericSymbol : u8;
|
||||
enum class Property : u8;
|
||||
enum class Script : u8;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
namespace Unicode {
|
||||
|
||||
Optional<NumberSystem> __attribute__((weak)) number_system_from_string(StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_number_system_symbol(StringView, StringView, NumericSymbol) { return {}; }
|
||||
Optional<NumberGroupings> __attribute__((weak)) get_number_system_groupings(StringView, StringView) { return {}; }
|
||||
Optional<NumberFormat> __attribute__((weak)) get_standard_number_system_format(StringView, StringView, StandardNumberFormatType) { return {}; }
|
||||
|
|
|
@ -66,7 +66,6 @@ enum class NumericSymbol : u8 {
|
|||
PlusSign,
|
||||
};
|
||||
|
||||
Optional<NumberSystem> number_system_from_string(StringView system);
|
||||
Optional<StringView> get_default_number_system(StringView locale);
|
||||
|
||||
Optional<StringView> get_number_system_symbol(StringView locale, StringView system, NumericSymbol symbol);
|
||||
|
|
Loading…
Reference in a new issue