Commit 423cd590 authored by Max Kellermann's avatar Max Kellermann

lib/icu/Util: fold UCharToUTF8Throw() into UCharToUTF8()

parent b9f535cd
......@@ -100,7 +100,7 @@ DoConvert(iconv_t conv, const char *src)
AllocatedString<char>
IcuConverter::ToUTF8(const char *s) const
{
try {
#ifdef HAVE_ICU
const ScopeLock protect(mutex);
......@@ -123,6 +123,8 @@ IcuConverter::ToUTF8(const char *s) const
#elif defined(HAVE_ICONV)
return DoConvert(to_utf8, s);
#endif
} catch (const std::runtime_error &) {
return nullptr;
}
AllocatedString<char>
......
......@@ -69,28 +69,6 @@ UCharToUTF8(ConstBuffer<UChar> src)
src.data, src.size,
&error_code);
if (U_FAILURE(error_code))
return nullptr;
dest[dest_length] = 0;
return AllocatedString<>::Donate(dest.release());
}
AllocatedString<>
UCharToUTF8Throw(ConstBuffer<UChar> src)
{
assert(!src.IsNull());
/* worst-case estimate */
size_t dest_capacity = 4 * src.size;
std::unique_ptr<char[]> dest(new char[dest_capacity + 1]);
UErrorCode error_code = U_ZERO_ERROR;
int32_t dest_length;
u_strToUTF8(dest.get(), dest_capacity, &dest_length,
src.data, src.size,
&error_code);
if (U_FAILURE(error_code))
throw std::runtime_error(u_errorName(error_code));
dest[dest_length] = 0;
......
......@@ -36,16 +36,10 @@ UCharFromUTF8(const char *src);
/**
* Wrapper for u_strToUTF8().
*/
AllocatedString<char>
UCharToUTF8(ConstBuffer<UChar> src);
/**
* Wrapper for u_strToUTF8().
*
* Throws std::runtime_error on error.
*/
AllocatedString<char>
UCharToUTF8Throw(ConstBuffer<UChar> src);
UCharToUTF8(ConstBuffer<UChar> src);
#endif
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