From 090ce262c4950236996787c588b0f3ef1dbceb64 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 23 Jun 2015 11:37:25 +0200 Subject: lib/icu/Collate: use CompareStringEx() on Windows --- src/lib/icu/Collate.cxx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/lib/icu/Collate.cxx b/src/lib/icu/Collate.cxx index ddb6313d6..902192c06 100644 --- a/src/lib/icu/Collate.cxx +++ b/src/lib/icu/Collate.cxx @@ -37,6 +37,12 @@ #include #endif +#ifdef WIN32 +#include "Win32.hxx" +#include "util/AllocatedString.hxx" +#include +#endif + #include #include #include @@ -107,6 +113,26 @@ IcuCollate(const char *a, const char *b) return result; #endif +#elif defined(WIN32) + const auto wa = MultiByteToWideChar(CP_UTF8, a); + const auto wb = MultiByteToWideChar(CP_UTF8, b); + if (wa.IsNull()) + return wb.IsNull() ? 0 : -1; + else if (wb.IsNull()) + return 1; + + auto result = CompareStringEx(LOCALE_NAME_INVARIANT, + LINGUISTIC_IGNORECASE, + wa.c_str(), -1, + wb.c_str(), -1, + nullptr, nullptr, 0); + if (result != 0) + /* "To maintain the C runtime convention of comparing + strings, the value 2 can be subtracted from a + nonzero return value." */ + result -= 2; + + return result; #elif defined(HAVE_GLIB) return g_utf8_collate(a, b); #else -- cgit v1.2.3