aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-06-27 15:52:37 +0200
committerMax Kellermann <max@duempel.org>2015-06-27 15:52:37 +0200
commitfb3564fbe76a10a0825bd06c0ff19f481d94b835 (patch)
treed95f698fedada944987880cbe985c6bce58d4dcb
parente1e365e16eea5f92bea8919bf1c81d6fc192eea3 (diff)
downloadmpd-fb3564fbe76a10a0825bd06c0ff19f481d94b835.tar.gz
mpd-fb3564fbe76a10a0825bd06c0ff19f481d94b835.tar.xz
mpd-fb3564fbe76a10a0825bd06c0ff19f481d94b835.zip
lib/icu/Collate: use LCMapStringEx() on Windows
-rw-r--r--src/lib/icu/Collate.cxx29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/icu/Collate.cxx b/src/lib/icu/Collate.cxx
index 0df305130..97a5766d8 100644
--- a/src/lib/icu/Collate.cxx
+++ b/src/lib/icu/Collate.cxx
@@ -172,6 +172,35 @@ IcuCaseFold(const char *src)
auto result = UCharToUTF8({folded, folded_length});
delete[] folded;
return result;
+
+#elif defined(WIN32)
+ const auto u = MultiByteToWideChar(CP_UTF8, src);
+ if (u.IsNull())
+ return AllocatedString<>::Duplicate(src);
+
+ const int size = LCMapStringEx(LOCALE_NAME_INVARIANT,
+ LCMAP_SORTKEY|LINGUISTIC_IGNORECASE,
+ u.c_str(), -1, nullptr, 0,
+ nullptr, nullptr, 0);
+ if (size <= 0)
+ return AllocatedString<>::Duplicate(src);
+
+ auto buffer = new wchar_t[size];
+ if (LCMapStringEx(LOCALE_NAME_INVARIANT,
+ LCMAP_SORTKEY|LINGUISTIC_IGNORECASE,
+ u.c_str(), -1, buffer, size,
+ nullptr, nullptr, 0) <= 0) {
+ delete[] buffer;
+ return AllocatedString<>::Duplicate(src);
+ }
+
+ auto result = WideCharToMultiByte(CP_UTF8, buffer);
+ delete[] buffer;
+ if (result.IsNull())
+ return AllocatedString<>::Duplicate(src);
+
+ return result;
+
#elif defined(HAVE_GLIB)
char *tmp = g_utf8_casefold(src, -1);
auto result = AllocatedString<>::Duplicate(tmp);