Commit a497cc46 authored by Max Kellermann's avatar Max Kellermann

lib/icu/Util: use std::unique_ptr

parent 178f7379
......@@ -26,6 +26,8 @@
#include <unicode/ustring.h>
#include <memory>
#include <assert.h>
#include <string.h>
......@@ -58,17 +60,16 @@ UCharToUTF8(ConstBuffer<UChar> src)
/* worst-case estimate */
size_t dest_capacity = 4 * src.size;
char *dest = new char[dest_capacity + 1];
std::unique_ptr<char[]> dest(new char[dest_capacity + 1]);
UErrorCode error_code = U_ZERO_ERROR;
int32_t dest_length;
u_strToUTF8(dest, dest_capacity, &dest_length, src.data, src.size,
u_strToUTF8(dest.get(), dest_capacity, &dest_length,
src.data, src.size,
&error_code);
if (U_FAILURE(error_code)) {
delete[] dest;
if (U_FAILURE(error_code))
return nullptr;
}
dest[dest_length] = 0;
return AllocatedString<>::Donate(dest);
return AllocatedString<>::Donate(dest.release());
}
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