diff options
author | Max Kellermann <max@duempel.org> | 2015-06-23 11:37:25 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-06-23 13:20:41 +0200 |
commit | 090ce262c4950236996787c588b0f3ef1dbceb64 (patch) | |
tree | d658caa669b9a160e827be052d0e956961054bbb /src | |
parent | d551d40886f50f83f5893891e8ed15b2dd786cf6 (diff) | |
download | mpd-090ce262c4950236996787c588b0f3ef1dbceb64.tar.gz mpd-090ce262c4950236996787c588b0f3ef1dbceb64.tar.xz mpd-090ce262c4950236996787c588b0f3ef1dbceb64.zip |
lib/icu/Collate: use CompareStringEx() on Windows
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/icu/Collate.cxx | 26 |
1 files changed, 26 insertions, 0 deletions
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 <ctype.h> #endif +#ifdef WIN32 +#include "Win32.hxx" +#include "util/AllocatedString.hxx" +#include <windows.h> +#endif + #include <assert.h> #include <string.h> #include <strings.h> @@ -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 |