Commit 74963bce authored by Max Kellermann's avatar Max Kellermann

lib/icu/Collate: use class AllocatedArray

parent 33a4dbe1
...@@ -144,22 +144,18 @@ IcuCaseFold(const char *src) ...@@ -144,22 +144,18 @@ IcuCaseFold(const char *src)
if (u.IsNull()) if (u.IsNull())
return AllocatedString<>::Duplicate(src); return AllocatedString<>::Duplicate(src);
size_t folded_capacity = u.size() * 2u; AllocatedArray<UChar> folded(u.size() * 2u);
UChar *folded = new UChar[folded_capacity];
UErrorCode error_code = U_ZERO_ERROR; UErrorCode error_code = U_ZERO_ERROR;
size_t folded_length = u_strFoldCase(folded, folded_capacity, size_t folded_length = u_strFoldCase(folded.begin(), folded.size(),
u.begin(), u.size(), u.begin(), u.size(),
U_FOLD_CASE_DEFAULT, U_FOLD_CASE_DEFAULT,
&error_code); &error_code);
if (folded_length == 0 || error_code != U_ZERO_ERROR) { if (folded_length == 0 || error_code != U_ZERO_ERROR)
delete[] folded;
return AllocatedString<>::Duplicate(src); return AllocatedString<>::Duplicate(src);
}
auto result = UCharToUTF8({folded, folded_length}); folded.SetSize(folded_length);
delete[] folded; return UCharToUTF8({folded.begin(), folded.size()});
return result;
#elif defined(WIN32) #elif defined(WIN32)
const auto u = MultiByteToWideChar(CP_UTF8, src); const auto u = MultiByteToWideChar(CP_UTF8, src);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment