lib/icu/Transliterator: pass std::basic_string_view<UChar> to constructor

This commit is contained in:
Max Kellermann 2022-11-15 20:40:29 +01:00
parent 5a1fbe60af
commit 852df2239e
2 changed files with 9 additions and 5 deletions

View File

@ -24,12 +24,14 @@
#include <stdexcept>
static UTransliterator *
OpenTransliterator(const UChar *id, const UChar *rules)
OpenTransliterator(std::basic_string_view<UChar> id,
std::basic_string_view<UChar> rules)
{
UErrorCode error_code = U_ZERO_ERROR;
UTransliterator *t = utrans_openU(id, -1, UTRANS_FORWARD,
rules, -1,
UTransliterator *t = utrans_openU(id.data(), id.size(),
UTRANS_FORWARD,
rules.data(), rules.size(),
nullptr, &error_code);
if (t == nullptr)
throw std::runtime_error(u_errorName(error_code));
@ -37,7 +39,8 @@ OpenTransliterator(const UChar *id, const UChar *rules)
return t;
}
IcuTransliterator::IcuTransliterator(const UChar *id, const UChar *rules)
IcuTransliterator::IcuTransliterator(std::basic_string_view<UChar> id,
std::basic_string_view<UChar> rules)
:transliterator(OpenTransliterator(id, rules))
{
}

View File

@ -41,7 +41,8 @@ public:
/**
* Throws on error.
*/
IcuTransliterator(const UChar *id, const UChar *rules);
IcuTransliterator(std::basic_string_view<UChar> id,
std::basic_string_view<UChar> rules);
~IcuTransliterator() noexcept {
if (transliterator != nullptr)