]> granicus.if.org Git - icu/commitdiff
ICU-12547 UCHAR_TYPE=char16_t on Windows, fix compilation problems.
authorAndy Heninger <andy.heninger@gmail.com>
Tue, 13 Sep 2016 21:37:40 +0000 (21:37 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Tue, 13 Sep 2016 21:37:40 +0000 (21:37 +0000)
X-SVN-Rev: 39217

icu4c/source/common/unicode/umachine.h
icu4c/source/common/ustr_wcs.cpp
icu4c/source/common/ustring.cpp
icu4c/source/i18n/windtfmt.cpp
icu4c/source/i18n/winnmfmt.cpp
icu4c/source/test/intltest/windttst.cpp
icu4c/source/test/intltest/winnmtst.cpp

index 0e2785c03f6c493a2f36e839750a3633ce46d735..48596584763a79b32afc08643b97e998941f0543 100644 (file)
  */
 #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++.                         */
index cbd74507a2f842d89e7d1ce6208ac017a430abe2..bf8607d44164a83383c36c1d46da0df098bc4a16 100644 (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);
index f019b341cd83f9b9a1d3b19e9fb811cdf4c9a47a..8813c569ec63fdba84c200df9fac1281ecf02c46 100644 (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) {
index aa4efddfd298f2d41b87276160933bb6c90eff1b..10243a702b7b445cab847fbae79890be6d40df1d 100644 (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);
index cac88099bd684e7115b2af2b6b90a2c35bd43fed..d7e98723bb271d6eefaaacf30bc162fbdda80022 100644 (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);
index d0f8584484d259a2bb2dd8f6f06594e0074d7190..f705689d2f3e8ac6e03ff5846bb6b159669a85ad 100644 (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 + "\"");
index eadf226cd8428e7e7c3364830e74d55deae8ff4e..12c25f8cefae0bce8685ae7082db0db83ddecbef 100644 (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);