summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2016-04-12 22:07:23 +0200
committerMax Kellermann <max@duempel.org>2016-04-12 22:07:23 +0200
commita497cc46f9878bd41c84d717a5398767c7cc4dcf (patch)
tree5f19766d60c0c3c645d80d9b1982477d1c3052c6 /src/lib
parent178f737971148577beacd54a5dd743b2a5830074 (diff)
lib/icu/Util: use std::unique_ptr
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/icu/Util.cxx13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/lib/icu/Util.cxx b/src/lib/icu/Util.cxx
index 0823a21cc..57cf2f59f 100644
--- a/src/lib/icu/Util.cxx
+++ b/src/lib/icu/Util.cxx
@@ -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());
}