summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2016-04-21 10:58:21 +0200
committerMax Kellermann <max@duempel.org>2016-04-21 10:58:21 +0200
commit423cd5900ede4ec304a316e4c490b3dc0af92b1b (patch)
tree321a055a9a505b3fa9f2ff01f2cd087bc884370e /src
parentb9f535cd4935edea8c3402e39d864231efbb2580 (diff)
lib/icu/Util: fold UCharToUTF8Throw() into UCharToUTF8()
Diffstat (limited to 'src')
-rw-r--r--src/lib/icu/Converter.cxx4
-rw-r--r--src/lib/icu/Util.cxx22
-rw-r--r--src/lib/icu/Util.hxx8
3 files changed, 4 insertions, 30 deletions
diff --git a/src/lib/icu/Converter.cxx b/src/lib/icu/Converter.cxx
index cb818d375..7d1a45382 100644
--- a/src/lib/icu/Converter.cxx
+++ b/src/lib/icu/Converter.cxx
@@ -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>
diff --git a/src/lib/icu/Util.cxx b/src/lib/icu/Util.cxx
index bd276756a..9a8c44b9c 100644
--- a/src/lib/icu/Util.cxx
+++ b/src/lib/icu/Util.cxx
@@ -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;
diff --git a/src/lib/icu/Util.hxx b/src/lib/icu/Util.hxx
index c72d6330f..bae694bc6 100644
--- a/src/lib/icu/Util.hxx
+++ b/src/lib/icu/Util.hxx
@@ -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