I use ICU4C in a C++ software builded under Windows, Linux and Mac-OSX.
I have an issue ONLY under Mac-OSX, and only related to conversion between UTF16 and WCS (calling u_strToWCS ).
Simply the unicoded chars are replaced with a fixed char.
The ICU4C version doesn’t matter: i try the lastest yesterday.
My Mac OS-X is 10.6.6 (Snow Leopard), GCC: i686-apple-darwin10-gcc-4.2.1.
I also try to switch between shared libraries and static libraries, without any changes.
I reproduce the issue with the code below. Look the variables “c1”, “c2” and “c3”: Windows and Linux give the same result, Mac OS-X not (my issue).
I don’t understand if is a compilation problem, or icu bug, or whatelse.
I hope anyone can suggest to me a direction, or at least confirm my test results.
Thanks.
// 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
}
See this bug. This had been already fixed in latest ICU and I’ve included a workaround. https://ssl.icu-project.org/trac/ticket/8894#comment:4