Mac OS X上的iconv库:奇怪的行为 [英] iconv library on Mac OS X: strange behavior

查看:346
本文介绍了Mac OS X上的iconv库:奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将应用程序从CentOS 6移植到Mac OS X.它取决于iconv,并在CentOS中正常工作。然而,在Mac OS X它不。我看到以下行为:

I am porting application from CentOS 6 to Mac OS X. It depends on iconv and works in CentOS normally. However, on Mac OS X it doesn't. I see following behavior:

const char *codePages[] = { "MAC", "LATIN1", "ISO_8859-1", "WINDOWS-1252", "ASCII" };
int codePagesCount = 5;
iconv_t converter1 = iconv_open("UTF-32", codePages[0]);// Works
if(converter1 != (iconv_t)-1)
   iconv_close(converter1);
iconv_t converter2 = iconv_open("UTF−32", "MAC");// Fails, returns -1
if(converter2 != (iconv_t)-1)
   iconv_close(converter2);

这段代码看起来很简单:第一个iconv_open创建转换器并从codePages数组获取代码页名称,它的零元素是MAC,所以对我来说,Mac OS X必须支持从自己的代码页到Unicode的转换是逻辑的。和第一次调用iconv_open工作。
然而,第二次调用iconv_open也是一样。它还创建从Mac编码转换为Unicode。并且由于任何原因它失败并返回-1。
当调用具有相同参数的相同函数(一个是硬编码数组的元素,另一个是硬编码字符串)时,会导致第一次调用的正常功能和第二次调用的失败的原因可能是这种情况的原因?

This piece of code looks trivial: the first iconv_open creates converter and gets code page name from codePages array, its zero element is MAC, so it is logical for me that Mac OS X must support conversion from its own code page to Unicode. And the first call to iconv_open works. However, the second call to iconv_open does the same. It also creates converter from Mac encoding to Unicode. And for any reason it fails and returns -1. What may be the reason of such situation when call to the same function with the same arguments (one is element of hardcoded array, another one is hardcoded string) results in normal functionality for the first call and failure for the second one?

推荐答案

第二个UTF-32不同于第一个:第一个使用一个简单的减号,第二个使用endash我猜。

The second "UTF-32" is not the same as the first: the first one uses a plain minus sign whereas the second one uses an endash I guess.

这篇关于Mac OS X上的iconv库:奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆