mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +00:00
LibUnicode: Dynamically load the generated UnicodeNumberFormat symbols
This commit is contained in:
parent
09be26b5d2
commit
a1f0ca59ae
4 changed files with 40 additions and 53 deletions
|
@ -713,30 +713,9 @@ static void generate_unicode_locale_header(Core::File& file, UnicodeLocaleData&)
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
|
|
||||||
|
// FIXME: Update unicode_data.cmake to not require a header.
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Optional.h>
|
|
||||||
#include <AK/StringView.h>
|
|
||||||
#include <AK/Vector.h>
|
|
||||||
#include <LibUnicode/Forward.h>
|
|
||||||
|
|
||||||
namespace Unicode {
|
|
||||||
)~~~");
|
|
||||||
|
|
||||||
generator.append(R"~~~(
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
Optional<StringView> get_number_system_symbol(StringView locale, StringView system, Unicode::NumericSymbol symbol);
|
|
||||||
Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system);
|
|
||||||
Optional<NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type);
|
|
||||||
Vector<NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type);
|
|
||||||
Vector<Unicode::NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style);
|
|
||||||
Optional<NumericSymbol> numeric_symbol_from_string(StringView numeric_symbol);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
VERIFY(file.write(generator.as_string_view()));
|
VERIFY(file.write(generator.as_string_view()));
|
||||||
|
@ -755,7 +734,10 @@ static void generate_unicode_locale_implementation(Core::File& file, UnicodeLoca
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
#include <AK/BinarySearch.h>
|
#include <AK/BinarySearch.h>
|
||||||
|
#include <AK/Optional.h>
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
|
#include <AK/StringView.h>
|
||||||
|
#include <AK/Vector.h>
|
||||||
#include <LibUnicode/Locale.h>
|
#include <LibUnicode/Locale.h>
|
||||||
#include <LibUnicode/NumberFormat.h>
|
#include <LibUnicode/NumberFormat.h>
|
||||||
#include <LibUnicode/UnicodeNumberFormat.h>
|
#include <LibUnicode/UnicodeNumberFormat.h>
|
||||||
|
@ -868,6 +850,7 @@ static NumberSystem const* find_number_system(StringView locale, StringView syst
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<StringView> get_number_system_symbol(StringView locale, StringView system, Unicode::NumericSymbol symbol) asm("unicode_get_number_system_symbol");
|
||||||
Optional<StringView> get_number_system_symbol(StringView locale, StringView system, Unicode::NumericSymbol symbol)
|
Optional<StringView> get_number_system_symbol(StringView locale, StringView system, Unicode::NumericSymbol symbol)
|
||||||
{
|
{
|
||||||
if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
|
if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
|
||||||
|
@ -883,6 +866,7 @@ Optional<StringView> get_number_system_symbol(StringView locale, StringView syst
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system) asm("unicode_get_number_system_groupings");
|
||||||
Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system)
|
Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system)
|
||||||
{
|
{
|
||||||
if (auto const* number_system = find_number_system(locale, system); number_system != nullptr)
|
if (auto const* number_system = find_number_system(locale, system); number_system != nullptr)
|
||||||
|
@ -890,6 +874,7 @@ Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringV
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<Unicode::NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type) asm("unicode_get_standard_number_system_format");
|
||||||
Optional<Unicode::NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type)
|
Optional<Unicode::NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type)
|
||||||
{
|
{
|
||||||
if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
|
if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
|
||||||
|
@ -919,6 +904,7 @@ Optional<Unicode::NumberFormat> get_standard_number_system_format(StringView loc
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<Unicode::NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type) asm("unicode_get_compact_number_system_formats");
|
||||||
Vector<Unicode::NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type)
|
Vector<Unicode::NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type)
|
||||||
{
|
{
|
||||||
Vector<Unicode::NumberFormat> formats;
|
Vector<Unicode::NumberFormat> formats;
|
||||||
|
@ -970,6 +956,7 @@ static Unit const* find_units(StringView locale, StringView unit)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<Unicode::NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style) asm("unicode_get_unit_formats");
|
||||||
Vector<Unicode::NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style)
|
Vector<Unicode::NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style)
|
||||||
{
|
{
|
||||||
Vector<Unicode::NumberFormat> formats;
|
Vector<Unicode::NumberFormat> formats;
|
||||||
|
|
|
@ -8,57 +8,42 @@
|
||||||
#include <LibUnicode/CharacterTypes.h>
|
#include <LibUnicode/CharacterTypes.h>
|
||||||
#include <LibUnicode/Locale.h>
|
#include <LibUnicode/Locale.h>
|
||||||
#include <LibUnicode/NumberFormat.h>
|
#include <LibUnicode/NumberFormat.h>
|
||||||
|
#include <LibUnicode/UnicodeSymbols.h>
|
||||||
|
|
||||||
#if ENABLE_UNICODE_DATA
|
#if ENABLE_UNICODE_DATA
|
||||||
# include <LibUnicode/UnicodeData.h>
|
# include <LibUnicode/UnicodeData.h>
|
||||||
# include <LibUnicode/UnicodeNumberFormat.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Unicode {
|
namespace Unicode {
|
||||||
|
|
||||||
Optional<StringView> get_number_system_symbol([[maybe_unused]] StringView locale, [[maybe_unused]] StringView system, [[maybe_unused]] NumericSymbol symbol)
|
Optional<StringView> get_number_system_symbol(StringView locale, StringView system, NumericSymbol symbol)
|
||||||
{
|
{
|
||||||
#if ENABLE_UNICODE_DATA
|
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||||
return Detail::get_number_system_symbol(locale, system, symbol);
|
return symbols.get_number_system_symbol(locale, system, symbol);
|
||||||
#else
|
|
||||||
return {};
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<NumberGroupings> get_number_system_groupings([[maybe_unused]] StringView locale, [[maybe_unused]] StringView system)
|
Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system)
|
||||||
{
|
{
|
||||||
#if ENABLE_UNICODE_DATA
|
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||||
return Detail::get_number_system_groupings(locale, system);
|
return symbols.get_number_system_groupings(locale, system);
|
||||||
#else
|
|
||||||
return {};
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<NumberFormat> get_standard_number_system_format([[maybe_unused]] StringView locale, [[maybe_unused]] StringView system, [[maybe_unused]] StandardNumberFormatType type)
|
Optional<NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type)
|
||||||
{
|
{
|
||||||
#if ENABLE_UNICODE_DATA
|
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||||
return Detail::get_standard_number_system_format(locale, system, type);
|
return symbols.get_standard_number_system_format(locale, system, type);
|
||||||
#else
|
|
||||||
return {};
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<NumberFormat> get_compact_number_system_formats([[maybe_unused]] StringView locale, [[maybe_unused]] StringView system, [[maybe_unused]] CompactNumberFormatType type)
|
Vector<NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type)
|
||||||
{
|
{
|
||||||
#if ENABLE_UNICODE_DATA
|
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||||
return Detail::get_compact_number_system_formats(locale, system, type);
|
return symbols.get_compact_number_system_formats(locale, system, type);
|
||||||
#else
|
|
||||||
return {};
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<NumberFormat> get_unit_formats([[maybe_unused]] StringView locale, [[maybe_unused]] StringView unit, [[maybe_unused]] Style style)
|
Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style)
|
||||||
{
|
{
|
||||||
#if ENABLE_UNICODE_DATA
|
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||||
return Detail::get_unit_formats(locale, unit, style);
|
return symbols.get_unit_formats(locale, unit, style);
|
||||||
#else
|
|
||||||
return {};
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<NumberFormat> select_pattern_with_plurality(Vector<NumberFormat> const& formats, double number)
|
Optional<NumberFormat> select_pattern_with_plurality(Vector<NumberFormat> const& formats, double number)
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#else
|
#else
|
||||||
# include <AK/Function.h>
|
# include <AK/Function.h>
|
||||||
# include <LibUnicode/Locale.h>
|
# include <LibUnicode/Locale.h>
|
||||||
|
# include <LibUnicode/NumberFormat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Unicode::Detail {
|
namespace Unicode::Detail {
|
||||||
|
@ -110,6 +111,12 @@ Symbols const& Symbols::ensure_loaded()
|
||||||
load_symbol(symbols.add_likely_subtags, "unicode_add_likely_subtags");
|
load_symbol(symbols.add_likely_subtags, "unicode_add_likely_subtags");
|
||||||
load_symbol(symbols.resolve_most_likely_territory, "unicode_resolve_most_likely_territory");
|
load_symbol(symbols.resolve_most_likely_territory, "unicode_resolve_most_likely_territory");
|
||||||
|
|
||||||
|
load_symbol(symbols.get_number_system_symbol, "unicode_get_number_system_symbol");
|
||||||
|
load_symbol(symbols.get_number_system_groupings, "unicode_get_number_system_groupings");
|
||||||
|
load_symbol(symbols.get_standard_number_system_format, "unicode_get_standard_number_system_format");
|
||||||
|
load_symbol(symbols.get_compact_number_system_formats, "unicode_get_compact_number_system_formats");
|
||||||
|
load_symbol(symbols.get_unit_formats, "unicode_get_unit_formats");
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
return symbols;
|
return symbols;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,14 @@ struct Symbols {
|
||||||
Optional<LanguageID> (*add_likely_subtags)(LanguageID const&);
|
Optional<LanguageID> (*add_likely_subtags)(LanguageID const&);
|
||||||
Optional<String> (*resolve_most_likely_territory)(LanguageID const&);
|
Optional<String> (*resolve_most_likely_territory)(LanguageID const&);
|
||||||
|
|
||||||
|
// Loaded from UnicodeNumberFormat.cpp:
|
||||||
|
|
||||||
|
Optional<StringView> (*get_number_system_symbol)(StringView, StringView, NumericSymbol);
|
||||||
|
Optional<NumberGroupings> (*get_number_system_groupings)(StringView, StringView);
|
||||||
|
Optional<NumberFormat> (*get_standard_number_system_format)(StringView, StringView, StandardNumberFormatType);
|
||||||
|
Vector<NumberFormat> (*get_compact_number_system_formats)(StringView, StringView, CompactNumberFormatType);
|
||||||
|
Vector<NumberFormat> (*get_unit_formats)(StringView, StringView, Style);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Symbols() = default;
|
Symbols() = default;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue