Question

I need to convert a UTF-16 string to a UTF-8 string.

const unsigned short *utf16string = ...;
const char *utf8string = convertUTF16toUTF8(utf16string);

Can anybody help me find/write the function const char* convertUTF16toUTF8(const unsigned short* utf16string)?

The types can't be changed, unfortunately, and I don't have access to C++11. I've been beating my head at this for hours and can't find any solutions.

Please help me. I believe in you, StackOverflow!

P.S. If anybody needs to know, I'm making a game using cocos2d-x and I'm trying to get a string using the JNI callbacks. JNI has a UTF version of the GetString... functions, yet these are buggy according to my own experience and Wikipedia, so I need to convert the strings using the raw functions.

Was it helpful?

Solution

If you want a simple and small C++ library you could use UTF8-CPP to convert between UTF-8 and UTF-16.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top