From 85f8d034a7963f38794e838e3e19f3f34902ceb6 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Tue, 13 Sep 2016 21:37:40 +0000 Subject: [PATCH] ICU-12547 UCHAR_TYPE=char16_t on Windows, fix compilation problems. X-SVN-Rev: 39217 --- icu4c/source/common/unicode/umachine.h | 21 +++++++++++++++++++++ icu4c/source/common/ustr_wcs.cpp | 4 ++-- icu4c/source/common/ustring.cpp | 2 +- icu4c/source/i18n/windtfmt.cpp | 16 ++++++++-------- icu4c/source/i18n/winnmfmt.cpp | 20 ++++++++++---------- icu4c/source/test/intltest/windttst.cpp | 16 ++++++++-------- icu4c/source/test/intltest/winnmtst.cpp | 6 +++--- 7 files changed, 53 insertions(+), 32 deletions(-) diff --git a/icu4c/source/common/unicode/umachine.h b/icu4c/source/common/unicode/umachine.h index 0e2785c03f6..48596584763 100644 --- a/icu4c/source/common/unicode/umachine.h +++ b/icu4c/source/common/unicode/umachine.h @@ -51,6 +51,27 @@ */ #include +/* + * 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, is needed for the definition of char16_t + */ +#ifndef __cplusplus +#include +#endif +#endif + /*==========================================================================*/ /* For C wrappers, we use the symbol U_STABLE. */ /* This works properly if the includer is C or C++. */ diff --git a/icu4c/source/common/ustr_wcs.cpp b/icu4c/source/common/ustr_wcs.cpp index cbd74507a2f..bf8607d4416 100644 --- a/icu4c/source/common/ustr_wcs.cpp +++ b/icu4c/source/common/ustr_wcs.cpp @@ -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); diff --git a/icu4c/source/common/ustring.cpp b/icu4c/source/common/ustring.cpp index f019b341cd8..8813c569ec6 100644 --- a/icu4c/source/common/ustring.cpp +++ b/icu4c/source/common/ustring.cpp @@ -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) { diff --git a/icu4c/source/i18n/windtfmt.cpp b/icu4c/source/i18n/windtfmt.cpp index aa4efddfd29..10243a702b7 100644 --- a/icu4c/source/i18n/windtfmt.cpp +++ b/icu4c/source/i18n/windtfmt.cpp @@ -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); diff --git a/icu4c/source/i18n/winnmfmt.cpp b/icu4c/source/i18n/winnmfmt.cpp index cac88099bd6..d7e98723bb2 100644 --- a/icu4c/source/i18n/winnmfmt.cpp +++ b/icu4c/source/i18n/winnmfmt.cpp @@ -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); diff --git a/icu4c/source/test/intltest/windttst.cpp b/icu4c/source/test/intltest/windttst.cpp index d0f8584484d..f705689d2f3 100644 --- a/icu4c/source/test/intltest/windttst.cpp +++ b/icu4c/source/test/intltest/windttst.cpp @@ -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 + "\""); diff --git a/icu4c/source/test/intltest/winnmtst.cpp b/icu4c/source/test/intltest/winnmtst.cpp index eadf226cd84..12c25f8cefa 100644 --- a/icu4c/source/test/intltest/winnmtst.cpp +++ b/icu4c/source/test/intltest/winnmtst.cpp @@ -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); -- 2.40.0