diff options
author | Max Kellermann <max@duempel.org> | 2015-06-25 22:43:55 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-06-25 23:44:16 +0200 |
commit | 8d11577ff2b7caf846a31cbb57b2cf9eb3515961 (patch) | |
tree | 8e1173e9bdb131ddba5e5166b96ee4681bc00d53 /src/lib/icu/Util.cxx | |
parent | 037d1d9ad14969947b1a9456dc716b6a22021d29 (diff) | |
download | mpd-8d11577ff2b7caf846a31cbb57b2cf9eb3515961.tar.gz mpd-8d11577ff2b7caf846a31cbb57b2cf9eb3515961.tar.xz mpd-8d11577ff2b7caf846a31cbb57b2cf9eb3515961.zip |
lib/icu/{Converter,Collate}: return AllocatedString
Diffstat (limited to '')
-rw-r--r-- | src/lib/icu/Util.cxx | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/icu/Util.cxx b/src/lib/icu/Util.cxx index ae47423ad..92f1de5aa 100644 --- a/src/lib/icu/Util.cxx +++ b/src/lib/icu/Util.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "Util.hxx" +#include "util/AllocatedString.hxx" #include "util/WritableBuffer.hxx" #include "util/ConstBuffer.hxx" @@ -49,7 +50,7 @@ UCharFromUTF8(const char *src) return { dest, size_t(dest_length) }; } -WritableBuffer<char> +AllocatedString<> UCharToUTF8(ConstBuffer<UChar> src) { assert(!src.IsNull()); @@ -57,7 +58,7 @@ UCharToUTF8(ConstBuffer<UChar> src) /* worst-case estimate */ size_t dest_capacity = 4 * src.size; - char *dest = new char[dest_capacity]; + char *dest = new char[dest_capacity + 1]; UErrorCode error_code = U_ZERO_ERROR; int32_t dest_length; @@ -68,5 +69,6 @@ UCharToUTF8(ConstBuffer<UChar> src) return nullptr; } - return { dest, size_t(dest_length) }; + dest[dest_length] = 0; + return AllocatedString<>::Donate(dest); } |