ICU-12547 UCHAR_TYPE=char16_t on Windows, fix compilation problems.

X-SVN-Rev: 39217
This commit is contained in:
Andy Heninger 2016-09-13 21:37:40 +00:00
parent f334e613c1
commit 85f8d034a7
7 changed files with 53 additions and 32 deletions

View file

@ -51,6 +51,27 @@
*/
#include <stddef.h>
/*
* U_USE_CHAR16_T
* When defined, force use of char16_t for UChar.
* Note: char16_t is expected to become the default and required in the future,
* and this option will be removed.
* @internal
*/
#ifdef U_USE_CHAR16_T
#ifdef UCHAR_TYPE
#undef UCHAR_TYPE
#endif
#define UCHAR_TYPE char16_t
/*
* In plain C, <uchar.h> is needed for the definition of char16_t
*/
#ifndef __cplusplus
#include <uchar.h>
#endif
#endif
/*==========================================================================*/
/* For C wrappers, we use the symbol U_STABLE. */
/* This works properly if the includer is C or C++. */

View file

@ -260,7 +260,7 @@ u_strToWCS(wchar_t *dest,
*pDestLength = srcLength;
}
u_terminateUChars(dest,destCapacity,srcLength,pErrorCode);
u_terminateUChars((UChar *)dest,destCapacity,srcLength,pErrorCode);
return dest;
@ -506,7 +506,7 @@ u_strFromWCS(UChar *dest,
#ifdef U_WCHAR_IS_UTF16
/* wchar_t is UTF-16 just do a memcpy */
if(srcLength == -1){
srcLength = u_strlen(src);
srcLength = u_strlen((const UChar *)src);
}
if(0 < srcLength && srcLength <= destCapacity){
uprv_memcpy(dest,src,srcLength*U_SIZEOF_UCHAR);

View file

@ -993,7 +993,7 @@ U_CAPI int32_t U_EXPORT2
u_strlen(const UChar *s)
{
#if U_SIZEOF_WCHAR_T == U_SIZEOF_UCHAR
return (int32_t)uprv_wcslen(s);
return (int32_t)uprv_wcslen((const wchar_t *)s);
#else
const UChar *t = s;
while(*t != 0) {

View file

@ -232,8 +232,8 @@ static const DWORD dfFlags[] = {DATE_LONGDATE, DATE_LONGDATE, DATE_SHORTDATE, DA
void Win32DateFormat::formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const
{
int result;
UChar stackBuffer[STACK_BUFFER_SIZE];
UChar *buffer = stackBuffer;
wchar_t stackBuffer[STACK_BUFFER_SIZE];
wchar_t *buffer = stackBuffer;
result = GetDateFormatW(fLCID, dfFlags[fDateStyle - kDateOffset], st, NULL, buffer, STACK_BUFFER_SIZE);
@ -241,12 +241,12 @@ void Win32DateFormat::formatDate(const SYSTEMTIME *st, UnicodeString &appendTo)
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
int newLength = GetDateFormatW(fLCID, dfFlags[fDateStyle - kDateOffset], st, NULL, NULL, 0);
buffer = NEW_ARRAY(UChar, newLength);
buffer = NEW_ARRAY(wchar_t, newLength);
GetDateFormatW(fLCID, dfFlags[fDateStyle - kDateOffset], st, NULL, buffer, newLength);
}
}
appendTo.append(buffer, (int32_t) wcslen(buffer));
appendTo.append((const UChar *)buffer, (int32_t) wcslen(buffer));
if (buffer != stackBuffer) {
DELETE_ARRAY(buffer);
@ -258,8 +258,8 @@ static const DWORD tfFlags[] = {0, 0, 0, TIME_NOSECONDS};
void Win32DateFormat::formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const
{
int result;
UChar stackBuffer[STACK_BUFFER_SIZE];
UChar *buffer = stackBuffer;
wchar_t stackBuffer[STACK_BUFFER_SIZE];
wchar_t *buffer = stackBuffer;
result = GetTimeFormatW(fLCID, tfFlags[fTimeStyle], st, NULL, buffer, STACK_BUFFER_SIZE);
@ -267,12 +267,12 @@ void Win32DateFormat::formatTime(const SYSTEMTIME *st, UnicodeString &appendTo)
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
int newLength = GetTimeFormatW(fLCID, tfFlags[fTimeStyle], st, NULL, NULL, 0);
buffer = NEW_ARRAY(UChar, newLength);
buffer = NEW_ARRAY(wchar_t, newLength);
GetDateFormatW(fLCID, tfFlags[fTimeStyle], st, NULL, buffer, newLength);
}
}
appendTo.append(buffer, (int32_t) wcslen(buffer));
appendTo.append((const UChar *)buffer, (int32_t) wcslen(buffer));
if (buffer != stackBuffer) {
DELETE_ARRAY(buffer);

View file

@ -88,10 +88,10 @@ static void getNumberFormat(NUMBERFMTW *fmt, int32_t lcid)
GetLocaleInfoA(lcid, LOCALE_SGROUPING, buf, 10);
fmt->Grouping = getGrouping(buf);
fmt->lpDecimalSep = NEW_ARRAY(UChar, 6);
fmt->lpDecimalSep = NEW_ARRAY(wchar_t, 6);
GetLocaleInfoW(lcid, LOCALE_SDECIMAL, fmt->lpDecimalSep, 6);
fmt->lpThousandSep = NEW_ARRAY(UChar, 6);
fmt->lpThousandSep = NEW_ARRAY(wchar_t, 6);
GetLocaleInfoW(lcid, LOCALE_STHOUSAND, fmt->lpThousandSep, 6);
GetLocaleInfoW(lcid, LOCALE_RETURN_NUMBER|LOCALE_INEGNUMBER, (LPWSTR) &fmt->NegativeOrder, sizeof(UINT));
@ -115,16 +115,16 @@ static void getCurrencyFormat(CURRENCYFMTW *fmt, int32_t lcid)
GetLocaleInfoA(lcid, LOCALE_SMONGROUPING, buf, sizeof(buf));
fmt->Grouping = getGrouping(buf);
fmt->lpDecimalSep = NEW_ARRAY(UChar, 6);
fmt->lpDecimalSep = NEW_ARRAY(wchar_t, 6);
GetLocaleInfoW(lcid, LOCALE_SMONDECIMALSEP, fmt->lpDecimalSep, 6);
fmt->lpThousandSep = NEW_ARRAY(UChar, 6);
fmt->lpThousandSep = NEW_ARRAY(wchar_t, 6);
GetLocaleInfoW(lcid, LOCALE_SMONTHOUSANDSEP, fmt->lpThousandSep, 6);
GetLocaleInfoW(lcid, LOCALE_RETURN_NUMBER|LOCALE_INEGCURR, (LPWSTR) &fmt->NegativeOrder, sizeof(UINT));
GetLocaleInfoW(lcid, LOCALE_RETURN_NUMBER|LOCALE_ICURRENCY, (LPWSTR) &fmt->PositiveOrder, sizeof(UINT));
fmt->lpCurrencySymbol = NEW_ARRAY(UChar, 8);
fmt->lpCurrencySymbol = NEW_ARRAY(wchar_t, 8);
GetLocaleInfoW(lcid, LOCALE_SCURRENCY, (LPWSTR) fmt->lpCurrencySymbol, 8);
}
@ -292,8 +292,8 @@ UnicodeString &Win32NumberFormat::format(int32_t numDigits, UnicodeString &appen
}
}
UChar stackBuffer[STACK_BUFFER_SIZE];
UChar *buffer = stackBuffer;
wchar_t stackBuffer[STACK_BUFFER_SIZE];
wchar_t *buffer = stackBuffer;
FormatInfo formatInfo;
formatInfo = *fFormatInfo;
@ -316,7 +316,7 @@ UnicodeString &Win32NumberFormat::format(int32_t numDigits, UnicodeString &appen
if (lastError == ERROR_INSUFFICIENT_BUFFER) {
int newLength = GetCurrencyFormatW(fLCID, 0, nBuffer, &formatInfo.currency, NULL, 0);
buffer = NEW_ARRAY(UChar, newLength);
buffer = NEW_ARRAY(wchar_t, newLength);
buffer[0] = 0x0000;
GetCurrencyFormatW(fLCID, 0, nBuffer, &formatInfo.currency, buffer, newLength);
}
@ -336,14 +336,14 @@ UnicodeString &Win32NumberFormat::format(int32_t numDigits, UnicodeString &appen
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
int newLength = GetNumberFormatW(fLCID, 0, nBuffer, &formatInfo.number, NULL, 0);
buffer = NEW_ARRAY(UChar, newLength);
buffer = NEW_ARRAY(wchar_t, newLength);
buffer[0] = 0x0000;
GetNumberFormatW(fLCID, 0, nBuffer, &formatInfo.number, buffer, newLength);
}
}
}
appendTo.append(buffer, (int32_t) wcslen(buffer));
appendTo.append((UChar *)buffer, (int32_t) wcslen(buffer));
if (buffer != stackBuffer) {
DELETE_ARRAY(buffer);

View file

@ -151,33 +151,33 @@ void Win32DateTimeTest::testLocales(TestLog *log)
wdf->format(icuNow, udBuffer);
wtf->format(icuNow, utBuffer);
if (ubBuffer.indexOf(wdBuffer, wdLength - 1, 0) < 0) {
if (ubBuffer.indexOf((const UChar *)wdBuffer, wdLength - 1, 0) < 0) {
UnicodeString baseName(wlocale.getBaseName());
UnicodeString expected(wdBuffer);
UnicodeString expected((const UChar *)wdBuffer);
log->errln("DateTime format error for locale " + baseName + ": expected date \"" + expected +
"\" got \"" + ubBuffer + "\"");
}
if (ubBuffer.indexOf(wtBuffer, wtLength - 1, 0) < 0) {
if (ubBuffer.indexOf((const UChar *)wtBuffer, wtLength - 1, 0) < 0) {
UnicodeString baseName(wlocale.getBaseName());
UnicodeString expected(wtBuffer);
UnicodeString expected((const UChar *)wtBuffer);
log->errln("DateTime format error for locale " + baseName + ": expected time \"" + expected +
"\" got \"" + ubBuffer + "\"");
}
if (udBuffer.compare(wdBuffer) != 0) {
if (udBuffer.compare((const UChar *)wdBuffer) != 0) {
UnicodeString baseName(wlocale.getBaseName());
UnicodeString expected(wdBuffer);
UnicodeString expected((const UChar *)wdBuffer);
log->errln("Date format error for locale " + baseName + ": expected \"" + expected +
"\" got \"" + udBuffer + "\"");
}
if (utBuffer.compare(wtBuffer) != 0) {
if (utBuffer.compare((const UChar *)wtBuffer) != 0) {
UnicodeString baseName(wlocale.getBaseName());
UnicodeString expected(wtBuffer);
UnicodeString expected((const UChar *)wtBuffer);
log->errln("Time format error for locale " + baseName + ": expected \"" + expected +
"\" got \"" + utBuffer + "\"");

View file

@ -193,7 +193,7 @@ static UnicodeString &getWindowsFormat(int32_t lcid, UBool currency, UnicodeStri
if (lastError == ERROR_INSUFFICIENT_BUFFER) {
int newLength = GetCurrencyFormatW(lcid, 0, nBuffer, NULL, NULL, 0);
buffer = NEW_ARRAY(UChar, newLength);
buffer = NEW_ARRAY(wchar_t, newLength);
buffer[0] = 0x0000;
GetCurrencyFormatW(lcid, 0, nBuffer, NULL, buffer, newLength);
}
@ -207,14 +207,14 @@ static UnicodeString &getWindowsFormat(int32_t lcid, UBool currency, UnicodeStri
if (lastError == ERROR_INSUFFICIENT_BUFFER) {
int newLength = GetNumberFormatW(lcid, 0, nBuffer, NULL, NULL, 0);
buffer = NEW_ARRAY(UChar, newLength);
buffer = NEW_ARRAY(wchar_t, newLength);
buffer[0] = 0x0000;
GetNumberFormatW(lcid, 0, nBuffer, NULL, buffer, newLength);
}
}
}
appendTo.append(buffer, (int32_t) wcslen(buffer));
appendTo.append((const UChar *)buffer, (int32_t) wcslen(buffer));
if (buffer != stackBuffer) {
DELETE_ARRAY(buffer);