/// Convert UTF-16 to UTF-8. utf8_string Halyard::utf8_from_utf16(const utf16_string &utf16) { utf8_string result; result.reserve(utf16.size()); // Output our characters. for (size_t i = 0; i < utf16.size(); i++) { wchar_t wc = utf16[i]; if (wc <= 0x007F) { result.push_back(wc & 0x7F); } else if (wc <= 0x07FF) { // 110xxxxx 10xxxxxx result.push_back(0xC0 | (wc >> 6)); result.push_back(0x80 | (wc & 0x3F)); } else if (wc <= 0xFFFF) {
inline string_t utf(utf16_string const& str) { return aux::converter<char_t>::utf(str.c_str(), str.size()); }
inline utf32_string utf32(utf16_string const& str) { return aux::converter<utf32_char>::utf(str.c_str(), str.size()); }