39#include <unicode/unistr.h>
51template <
typename string = std::
string>
52auto toUTF8(
const icu::UnicodeString& s) ->
string {
54 return s.toUTF8String(res);
66template <
typename string>
77template <
typename string = std::u32
string>
78auto toUTF32(
const icu::UnicodeString& s) ->
string {
79 string res(s.countChar32(),
'\0');
80 UErrorCode ec{U_ZERO_ERROR};
81 s.toUTF32(&res[0], res.size(), ec);
98template <
typename string>
107namespace icu_str_ops {
117 inline auto operator<<(std::ostream& os,
const icu::UnicodeString& str)
126 inline auto operator+(std::string lhs,
const icu::UnicodeString& str)
128 return str.toUTF8String(lhs);
134 inline auto operator+(icu::UnicodeString lhs,
const std::string& rhs)
135 -> icu::UnicodeString {
149auto fromStr(
const icu::UnicodeString& val,
const char* type =
typeid(T).name())
151 return fromStr<T>(
toUTF8(val), type);
auto operator+(icu::UnicodeString lhs, const std::string &rhs) -> icu::UnicodeString
auto operator<<(std::ostream &os, const icu::UnicodeString &str) -> std::ostream &
Provides a transcoding stream insertion operator for UnicodeStrings.
auto toUTF32(const icu::UnicodeString &s) -> string
Converts a UnicodeString to UTF-32.
auto toUTF8(const icu::UnicodeString &s) -> string
Convert a UnicodeString to a UTF-8 string.
auto fromStr(const icu::UnicodeString &val, const char *type=typeid(T).name()) -> T
Reencodes val to UTF-8 and then converts it to T using the primary overload.
auto fromUTF8(string s) -> icu::UnicodeString
Convert a UTF-8 string into a UnicodeString.
auto fromUTF32(string s) -> icu::UnicodeString
Converts a UTF-32 string into a UnicodeString.
Provides macros and basic templates used by the rest of kblib.