首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于UTF16和WCS之间转换的Unicode ICU4C问题(仅限OS-X)

关于UTF16和WCS之间转换的Unicode ICU4C问题(仅限OS-X)
EN

Stack Overflow用户
提问于 2011-10-19 21:12:47
回答 1查看 188关注 0票数 0

我在一个基于Windows、Linux和Mac-OSX的C++软件中使用ICU4C。我只在Mac-OSX下有一个问题,并且只与UTF16和WCS之间的转换有关(调用u_strToWCS )。简单地将单码字符替换为固定字符。

ICU4C版本无关紧要:我昨天尝试了最新的版本。

我的Mac X是10.6.6 (雪豹),GCC: i686-apple-darwin10-gcc-4.2.1。

我还尝试在共享库和静态库之间切换,而不做任何更改。

我用下面的代码重现了这个问题。看看变量"c1","c2“和"c3":Windows和Linux给出了相同的结果,Mac X不是(我的问题)。

我不知道是编译问题,还是icu bug,或者其他什么问题。

我希望任何人能给我一个方向的建议,或者至少确认我的测试结果。

谢谢。

代码语言:javascript
复制
    // Manually construct UTF16 buffer of this string: http://pastebin.com/HW06TaA9
    unsigned char* pSource = new unsigned char[28];
    pSource[0] = 84;
    pSource[1] = 0;
    pSource[2] = 101;
    pSource[3] = 0;
    pSource[4] = 115;
    pSource[5] = 0;
    pSource[6] = 116;
    pSource[7] = 0;
    pSource[8] = 32;
    pSource[9] = 0;
    pSource[10] = 179;
    pSource[11] = 111;
    pSource[12] = 128;
    pSource[13] = 149;
    pSource[14] = 121;
    pSource[15] = 114;
    pSource[16] = 43;
    pSource[17] = 82;
    pSource[18] = 76;
    pSource[19] = 136;
    pSource[20] = 63;
    pSource[21] = 101;
    pSource[22] = 64;
    pSource[23] = 83;
    pSource[24] = 125;
    pSource[25] = 0;
    pSource[26] = 0;
    pSource[27] = 0;

    int32_t nChars = 100;
    wchar_t* pDest = new wchar_t[nChars];
    memset(pDest, 0, nChars * sizeof(wchar_t));

    UErrorCode status = U_ZERO_ERROR;
    u_strToWCS(pDest, nChars, &nChars, (const UChar*) pSource, -1, &status);
    if(U_SUCCESS(status))
    {
        wchar_t c1 = pDest[2];  // Ascii char. Win: 115, Linux: 115, OS-X: 115 
        wchar_t c2 = pDest[5];  // Japan char. Win: 28595, Linux: 28595, OS-X: 26
        wchar_t c3 = pDest[6];   // Japan char. Win: 38272, Linux: 38272, OS-X: 26
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-09 10:42:25

请看这个bug。这个问题已经在最新的ICU中解决了,我已经包含了一个变通方法。https://ssl.icu-project.org/trac/ticket/8894#comment:4

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7821820

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档