This is the way we are currently converting a UTF-16 to UTF-8 on Ubuntu 18.04.
The input is a const wchar_t*
(UTF-16) and the output is a const char*
(UTF-8):
const char* to_string(const wchar_t* input)
{
std::wstring w(input);
std::string s(w.begin(), w.end());
return strdup(s.c_str());
}
However, it doesn't seem to be working because I'm still seeing non UTF-8 encoded characters in my string. Example:
Adobe® Flash® Player
Is there a problem with the to_string
function above?