I am currently writing a plugin that is only a wrapper around an existing library. The host plugin passes me a utf-16 formatted string, defined as the following
typedef unsigned short PA_Unichar;
And the wrapped library only accepts a formatted string const char * or std :: string utf-8 I tried to write a conversion function like
std::string toUtf8(const PA_Unichar* data) { std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert; return std::string(convert.to_bytes(static_cast<const char16_t*>(data)); }
But obviously this will not work, throwing me into the compilation error "static_cast from" const pointer "(aka 'const unsigned short *') to 'const char16_t *' is not allowed
What is the most elegant / correct way to do this?
Thanks in advance.
source share