Take the 2-minute tour ×

I have legacy C code that does text processing. All rules and data are encoded in ISO-8859-7. Now, I am trying to port to android. I have build the appropriate JNI function that GetStringUTFChars(). This const char* seems to be UTF-8. So, I need to convert to ISO.

In Windows, I have a function that converts utf-8 (const char*) to wchar_t and then I use wcstombs() to convert to ISO. But, this does not work under Android, I also read that wchar_t is not safe.

So, how can I perform this conversion?

Thank you

share|improve this question
Why would wcstombs not work? –  David Heffernan Dec 17 '12 at 11:34
@DavidHeffernan ISO-8859-7 is a multi-byte string but wcstombs looks like it expects a wide string. –  simonc Dec 17 '12 at 11:39
Look up if iconv library is available on Android –  EarlGray Dec 17 '12 at 11:40
@simonc My point is that wcstombs is the same everywhere. Perhaps the issue is that the utf8 -> utf16 part isn't available on Android. But I think I'd want to use a conversion library that did the conversion in a single step. So, iconv would be a good choice. –  David Heffernan Dec 17 '12 at 11:46
iconv seems too-much complicated to (compile and) use in my app. The easiest solution was to implement a lookup table. Thank you for your replies. –  Tsiftis Karampouzouklis Dec 18 '12 at 11:21
add comment

1 Answer

To get from UTF-8 to ISO-8859-7. First convert from UTF-8 to native unicode and then from native unicode to ISO-8859-7. However, UTF-8 potentially allows over 60000 code points from almost all modern scripts while ISO-8859-7 allows only 256. Therefore, you should be aware of data loss and try to keep your data in unicode/UTF-8, if possible.

As of now, you can use any android specific API if available(I am aware of a iconv-android API) or the GNU C libiconv library for your conversions.

share|improve this answer
add comment

Your Answer


