Question

I am working on porting some legacy C++ code to Android platform. While doing so, I noticed that the code uses iconv_xxx() routines to deal with Unicode conversions. It so happens that Android NDK does not have iconv.h by default. I can download and build the source code for libiconv. However, I am just wondering why would one even bother using iconv_xxx functions when C++ compilers on almost all platforms support mbstowcs, wcstombs. and the related routines. Do iconv_xxx functions offer any advantage over mbsXXXwbsXXX routines? Regards.

Was it helpful?

Solution

The mb/wc functions convert between the wchar_t encoding, which is platform-specific, and the multibyte encoding, which is platform and locale-specific.

On Linux on x86, wc is likely to be UTF-32LE and mb is most likely, but far from guaranteed, to be UTF-8. On Windows, wc is UTF-16LE; mb is likely to be the machine's default locale (ANSI) code page and vanishingly unlikely to be UTF-8.

So if you want to convert to or from known, specific encodings, you have to use iconv().

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