lib/icu/Util: use std::unique_ptr
This commit is contained in:
parent
178f737971
commit
a497cc46f9
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue