mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +00:00
LibUnicode: Convert UnicodeData to link with weak symbols
This commit is contained in:
parent
f576142fe8
commit
437b9fe204
3 changed files with 25 additions and 75 deletions
|
@ -625,9 +625,10 @@ static void generate_unicode_data_implementation(Core::File& file, UnicodeData c
|
|||
#include <AK/Span.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibUnicode/CharacterTypes.h>
|
||||
#include <LibUnicode/UnicodeData.h>
|
||||
|
||||
namespace Unicode::Detail {
|
||||
namespace Unicode {
|
||||
)~~~");
|
||||
|
||||
auto append_list_and_size = [&](auto const& list, StringView format) {
|
||||
|
@ -851,7 +852,6 @@ static constexpr Array<CodePointName, @code_point_display_names_size@> s_code_po
|
|||
)~~~");
|
||||
|
||||
generator.append(R"~~~(
|
||||
Optional<String> code_point_display_name(u32 code_point) asm("unicode_code_point_display_name");
|
||||
Optional<String> code_point_display_name(u32 code_point)
|
||||
{
|
||||
if (auto const* entry = binary_search(s_code_point_display_names, code_point, nullptr, CodePointNameComparator {})) {
|
||||
|
@ -870,7 +870,6 @@ Optional<String> code_point_display_name(u32 code_point)
|
|||
generator.set("mappings", mappings);
|
||||
generator.set("fallback", fallback);
|
||||
generator.append(R"~~~(
|
||||
u32 @method@(u32 code_point) asm("unicode_@method@");
|
||||
u32 @method@(u32 code_point)
|
||||
{
|
||||
auto const* mapping = binary_search(@mappings@, code_point, nullptr, CodePointComparator<CodePointMapping> {});
|
||||
|
@ -880,11 +879,10 @@ u32 @method@(u32 code_point)
|
|||
};
|
||||
|
||||
append_code_point_mapping_search("canonical_combining_class"sv, "s_combining_class_mappings"sv, "0"sv);
|
||||
append_code_point_mapping_search("simple_uppercase_mapping"sv, "s_uppercase_mappings"sv, "code_point"sv);
|
||||
append_code_point_mapping_search("simple_lowercase_mapping"sv, "s_lowercase_mappings"sv, "code_point"sv);
|
||||
append_code_point_mapping_search("to_unicode_uppercase"sv, "s_uppercase_mappings"sv, "code_point"sv);
|
||||
append_code_point_mapping_search("to_unicode_lowercase"sv, "s_lowercase_mappings"sv, "code_point"sv);
|
||||
|
||||
generator.append(R"~~~(
|
||||
Span<SpecialCasing const* const> special_case_mapping(u32 code_point) asm("unicode_special_case_mapping");
|
||||
Span<SpecialCasing const* const> special_case_mapping(u32 code_point)
|
||||
{
|
||||
auto const* mapping = binary_search(s_special_case_mappings, code_point, nullptr, CodePointComparator<SpecialCaseMapping> {});
|
||||
|
@ -900,7 +898,6 @@ Span<SpecialCasing const* const> special_case_mapping(u32 code_point)
|
|||
generator.set("enum_snake", enum_snake);
|
||||
generator.set("collection_name", collection_name);
|
||||
generator.append(R"~~~(
|
||||
bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@) asm("unicode_code_point_has_@enum_snake@");
|
||||
bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
|
||||
{
|
||||
auto index = static_cast<@enum_title@UnderlyingType>(@enum_snake@);
|
||||
|
@ -921,7 +918,7 @@ bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
|
|||
for (auto const& alias : aliases)
|
||||
hashes.set(alias.alias.hash(), alias.alias);
|
||||
|
||||
generate_value_from_string_for_dynamic_loading(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
|
||||
generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
|
||||
};
|
||||
|
||||
append_prop_search("GeneralCategory"sv, "general_category"sv, "s_general_categories"sv);
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <AK/Utf8View.h>
|
||||
#include <LibUnicode/CharacterTypes.h>
|
||||
#include <LibUnicode/Locale.h>
|
||||
#include <LibUnicode/UnicodeSymbols.h>
|
||||
|
||||
#if ENABLE_UNICODE_DATA
|
||||
# include <LibUnicode/UnicodeData.h>
|
||||
|
@ -22,20 +21,12 @@
|
|||
|
||||
namespace Unicode {
|
||||
|
||||
Optional<String> __attribute__((weak)) code_point_display_name(u32) { return {}; }
|
||||
u32 __attribute__((weak)) canonical_combining_class(u32) { return {}; }
|
||||
Span<SpecialCasing const* const> __attribute__((weak)) special_case_mapping(u32) { return {}; }
|
||||
|
||||
#if ENABLE_UNICODE_DATA
|
||||
|
||||
static u32 canonical_combining_class(u32 code_point)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.canonical_combining_class(code_point);
|
||||
}
|
||||
|
||||
static Span<Unicode::SpecialCasing const* const> special_case_mapping(u32 code_point)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.special_case_mapping(code_point);
|
||||
}
|
||||
|
||||
static bool is_after_uppercase_i(Utf8View const& string, size_t index)
|
||||
{
|
||||
// There is an uppercase I before C, and there is no intervening combining character class 230 (Above) or 0.
|
||||
|
@ -217,22 +208,14 @@ static SpecialCasing const* find_matching_special_case(u32 code_point, Utf8View
|
|||
|
||||
#endif
|
||||
|
||||
u32 to_unicode_lowercase(u32 code_point)
|
||||
u32 __attribute__((weak)) to_unicode_lowercase(u32 code_point)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.simple_lowercase_mapping(code_point);
|
||||
return to_ascii_lowercase(code_point);
|
||||
}
|
||||
|
||||
u32 to_unicode_uppercase(u32 code_point)
|
||||
u32 __attribute__((weak)) to_unicode_uppercase(u32 code_point)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.simple_uppercase_mapping(code_point);
|
||||
}
|
||||
|
||||
Optional<String> code_point_display_name(u32 code_point)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.code_point_display_name(code_point);
|
||||
return to_ascii_uppercase(code_point);
|
||||
}
|
||||
|
||||
String to_unicode_lowercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
|
||||
|
@ -293,29 +276,10 @@ String to_unicode_uppercase_full(StringView string, [[maybe_unused]] Optional<St
|
|||
#endif
|
||||
}
|
||||
|
||||
Optional<GeneralCategory> general_category_from_string(StringView general_category)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.general_category_from_string(general_category);
|
||||
}
|
||||
|
||||
bool code_point_has_general_category(u32 code_point, GeneralCategory general_category)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.code_point_has_general_category(code_point, general_category);
|
||||
}
|
||||
|
||||
Optional<Property> property_from_string(StringView property)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.property_from_string(property);
|
||||
}
|
||||
|
||||
bool code_point_has_property(u32 code_point, Property property)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.code_point_has_property(code_point, property);
|
||||
}
|
||||
Optional<GeneralCategory> __attribute__((weak)) general_category_from_string(StringView) { return {}; }
|
||||
bool __attribute__((weak)) code_point_has_general_category(u32, GeneralCategory) { return {}; }
|
||||
Optional<Property> __attribute__((weak)) property_from_string(StringView) { return {}; }
|
||||
bool __attribute__((weak)) code_point_has_property(u32, Property) { return {}; }
|
||||
|
||||
bool is_ecma262_property([[maybe_unused]] Property property)
|
||||
{
|
||||
|
@ -384,22 +348,8 @@ bool is_ecma262_property([[maybe_unused]] Property property)
|
|||
#endif
|
||||
}
|
||||
|
||||
Optional<Script> script_from_string(StringView script)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.script_from_string(script);
|
||||
}
|
||||
|
||||
bool code_point_has_script(u32 code_point, Script script)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.code_point_has_script(code_point, script);
|
||||
}
|
||||
|
||||
bool code_point_has_script_extension(u32 code_point, Script script)
|
||||
{
|
||||
static auto const& symbols = Detail::Symbols::ensure_loaded();
|
||||
return symbols.code_point_has_script_extension(code_point, script);
|
||||
}
|
||||
Optional<Script> __attribute__((weak)) script_from_string(StringView) { return {}; }
|
||||
bool __attribute__((weak)) code_point_has_script(u32, Script) { return {}; }
|
||||
bool __attribute__((weak)) code_point_has_script_extension(u32, Script) { return {}; }
|
||||
|
||||
}
|
||||
|
|
|
@ -8,19 +8,22 @@
|
|||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Span.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibUnicode/Forward.h>
|
||||
|
||||
namespace Unicode {
|
||||
|
||||
Optional<String> code_point_display_name(u32 code_point);
|
||||
u32 canonical_combining_class(u32 code_point);
|
||||
Span<SpecialCasing const* const> special_case_mapping(u32 code_point);
|
||||
|
||||
// Note: The single code point case conversions only perform simple case folding.
|
||||
// Use the full-string transformations for full case folding.
|
||||
u32 to_unicode_lowercase(u32 code_point);
|
||||
u32 to_unicode_uppercase(u32 code_point);
|
||||
|
||||
Optional<String> code_point_display_name(u32 code_point);
|
||||
|
||||
String to_unicode_lowercase_full(StringView, Optional<StringView> locale = {});
|
||||
String to_unicode_uppercase_full(StringView, Optional<StringView> locale = {});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue