Commit 21f17270 authored by Max Kellermann's avatar Max Kellermann

lib/icu/Util: UCharFromUTF8() throws on error

parent 423cd590
......@@ -99,13 +99,16 @@ IcuCollate(const char *a, const char *b)
#else
/* fall back to ucol_strcoll() */
const auto au = UCharFromUTF8(a);
const auto bu = UCharFromUTF8(b);
try {
const auto au = UCharFromUTF8(a);
const auto bu = UCharFromUTF8(b);
return !au.IsNull() && !bu.IsNull()
? (int)ucol_strcoll(collator, au.begin(), au.size(),
bu.begin(), bu.size())
: strcasecmp(a, b);
return ucol_strcoll(collator, au.begin(), au.size(),
bu.begin(), bu.size());
} catch (const std::runtime_error &) {
/* fall back to plain strcasecmp() */
return strcasecmp(a, b);
}
#endif
#elif defined(WIN32)
......
......@@ -129,7 +129,7 @@ try {
AllocatedString<char>
IcuConverter::FromUTF8(const char *s) const
{
try {
#ifdef HAVE_ICU
const ScopeLock protect(mutex);
......@@ -156,6 +156,8 @@ IcuConverter::FromUTF8(const char *s) const
#elif defined(HAVE_ICONV)
return DoConvert(from_utf8, s);
#endif
} catch (const std::runtime_error &) {
return nullptr;
}
#endif
......@@ -47,7 +47,7 @@ UCharFromUTF8(const char *src)
src, src_length,
&error_code);
if (U_FAILURE(error_code))
return {};
throw std::runtime_error(u_errorName(error_code));
dest.SetSize(dest_length);
return dest;
......
......@@ -30,6 +30,8 @@ template<typename T> class AllocatedString;
/**
* Wrapper for u_strFromUTF8().
*
* Throws std::runtime_error on error.
*/
AllocatedArray<UChar>
UCharFromUTF8(const char *src);
......
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