开发者

What API's are available to do charset conversion on MacOSX? (iconv not working for me)

In the context of an email client I need to convert to / from lots of different charsets and unicode. So far on windows and linux I've been using iconv to do the conversions of text between charsets. However on the mac the first conversion I tried, from cp932 to utf-16 failed with a bunch of garbage characters. I had a google around and some people were suggesting setting the locale first using setlocale, but that didn't seem to affect things.

Maybe I shouldn't be using iconv on the mac at all? Is there a alternative API for charset conversion?

I'm open to suggestions on fixing the iconv code as well... code is basically along the lines of:

setlocale(LC_ALL,"")开发者_JAVA技巧;

iconv_t Conv;
if ((Conv = libiconv_open("utf-16", "cp932")) >= 0)
{
    // Convert
    int s = libiconv(Conv, &InBuf, (size_t*)&InLen, &OutBuf, (size_t*)&OutLen);
    libiconv_close(Conv);
}

Same input text on windows works fine, gives garbage on the mac.


CFString (-framework CoreFoundation) has character conversion APIs. Essentially, you create a CFString from your CP932 (kCFStringEncodingDOSJapanese) string then you can extract UTF-16 data from it.

More information here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜