I\'m working on a native extension for a zinc based flash application and I need to convert a const char* to a wstring.
This is my code:
On OS X wstring uses UTF-32 rather than UTF-16. You can do the conversion like this:
#include
#include
// make facets usable by giving them a public destructor
template
class usable_facet
: public Facet
{
public:
template
usable_facet(Args&& ...args)
: Facet(std::forward(args)...) {}
~usable_facet() {}
};
std::wstring s2ws(std::string const &s) {
std::wstring_convert<
usable_facet>
,char32_t> convert;
std::u32string utf32 = convert.from_bytes(s);
static_assert(sizeof(wchar_t)==sizeof(char32_t),"char32_t and wchar_t must have same size");
return {begin(utf32),end(utf32)};
}