/** * UTF-8 to UTF-32 conversion functions */ void CubeUtils::UTF32ToUTF8(const char_32 *utf32_str, string *str) { str->clear(); for (const char_32 *ch_32 = utf32_str; (*ch_32) != 0; ch_32++) { UNICHAR uni_ch((*ch_32)); char *utf8 = uni_ch.utf8_str(); if (utf8 != NULL) { (*str) += utf8; delete[]utf8; } } }
void UTF32ToUTF8(const GenericVector<char32>& str32, STRING* utf8_str) { utf8_str->ensure(str32.length()); utf8_str->assign("", 0); for (int i = 0; i < str32.length(); ++i) { UNICHAR uni_ch(str32[i]); char *utf8 = uni_ch.utf8_str(); if (utf8 != nullptr) { (*utf8_str) += utf8; delete[] utf8; } } }
/** * UTF-8 to UTF-32 conversion functions */ void CubeUtils::UTF8ToUTF32(const char *utf8_str, string_32 *str32) { str32->clear(); int len = strlen(utf8_str); int step = 0; for (int ch = 0; ch < len; ch += step) { step = UNICHAR::utf8_step(utf8_str + ch); if (step > 0) { UNICHAR uni_ch(utf8_str + ch, step); (*str32) += uni_ch.first_uni(); } } }
void UTF8ToUTF32(const char* utf8_str, GenericVector<char32>* str32) { str32->clear(); str32->reserve(strlen(utf8_str)); int len = strlen(utf8_str); int step = 0; for (int ch = 0; ch < len; ch += step) { step = UNICHAR::utf8_step(utf8_str + ch); if (step > 0) { UNICHAR uni_ch(utf8_str + ch, step); (*str32) += uni_ch.first_uni(); } } }
static string EncodeAsUTF8(const char32 ch32) { UNICHAR uni_ch(ch32); return string(uni_ch.utf8(), uni_ch.utf8_len()); }