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