From d382e77d38cff6e833d6a59ff8c6179a2b3e6ad9 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 13 Dec 2022 10:07:23 -0500 Subject: [PATCH] LibUnicode: Fix compilation when the UCD download is disabled --- Meta/Lagom/CMakeLists.txt | 4 +++- Userland/Libraries/LibUnicode/Normalize.cpp | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 1ae5b7a7254..40c9e4e4f73 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -432,7 +432,9 @@ if (BUILD_LAGOM) # FIXME: LibLocaleData is an object lib in Lagom, because the weak symbol trick we use on serenity # straight up isn't supposed to work per ELF rules target_link_libraries(LibLocale PRIVATE LibTimeZone) - install(TARGETS LibLocaleData EXPORT LagomTargets) + if (ENABLE_UNICODE_DATABASE_DOWNLOAD) + install(TARGETS LibLocaleData EXPORT LagomTargets) + endif() add_serenity_subdirectory(Userland/Shell) diff --git a/Userland/Libraries/LibUnicode/Normalize.cpp b/Userland/Libraries/LibUnicode/Normalize.cpp index 55ad0877e97..a47aabb17f4 100644 --- a/Userland/Libraries/LibUnicode/Normalize.cpp +++ b/Userland/Libraries/LibUnicode/Normalize.cpp @@ -10,7 +10,12 @@ #include #include #include -#include + +#if ENABLE_UNICODE_DATA +# include +#else +struct Unicode::CodePointDecomposition { }; +#endif namespace Unicode { @@ -118,9 +123,11 @@ static u32 combine_hangul_code_points(u32 a, u32 b) return 0; } -static u32 combine_code_points(u32 a, u32 b) +static u32 combine_code_points([[maybe_unused]] u32 a, [[maybe_unused]] u32 b) { +#if ENABLE_UNICODE_DATA Array const points { a, b }; + // FIXME: Do something better than linear search to find reverse mappings. for (size_t index = 0;; ++index) { auto mapping_maybe = Unicode::code_point_decomposition_by_index(index); @@ -133,6 +140,8 @@ static u32 combine_code_points(u32 a, u32 b) return mapping.code_point; } } +#endif + return 0; } @@ -141,12 +150,14 @@ enum class UseCompatibility { No }; -static void decompose_code_point(u32 code_point, Vector& code_points_output, UseCompatibility use_compatibility) +static void decompose_code_point(u32 code_point, Vector& code_points_output, [[maybe_unused]] UseCompatibility use_compatibility) { if (is_hangul_code_point(code_point)) { decompose_hangul_code_point(code_point, code_points_output); return; } + +#if ENABLE_UNICODE_DATA auto const mapping = Unicode::code_point_decomposition(code_point); if (mapping.has_value() && (mapping->tag == CompatibilityFormattingTag::Canonical || use_compatibility == UseCompatibility::Yes)) { for (auto code_point : mapping->decomposition) { @@ -155,6 +166,7 @@ static void decompose_code_point(u32 code_point, Vector& code_points_output } else { code_points_output.append(code_point); } +#endif } // This can be any sorting algorithm that maintains order (like std::stable_sort),