From c7712e2ef0232a39786075dbf6683120cfe5cc0a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 25 Jun 2015 23:01:29 +0200 Subject: [PATCH] lib/icu/Collate: fall back to strxfrm() --- src/lib/icu/Collate.cxx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib/icu/Collate.cxx b/src/lib/icu/Collate.cxx index 455f346b7..207252935 100644 --- a/src/lib/icu/Collate.cxx +++ b/src/lib/icu/Collate.cxx @@ -180,8 +180,22 @@ IcuCaseFold(const char *src) std::string result(tmp); g_free(tmp); #else - std::string result(src); - std::transform(result.begin(), result.end(), result.begin(), tolower); + size_t size = strlen(src) + 1; + auto buffer = new char[size]; + size_t nbytes = strxfrm(buffer, src, size); + if (nbytes >= size) { + /* buffer too small - reallocate and try again */ + delete[] buffer; + size = nbytes + 1; + buffer = new char[size]; + nbytes = strxfrm(buffer, src, size); + } + + assert(nbytes < size); + assert(buffer[nbytes] == 0); + + std::string result(buffer, nbytes); + delete[] buffer; #endif return result; }