简体   繁体   English

Mac OS X上的iconv库:奇怪的行为

[英]iconv library on Mac OS X: strange behavior

I am porting application from CentOS 6 to Mac OS X. It depends on iconv and works in CentOS normally. 我正在将应用程序从CentOS 6移植到Mac OSX。它取决于iconv,并且可以在CentOS中正常工作。 However, on Mac OS X it doesn't. 但是,在Mac OS X上则没有。 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);

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. 这段代码看起来微不足道:第一个iconv_open创建转换器并从codePages数组获取代码页名称,其零元素是MAC,所以我认为Mac OS X必须支持从其自己的代码页到Unicode的转换是合理的。 And the first call to iconv_open works. 并且对iconv_open的第一个调用有效。 However, the second call to iconv_open does the same. 但是,对iconv_open的第二次调用也是如此。 It also creates converter from Mac encoding to Unicode. 它还会创建从Mac编码到Unicode的转换器。 And for any reason it fails and returns -1. 并且由于任何原因它都会失败并返回-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”与第一个不同:我猜第一个使用普通的减号,而第二个使用内灰。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM