9 #ifndef META_UTF_DETAIL_H_
10 #define META_UTF_DETAIL_H_
15 #include <unicode/uclean.h>
16 #include <unicode/unistr.h>
32 auto status = U_ZERO_ERROR;
34 if (!U_SUCCESS(status))
35 throw std::runtime_error{
"Failed to initialize icu"};
66 std::u16string u16str;
67 u16str.resize(icu_str.length());
68 auto status = U_ZERO_ERROR;
72 icu_str.extract(reinterpret_cast<UChar*>(&u16str[0]), u16str.length(),
86 icu_str.toUTF8String(u8str);
97 std::array<uint8_t, U8_MAX_LENGTH> buf;
100 U8_APPEND(&buf[0], len, U8_MAX_LENGTH, codepoint, err);
102 throw std::runtime_error{
"failed to add codepoint to string"};
103 dest.append(reinterpret_cast<char*>(&buf[0]), len);