Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBL-3865: Remove Win32 Unicode implementation in favor of ICU #1623

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions LiteCore/Storage/UnicodeCollator_ICU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace litecore {
using namespace fleece;




class ICUCollationContext : public CollationContext {
public:
UCollator* ucoll {nullptr};
Expand Down Expand Up @@ -135,6 +137,7 @@ namespace litecore {


bool ContainsUTF8(fleece::slice str, fleece::slice substr, const CollationContext &ctx) {

// FIXME: This is quite slow! Call ICU instead
return ContainsUTF8_Slow(str, substr, ctx);
}
Expand Down
187 changes: 0 additions & 187 deletions LiteCore/Storage/UnicodeCollator_winapi.cc

This file was deleted.

File renamed without changes.
24 changes: 24 additions & 0 deletions LiteCore/Unix/icu_shim.h → LiteCore/Support/icu_shim.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
#if LITECORE_USES_ICU

#ifdef _MSC_VER
#include <icu.h>
#else
#include <unicode/ucol.h>
#include <unicode/ucasemap.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _MSC_VER

// ICU is a part of Windows since Windows 10 1709, no need to shim
// since it is not ultra hard versioned like its Linux counterpart

#define lc_ucol_open ucol_open
#define lc_ucol_setAttribute ucol_setAttribute
#define lc_ucol_close ucol_close
#define lc_ucol_strcollUTF8 ucol_strcollUTF8
#define lc_ucasemap_open ucasemap_open
#define lc_ucasemap_utf8ToUpper ucasemap_utf8ToUpper
#define lc_ucasemap_utf8ToLower ucasemap_utf8ToLower
#define lc_ucasemap_close ucasemap_close
#define lc_ucol_countAvailable ucol_countAvailable
#define lc_ucol_getAvailable ucol_getAvailable

#else

UCollator* lc_ucol_open(const char* loc, UErrorCode* status);
void lc_ucol_setAttribute(UCollator* coll, UColAttribute attr, UColAttributeValue value, UErrorCode* status);
void lc_ucol_close(UCollator* coll);
Expand All @@ -18,6 +40,8 @@ void lc_ucasemap_close(UCaseMap* csm);
int32_t lc_ucol_countAvailable(void);
const char* lc_ucol_getAvailable(int32_t localeIndex);

#endif

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions LiteCore/tests/SQLiteFunctionsTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ TEST_CASE("Unicode string functions", "[Query]") {
CHECK(UTF8ChangeCase("E"_sl, true) == "E"_sl);
CHECK(UTF8ChangeCase("-"_sl, true) == "-"_sl);
CHECK(UTF8ChangeCase("Z•rGMai2"_sl, true) == "Z•RGMAI2"_sl);
#if __APPLE__ || defined(_MSC_VER) || LITECORE_USES_ICU
#if __APPLE__ || LITECORE_USES_ICU
CHECK(UTF8ChangeCase("Zérgmåī2"_sl, true) == "ZÉRGMÅĪ2"_sl);
#endif
CHECK(UTF8ChangeCase("😀"_sl, true) == "😀"_sl);
Expand All @@ -362,7 +362,7 @@ TEST_CASE("Unicode string functions", "[Query]") {
CHECK(UTF8ChangeCase("e"_sl, false) == "e"_sl);
CHECK(UTF8ChangeCase("-"_sl, false) == "-"_sl);
CHECK(UTF8ChangeCase("Z•rGMai2"_sl, false) == "z•rgmai2"_sl);
#if __APPLE__ || defined(_MSC_VER)|| LITECORE_USES_ICU
#if __APPLE__ || LITECORE_USES_ICU
CHECK(UTF8ChangeCase("zÉRGMÅĪ2"_sl, false) == "zérgmåī2"_sl);
#endif
CHECK(UTF8ChangeCase("😀"_sl, false) == "😀"_sl);
Expand Down Expand Up @@ -411,7 +411,7 @@ N_WAY_TEST_CASE_METHOD(SQLiteFunctionsTest, "SQLite fl_blob", "[Query]") {
#pragma mark - COLLATION:


#if __APPLE__ || defined(_MSC_VER) || LITECORE_USES_ICU
#if __APPLE__ || LITECORE_USES_ICU
TEST_CASE("Unicode collation", "[Query][Collation]") {
struct {slice a; slice b; int result; bool caseSensitive; bool diacriticSensitive;} tests[] = {
//---- First, test just ASCII:
Expand Down
5 changes: 5 additions & 0 deletions LiteCore/tests/cmake/platform_win.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ function(setup_build)
CppTests PRIVATE
${TOP}MSVC
)

target_compile_definitions(
CppTests PRIVATE
-DLITECORE_USES_ICU=1
)
endfunction()
2 changes: 1 addition & 1 deletion cmake/platform_android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function(set_litecore_source)
set(
${ANDROID_SSS_RESULT}
${BASE_LITECORE_FILES}
LiteCore/Unix/icu_shim.c
LiteCore/Support/icu_shim.c
LiteCore/Android/getifaddrs.cc
LiteCore/Android/bionic_netlink.cc
PARENT_SCOPE
Expand Down
2 changes: 1 addition & 1 deletion cmake/platform_linux_desktop.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function(set_litecore_source)
set(
${LINUX_SSS_RESULT}
${BASE_LITECORE_FILES}
LiteCore/Unix/icu_shim.c
LiteCore/Support/icu_shim.c
PARENT_SCOPE
)
endfunction()
Expand Down
6 changes: 4 additions & 2 deletions cmake/platform_win.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ function(set_litecore_source)
set(
${WIN_SSS_RESULT}
${BASE_LITECORE_FILES}
LiteCore/Storage/UnicodeCollator_winapi.cc
LiteCore/Storage/UnicodeCollator_ICU.cc
MSVC/mkstemp.cc
MSVC/mkdtemp.cc
MSVC/strlcat.c
LiteCore/Support/StringUtil_winapi.cc
LiteCore/Support/StringUtil_icu.cc
Crypto/PublicKey+Windows.cc
PARENT_SCOPE
)
Expand Down Expand Up @@ -57,6 +57,7 @@ function(setup_litecore_build_win)
-D_USE_MATH_DEFINES # Define math constants like PI
-DWIN32 # Identify as WIN32
-DNOMINMAX # Disable min/max macros (they interfere with std::min and max)
-DLITECORE_USES_ICU=1
)

target_compile_definitions(
Expand Down Expand Up @@ -84,6 +85,7 @@ function(setup_litecore_build_win)
Ws2_32
ncrypt
crypt32
icu
)

# Compile string literals as UTF-8,
Expand Down