Skip to content

Instantly share code, notes, and snippets.

@taxilian
Created July 29, 2011 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taxilian/1114451 to your computer and use it in GitHub Desktop.
Save taxilian/1114451 to your computer and use it in GitHub Desktop.
utf8 conversion tools
std::string wstring_to_utf8(const std::wstring& src) {
std::string out_str;
#ifdef _WIN32
utf8::utf16to8(src.begin(), src.end(), std::back_inserter(out_str));
#else
utf8::utf32to8(src.begin(), src.end(), std::back_inserter(out_str));
#endif
return out_str;
}
std::wstring utf8_to_wstring(const std::string& src) {
std::wstring out_str;
#ifdef _WIN32
utf8::utf8to16(src.begin(), src.end(), std::back_inserter(out_str));
#else
utf8::utf8to32(src.begin(), src.end(), std::back_inserter(out_str));
#endif
return out_str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment