0
我在Windows,Linux和Mac-OSX下的C++軟件中使用ICU4C。 我只有在Mac-OSX下有問題,並且只與UTF16和WCS(調用u_strToWCS)之間的轉換有關。 只需將統一字符替換爲固定字符即可。Unicode ICU4C UTF16與WCS之間的轉換問題(僅適用於OS-X)
ICU4C版本並不重要:我昨天試了最新的。
我的Mac OS-X是10.6.6(Snow Leopard),GCC:i686-apple-darwin10-gcc-4.2.1。
我也嘗試在共享庫和靜態庫之間切換,沒有任何改變。
我重現了以下代碼的問題。查看變量「c1」,「c2」和「c3」:Windows和Linux給出了相同的結果,Mac OS-X沒有(我的問題)。
我不明白是編譯問題,還是icu錯誤或whatelse。
我希望任何人都可以向我建議一個方向,或者至少確認我的測試結果。
謝謝。
// 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
}
這也是提交在http://bugs.icu-project.org/trac/ticket/8894 –
耶,我得到了錯誤。 –