]> granicus.if.org Git - icu/commitdiff
ICU-12012 Replace all sizeof p / sizeof T with UPRV_LENGTHOF().
authorFredrik Roubert <roubert@google.com>
Wed, 24 Feb 2016 21:48:56 +0000 (21:48 +0000)
committerFredrik Roubert <roubert@google.com>
Wed, 24 Feb 2016 21:48:56 +0000 (21:48 +0000)
R=markus.icu@gmail.com

Review URL: https://codereview.appspot.com/288320043 .

X-SVN-Rev: 38347

24 files changed:
icu4c/source/common/locmap.c
icu4c/source/common/ucnv.c
icu4c/source/i18n/repattrn.cpp
icu4c/source/i18n/uspoof_impl.cpp
icu4c/source/io/uprntf_p.c
icu4c/source/test/cintltst/ccaltst.c
icu4c/source/test/cintltst/ccapitst.c
icu4c/source/test/cintltst/cloctst.c
icu4c/source/test/cintltst/cucdapi.c
icu4c/source/test/cintltst/custrtst.c
icu4c/source/test/cintltst/nucnvtst.c
icu4c/source/test/cintltst/spooftest.c
icu4c/source/test/cintltst/usrchtst.c
icu4c/source/test/intltest/icusvtst.cpp
icu4c/source/test/intltest/itrbnf.cpp
icu4c/source/test/intltest/numfmtst.cpp
icu4c/source/test/intltest/rbbitst.cpp
icu4c/source/test/intltest/tfsmalls.cpp
icu4c/source/test/intltest/tmsgfmt.cpp
icu4c/source/test/intltest/tufmtts.cpp
icu4c/source/test/intltest/tzrulets.cpp
icu4c/source/test/intltest/utxttest.cpp
icu4c/source/test/iotest/stream.cpp
icu4c/source/test/perf/normperf/dtfmtrtperf.h

index 50c29f687a28daf8e778aa05bea044d321640d38..d45614897a50e178255470aa57f210006a82d319 100644 (file)
@@ -908,7 +908,7 @@ static const ILcidPosixMap gPosixIDmap[] = {
     ILCID_POSIX_MAP(zu),    /*  zu  Zulu                      0x35 */
 };
 
-static const uint32_t gLocaleCount = sizeof(gPosixIDmap)/sizeof(ILcidPosixMap);
+static const uint32_t gLocaleCount = UPRV_LENGTHOF(gPosixIDmap);
 
 /**
  * Do not call this function. It is called by hostID.
index 8d570108ad7b6257c1c166ab619e5df4e1e45a0c..addae15898967c8baca5adcc415516281be27f32 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *
-*   Copyright (C) 1998-2015, International Business Machines
+*   Copyright (C) 1998-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
@@ -2646,7 +2646,7 @@ static const UAmbiguousConverter *ucnv_getAmbiguous(const UConverter *cnv)
         return NULL;
     }
 
-    for(i=0; i<(int32_t)(sizeof(ambiguousConverters)/sizeof(UAmbiguousConverter)); ++i)
+    for(i=0; i<UPRV_LENGTHOF(ambiguousConverters); ++i)
     {
         if(0==uprv_strcmp(name, ambiguousConverters[i].name))
         {
index 9363e3bb357882b2cdaae56a7396c7ad73b5d2ae..f4f22a8888943ef70f45e4a15ef4aaf699ee89ef 100644 (file)
@@ -3,8 +3,8 @@
 //
 /*
 ***************************************************************************
-*   Copyright (C) 2002-2015 International Business Machines Corporation   *
-*   and others. All rights reserved.                                      *
+*   Copyright (C) 2002-2016 International Business Machines Corporation
+*   and others. All rights reserved.
 ***************************************************************************
 */
 
@@ -14,6 +14,7 @@
 
 #include "unicode/regex.h"
 #include "unicode/uclean.h"
+#include "cmemory.h"
 #include "cstr.h"
 #include "uassert.h"
 #include "uhash.h"
@@ -690,7 +691,7 @@ void   RegexPattern::dumpOp(int32_t index) const {
     int32_t val         = URX_VAL(op);
     int32_t type        = URX_TYPE(op);
     int32_t pinnedType  = type;
-    if ((uint32_t)pinnedType >= sizeof(opNames)/sizeof(char *)) {
+    if ((uint32_t)pinnedType >= UPRV_LENGTHOF(opNames)) {
         pinnedType = 0;
     }
 
index e9077d3ac3414027735b4cbc8880fb92a6e9a996..4e98db548a48efae90b4b64ff710ae60c541561f 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (C) 2008-2015, International Business Machines
+*   Copyright (C) 2008-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 */
@@ -356,7 +356,7 @@ const char * SpoofImpl::getAllowedLocales(UErrorCode &/*status*/) {
 void SpoofImpl::addScriptChars(const char *locale, UnicodeSet *allowedChars, UErrorCode &status) {
     UScriptCode scripts[30];
 
-    int32_t numScripts = uscript_getCode(locale, scripts, sizeof(scripts)/sizeof(UScriptCode), &status);
+    int32_t numScripts = uscript_getCode(locale, scripts, UPRV_LENGTHOF(scripts), &status);
     if (U_FAILURE(status)) {
         return;
     }
index 04073e71bf9b892c7738781bc75e9e4cf090c074..a3dd75be50839b4ea3ac46e021f41d3d5297e9ac 100644 (file)
@@ -215,7 +215,7 @@ u_printf_string_handler(const u_printf_stream_handler  *handler,
         }
         else {
             s = ufmt_defaultCPToUnicode(arg, argSize, buffer,
-                    sizeof(buffer)/sizeof(UChar));
+                    UPRV_LENGTHOF(buffer));
         }
     }
     else {
@@ -251,7 +251,7 @@ u_printf_char_handler(const u_printf_stream_handler  *handler,
     unsigned char arg = (unsigned char)(args[0].int64Value);
 
     /* convert from default codepage to Unicode */
-    ufmt_defaultCPToUnicode((const char *)&arg, 2, s, sizeof(s)/sizeof(UChar));
+    ufmt_defaultCPToUnicode((const char *)&arg, 2, s, UPRV_LENGTHOF(s));
 
     /* Remember that this may be an MBCS character */
     if (arg != 0) {
index 1d89343bbf5e4463ff7497597711970f24e3f6c5..0f8927f40f004dac6fbe8a517a53b2c3f9cdde48 100644 (file)
@@ -264,7 +264,7 @@ static void TestCalendar()
     /*Testing ucal_getCanonicalTimeZoneID*/
     status = U_ZERO_ERROR;
     resultlength = ucal_getCanonicalTimeZoneID(PST, -1,
-        canonicalID, sizeof(canonicalID)/sizeof(UChar), &isSystemID, &status);
+        canonicalID, UPRV_LENGTHOF(canonicalID), &isSystemID, &status);
     if (U_FAILURE(status)) {
         log_data_err("FAIL: error in ucal_getCanonicalTimeZoneID : %s\n", u_errorName(status));
     } else {
index 856529d7fddb27fd780e60cbce2a1c58ea050d11..d92d4d8af138b765a7f2bd491b4cb6f96265dce2 100644 (file)
@@ -1893,7 +1893,7 @@ static void TestCCSID() {
     int32_t ccsids[]={ 37, 850, 943, 949, 950, 1047, 1252, 1392, 33722 };
     int32_t i, ccsid;
 
-    for(i=0; i<(int32_t)(sizeof(ccsids)/sizeof(int32_t)); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(ccsids); ++i) {
         ccsid=ccsids[i];
 
         errorCode=U_ZERO_ERROR;
index ac97c7907a4a6806cd613d603fd43c6a013c3918..fe8d083aea49dfe2373aec57466aa4c5a5415d49 100644 (file)
@@ -3211,7 +3211,7 @@ static void TestGetLocaleForLCID() {
         status = U_ZERO_ERROR;
     }
     
-    length = uloc_getLocaleForLCID(lcid, temp2, sizeof(temp2)/sizeof(char), &status);
+    length = uloc_getLocaleForLCID(lcid, temp2, UPRV_LENGTHOF(temp2), &status);
     if (U_FAILURE(status)) {
         log_err("  unexpected result from uloc_getLocaleForLCID(0x0409): %s\n", u_errorName(status));
         status = U_ZERO_ERROR;
@@ -3221,7 +3221,7 @@ static void TestGetLocaleForLCID() {
         log_err("  uloc_getLocaleForLCID(0x0409): returned length %d does not match preflight length %d\n", length, lengthPre);
     }
     
-    length = uloc_getLocaleForLCID(0x12345, temp2, sizeof(temp2)/sizeof(char), &status);
+    length = uloc_getLocaleForLCID(0x12345, temp2, UPRV_LENGTHOF(temp2), &status);
     if (U_SUCCESS(status)) {
         log_err("  unexpected result from uloc_getLocaleForLCID(0x12345): %s, status %s\n", temp2, u_errorName(status));
     }
@@ -3235,7 +3235,7 @@ static void TestGetLocaleForLCID() {
         log_verbose("Testing   %s ......\n", testLocale);
         
         sscanf(rawData2[LCID][i], "%x", &lcid);
-        length = uloc_getLocaleForLCID(lcid, temp2, sizeof(temp2)/sizeof(char), &status);
+        length = uloc_getLocaleForLCID(lcid, temp2, UPRV_LENGTHOF(temp2), &status);
         if (U_FAILURE(status)) {
             log_err("  unexpected failure of uloc_getLocaleForLCID(%#04x), status %s\n", lcid, u_errorName(status));
             status = U_ZERO_ERROR;
@@ -3247,7 +3247,7 @@ static void TestGetLocaleForLCID() {
         }
         
         /* Compare language, country, script */
-        length = uloc_getLanguage(temp2, temp3, sizeof(temp3)/sizeof(char), &status);
+        length = uloc_getLanguage(temp2, temp3, UPRV_LENGTHOF(temp3), &status);
         if (U_FAILURE(status)) {
             log_err("  couldn't get language in uloc_getLocaleForLCID(%#04x) = %s, status %s\n", lcid, temp2, u_errorName(status));
             status = U_ZERO_ERROR;
@@ -3256,7 +3256,7 @@ static void TestGetLocaleForLCID() {
             log_err("  language doesn't match expected %s in in uloc_getLocaleForLCID(%#04x) = %s\n", rawData2[LANG][i], lcid, temp2);
         }
         
-        length = uloc_getScript(temp2, temp3, sizeof(temp3)/sizeof(char), &status);
+        length = uloc_getScript(temp2, temp3, UPRV_LENGTHOF(temp3), &status);
         if (U_FAILURE(status)) {
             log_err("  couldn't get script in uloc_getLocaleForLCID(%#04x) = %s, status %s\n", lcid, temp2, u_errorName(status));
             status = U_ZERO_ERROR;
@@ -3265,7 +3265,7 @@ static void TestGetLocaleForLCID() {
             log_err("  script doesn't match expected %s in in uloc_getLocaleForLCID(%#04x) = %s\n", rawData2[SCRIPT][i], lcid, temp2);
         }
         
-        length = uloc_getCountry(temp2, temp3, sizeof(temp3)/sizeof(char), &status);
+        length = uloc_getCountry(temp2, temp3, UPRV_LENGTHOF(temp3), &status);
         if (U_FAILURE(status)) {
             log_err("  couldn't get country in uloc_getLocaleForLCID(%#04x) = %s, status %s\n", lcid, temp2, u_errorName(status));
             status = U_ZERO_ERROR;
index 522ebc93cfa333491ea7cb438cb4b248cb517521..d1e1b0f63d4dac30a92b8f7121e8b321ae503d5b 100644 (file)
@@ -1,5 +1,5 @@
 /********************************************************************
- * Copyright (c) 1997-2015, International Business Machines
+ * Copyright (c) 1997-2016, International Business Machines
  * Corporation and others. All Rights Reserved.
  ********************************************************************/
 
@@ -125,11 +125,11 @@ void TestUScriptCodeAPI(){
             err = U_ZERO_ERROR;
             capacity = 10;
             num = uscript_getCode("ja",script,capacity, &err);
-            if(num!=(sizeof(jaCode)/sizeof(UScriptCode))){
+            if(num!=UPRV_LENGTHOF(jaCode)){
                 log_err("Errors uscript_getScriptCode() for Japanese locale: num=%d, expected %d \n",
-                        num, (sizeof(jaCode)/sizeof(UScriptCode)));
+                        num, UPRV_LENGTHOF(jaCode));
             }
-            for(j=0;j<sizeof(jaCode)/sizeof(UScriptCode);j++) {
+            for(j=0;j<UPRV_LENGTHOF(jaCode);j++) {
                 if(script[j]!=jaCode[j]) {
                     log_err("Japanese locale: code #%d was %d (%s) but expected %d (%s)\n", j,
                             script[j], uscript_getName(script[j]),
@@ -204,7 +204,7 @@ void TestUScriptCodeAPI(){
              NULL
         };
         i=0;
-        while(i<sizeof(testAbbr)/sizeof(UScriptCode)){
+        while(i<UPRV_LENGTHOF(testAbbr)){
             const char* name = uscript_getName(testAbbr[i]);
              if(name == NULL) {
                log_data_err("Couldn't get script name\n");
@@ -243,7 +243,7 @@ void TestUScriptCodeAPI(){
              NULL
         };
         i=0;
-        while(i<sizeof(testAbbr)/sizeof(UScriptCode)){
+        while(i<UPRV_LENGTHOF(testAbbr)){
             const char* name = uscript_getShortName(testAbbr[i]);
             numErrors=0;
             if(strcmp(expectedAbbr[i],name)!=0){
index 9e83391076a36e42c796537211ac894923a0dc70..13425dbfcd4a21667da3fdac538f3b02b54969ae 100644 (file)
@@ -230,7 +230,7 @@ static void TestStringFunctions()
         if(temp[k] != 0xa4)
             log_err("something threw an error in u_strncpy()\n");
 
-        u_memset(temp, 0x3F, (sizeof(temp) / sizeof(UChar)) - 1);
+        u_memset(temp, 0x3F, UPRV_LENGTHOF(temp) - 1);
         u_uastrncpy(temp, raw[i][j], k-1);
         if(u_strncmp(temp, dataTable[i][j],k-1)!=0)
             log_err("something threw an error in u_uastrncpy(k-1)\n");
@@ -238,7 +238,7 @@ static void TestStringFunctions()
         if(temp[k-1] != 0x3F)
             log_err("something threw an error in u_uastrncpy(k-1)\n");
 
-        u_memset(temp, 0x3F, (sizeof(temp) / sizeof(UChar)) - 1);
+        u_memset(temp, 0x3F, UPRV_LENGTHOF(temp) - 1);
         u_uastrncpy(temp, raw[i][j], k+1);
         if(u_strcmp(temp, dataTable[i][j])!=0)
             log_err("something threw an error in u_uastrncpy(k+1)\n");
@@ -246,7 +246,7 @@ static void TestStringFunctions()
         if(temp[k] != 0)
             log_err("something threw an error in u_uastrncpy(k+1)\n");
 
-        u_memset(temp, 0x3F, (sizeof(temp) / sizeof(UChar)) - 1);
+        u_memset(temp, 0x3F, UPRV_LENGTHOF(temp) - 1);
         u_uastrncpy(temp, raw[i][j], k);
         if(u_strncmp(temp, dataTable[i][j], k)!=0)
             log_err("something threw an error in u_uastrncpy(k)\n");
index 22fa32b775a6c76f5145c327c0c0029db2db8903..184bcfb31b8be23e7d514321f5f653abf6fc5ba3 100644 (file)
@@ -1663,7 +1663,7 @@ TestSignatureDetection(){
         int32_t signatureLength = -1;
         const char* source = NULL;
         const char* enc = NULL;
-        for( ; i<sizeof(data)/sizeof(char*); i++){
+        for( ; i<UPRV_LENGTHOF(data); i++){
             err = U_ZERO_ERROR;
             source = data[i];
             enc = ucnv_detectUnicodeSignature(source, -1 , &signatureLength, &err);
@@ -1776,7 +1776,7 @@ TestSignatureDetection(){
         int32_t sourceLength=-1;
         const char* source = NULL;
         const char* enc = NULL;
-        for( ; i<sizeof(data)/sizeof(char*); i++){
+        for( ; i<UPRV_LENGTHOF(data); i++){
             err = U_ZERO_ERROR;
             source = data[i];
             sourceLength = len[i];
@@ -4908,7 +4908,7 @@ TestLMBCS() {
 
        UChar Out [sizeof(pszUnicode) + 1];
        UChar * pOut = Out;
-       UChar * OutLimit = Out + sizeof(pszUnicode)/sizeof(UChar);
+       UChar * OutLimit = Out + UPRV_LENGTHOF(pszUnicode);
 
        int32_t off [sizeof(offsets)];
 
@@ -5078,7 +5078,7 @@ TestLMBCS() {
 
        UChar Out [sizeof(pszUnicode) + 1];
        UChar * pOut = Out;
-       UChar * OutLimit = Out + sizeof(pszUnicode)/sizeof(UChar);
+       UChar * OutLimit = Out + UPRV_LENGTHOF(pszUnicode);
 
 
        cnv = ucnv_open(NAME_LMBCS_1, &errorCode);
@@ -5187,7 +5187,7 @@ TestLMBCS() {
          /* running out of target room : U_BUFFER_OVERFLOW_ERROR */
 
          pUIn = pszUnicode;
-         ucnv_fromUnicode(cnv, &pLOut,pLOut+offsets[4],&pUIn,pUIn+sizeof(pszUnicode)/sizeof(UChar),off,FALSE, &errorCode);
+         ucnv_fromUnicode(cnv, &pLOut,pLOut+offsets[4],&pUIn,pUIn+UPRV_LENGTHOF(pszUnicode),off,FALSE, &errorCode);
          if (errorCode != U_BUFFER_OVERFLOW_ERROR || pLOut != LOut + offsets[4] || pUIn != pszUnicode+4 )
          {
             log_err("Unexpected results on out of target room to ucnv_fromUnicode\n");
@@ -5215,7 +5215,7 @@ TestLMBCS() {
          pUOut = UOut;
 
          ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
-         ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode);
+         ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode);
          if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 5)
          {
             log_err("Unexpected results on chopped low surrogate\n");
@@ -5229,7 +5229,7 @@ TestLMBCS() {
          errorCode = U_ZERO_ERROR;
          pUOut = UOut;
 
-         ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+3),off,TRUE, &errorCode);
+         ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+3),off,TRUE, &errorCode);
          if (UOut[0] != 0xD801 || U_FAILURE(errorCode) || pUOut != UOut + 1 || pLIn != LIn + 3)
          {
             log_err("Unexpected results on chopped at surrogate boundary \n");
@@ -5246,7 +5246,7 @@ TestLMBCS() {
          errorCode = U_ZERO_ERROR;
          pUOut = UOut;
 
-         ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+6),off,TRUE, &errorCode);
+         ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+6),off,TRUE, &errorCode);
          if (UOut[0] != 0xD801 || UOut[1] != 0xC9D0 || U_FAILURE(errorCode) || pUOut != UOut + 2 || pLIn != LIn + 6)
          {
             log_err("Unexpected results after unpaired surrogate plus valid Unichar \n");
@@ -5263,7 +5263,7 @@ TestLMBCS() {
          errorCode = U_ZERO_ERROR;
          pUOut = UOut;
 
-         ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode);
+         ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode);
          if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 5)
          {
             log_err("Unexpected results after unpaired surrogate plus chopped Unichar \n");
@@ -5280,7 +5280,7 @@ TestLMBCS() {
          errorCode = U_ZERO_ERROR;
          pUOut = UOut;
 
-         ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode);
+         ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode);
          if (UOut[0] != 0xD801 || UOut[1] != 0x1B || U_FAILURE(errorCode) || pUOut != UOut + 2 || pLIn != LIn + 5)
          {
             log_err("Unexpected results after unpaired surrogate plus valid non-Unichar\n");
@@ -5296,7 +5296,7 @@ TestLMBCS() {
          errorCode = U_ZERO_ERROR;
          pUOut = UOut;
 
-         ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+4),off,TRUE, &errorCode);
+         ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+4),off,TRUE, &errorCode);
 
          if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 4)
          {
index ea70416f9440e8c7c26dc70240a121f1c2676ad1..f6ebdca06eb0b32c5a17a832ad5a135d16ee93c5 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
- * COPYRIGHT: 
- * Copyright (c) 2009-2015, International Business Machines Corporation and
+ * COPYRIGHT:
+ * Copyright (c) 2009-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -27,6 +27,7 @@
 #include "unicode/ustring.h"
 #include "unicode/uset.h"
 #include "cintltst.h"
+#include "cmemory.h"
 
 #define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \
     log_err_status(status, "Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status));}}
@@ -521,13 +522,13 @@ static void TestUSpoofCAPI(void) {
         UChar dest[100];
         int32_t   skelLength;
 
-        skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, dest, sizeof(dest)/sizeof(UChar), &status);
+        skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, dest, UPRV_LENGTHOF(dest), &status);
         TEST_ASSERT_SUCCESS(status);
         TEST_ASSERT_EQ(0, u_strcmp(lll_Skel, dest));
         TEST_ASSERT_EQ(u_strlen(lll_Skel), skelLength);
 
         skelLength = uspoof_getSkeletonUTF8(sc, USPOOF_ANY_CASE, goodLatinUTF8, -1, (char*)dest, 
-                                            sizeof(dest)/sizeof(UChar), &status);
+                                            UPRV_LENGTHOF(dest), &status);
         TEST_ASSERT_SUCCESS(status);
 
         skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, NULL, 0, &status);
index e425e552acabd9f7e3528bf8e2d2daad0f8de567..0c233af2e7fe3eb374afe66a4b218529de1d2ebc 100644 (file)
@@ -1,5 +1,5 @@
 /********************************************************************
- * Copyright (c) 2001-2011,2015,2016 International Business Machines 
+ * Copyright (c) 2001-2016 International Business Machines
  * Corporation and others. All Rights Reserved.
  ********************************************************************
  * File usrchtst.c
@@ -2896,8 +2896,8 @@ static void TestPCEBuffer_100df(void) {
     { 0x0020, 0x0020, 0x00df, 0x0020, 0x0041, 0x00df, 0x0020, 0x0061, 0x00df, 0x0020, 0x00c5, 0x00df, 0x0020, 0x212b, 0x00df, 0x0020, 0x0041, 0x030a, 0x00df, 0x0020, 0x00e5, 0x00df, 0x0020, 0x0061, 0x02da, 0x00df, 0x0020, 0x0061, 0x030a, 0x00df, 0x0020, 0xd8fa, 0xdeae, 0x00df, 0x0020, 0x2027, 0x00df }; /* 38 cp, 9 of them unpaired surrogates */
   UChar source[] = 
     { 0x0020, 0x0020, 0x00df, 0x0020, 0x0041, 0x00df, 0x0020, 0x0061, 0x00df, 0x0020, 0x00c5, 0x00df, 0x0020, 0x212b, 0x00df, 0x0020, 0x0041, 0x030a, 0x00df, 0x0020, 0x00e5, 0x00df, 0x0020, 0x0061, 0x02da, 0x00df, 0x0020, 0x0061, 0x030a, 0x00df, 0x0020, 0xd8fa, 0xdeae, 0x00df, 0x0020, 0x2027, 0x00df };
-  uint32_t searchLen = sizeof(search)/sizeof(UChar);
-  uint32_t sourceLen = sizeof(source)/sizeof(UChar);
+  uint32_t searchLen = UPRV_LENGTHOF(search);
+  uint32_t sourceLen = UPRV_LENGTHOF(source);
   TestPCEBuffer_with(search,searchLen,source,sourceLen);
  }
 
@@ -2907,8 +2907,8 @@ static void TestPCEBuffer_2surr(void) {
     { 0x0020, 0x0020, 0xdfff, 0x0020, 0x0041, 0xdfff, 0x0020, 0x0061, 0xdfff, 0x0020, 0x00c5, 0xdfff, 0x0020, 0x212b, 0xdfff, 0x0020, 0x0041, 0x030a, 0xdfff, 0x0020, 0x00e5, 0xdfff, 0x0020, 0x0061, 0x02da, 0xdfff, 0x0020, 0x0061, 0x030a, 0xdfff, 0x0020, 0xd8fa, 0xdeae, 0xdfff, 0x0020, 0x2027, 0xdfff }; /* 38 cp, 9 of them unpaired surrogates */
   UChar source[] = 
     { 0x0020, 0x0020, 0xdfff, 0x0020, 0x0041, 0xdfff, 0x0020, 0x0061, 0xdfff, 0x0020, 0x00c5, 0xdfff, 0x0020, 0x212b, 0xdfff, 0x0020, 0x0041, 0x030a, 0xdfff, 0x0020, 0x00e5, 0xdfff, 0x0020, 0x0061, 0x02da, 0xdfff, 0x0020, 0x0061, 0x030a, 0xdfff, 0x0020, 0xd8fa, 0xdeae, 0xdfff, 0x0020, 0x2027, 0xdfff };
-  uint32_t searchLen = sizeof(search)/sizeof(UChar);
-  uint32_t sourceLen = sizeof(source)/sizeof(UChar);
+  uint32_t searchLen = UPRV_LENGTHOF(search);
+  uint32_t sourceLen = UPRV_LENGTHOF(source);
   TestPCEBuffer_with(search,searchLen,source,sourceLen);
 }
 
@@ -2927,8 +2927,8 @@ static void TestMatchFollowedByIgnorables(void) {
     int32_t matchLength = 0;
     const int32_t expectedMatchLength = 1;
 
-    searchLen = sizeof(search)/sizeof(UChar);
-    sourceLen = sizeof(source)/sizeof(UChar);
+    searchLen = UPRV_LENGTHOF(search);
+    sourceLen = UPRV_LENGTHOF(source);
 
     coll = ucol_openFromShortString("LHR_AN_CX_EX_FX_HX_NX_S3",
                                     FALSE,
index bdf153e9aa8dec30dbe13ed3f71ad2832fa2df30..a9092855ac96ff1f9ac2c05932c9d3d6d8d9dc9f 100644 (file)
@@ -672,7 +672,7 @@ ICUServiceTest::testAPI_Two()
             "en_US_SURFER_GAL",
             "en_US_SURFER_DUDE"
         };
-        int32_t count = sizeof(xids)/sizeof(UnicodeString);
+        int32_t count = UPRV_LENGTHOF(xids);
 
         ICUServiceFactory* f = new TestMultipleKeyStringFactory(xids, count, "Later");
         service.registerFactory(f, status);
@@ -730,7 +730,7 @@ ICUServiceTest::testAPI_Two()
             "en_US_SILICON", 
             "en_US_SILICON_GEEK",
         };
-        int32_t count = sizeof(xids)/sizeof(UnicodeString);
+        int32_t count = UPRV_LENGTHOF(xids);
 
         ICUServiceFactory* f = new TestMultipleKeyStringFactory(xids, count, "Rad dude");
         service.registerFactory(f, status);
index 83c20a8aa4a20867e9f15861dd08029fdd84f56f..937bbee47dc252e405b694fb871dea845167fbe1 100644 (file)
@@ -1896,7 +1896,7 @@ IntlTestRBNF::TestAllLocales()
                 continue;
             }
 #if !UCONFIG_NO_COLLATION
-            for (unsigned int numidx = 0; numidx < sizeof(numbers)/sizeof(double); numidx++) {
+            for (unsigned int numidx = 0; numidx < UPRV_LENGTHOF(numbers); numidx++) {
                 double n = numbers[numidx];
                 UnicodeString str;
                 f->format(n, str);
index fe3ef498b00b08c064053c8d013e81eb8e718ba7..797edd4eb0134f44a31e9b4d49b5fc3945cf1b5d 100644 (file)
@@ -2417,7 +2417,7 @@ void NumberFormatTest::TestSymbolsWithBadLocale(void) {
     }; // expect U_USING_DEFAULT_WARNING for both
 
     unsigned int i;
-    for (i = 0; i < sizeof(badLocales) / sizeof(char*); i++) {
+    for (i = 0; i < UPRV_LENGTHOF(badLocales); i++) {
         const char *localeName = badLocales[i];
         Locale locBad(localeName);
         UErrorCode status = U_ZERO_ERROR;
@@ -7555,7 +7555,7 @@ void NumberFormatTest::TestSignificantDigits(void) {
     
     UnicodeString result;
     UnicodeString expectedResult;
-    for (unsigned int i = 0; i < sizeof(input)/sizeof(double); ++i) {
+    for (unsigned int i = 0; i < UPRV_LENGTHOF(input); ++i) {
         numberFormat->format(input[i], result);
         UnicodeString expectedResult(expected[i]);
         if (result != expectedResult) {
index 59bc16e8ad02ff9de1247db2ae108ab2402107a7..4e436deba9f0b58566b440aa3b1f93476c070632 100644 (file)
@@ -3732,7 +3732,7 @@ void RBBITest::TestWordBreaks(void)
         errcheckln(status, "Creation of break iterator failed %s", u_errorName(status));
         return;
     }
-    for (loop = 0; loop < (int)(sizeof(strlist) / sizeof(char *)); loop ++) {
+    for (loop = 0; loop < UPRV_LENGTHOF(strlist); loop ++) {
         // printf("looping %d\n", loop);
         UnicodeString ustr = CharsToUnicodeString(strlist[loop]);
         // RBBICharMonkey monkey;
@@ -3798,7 +3798,7 @@ void RBBITest::TestWordBoundary(void)
         errcheckln(status, "Creation of break iterator failed %s", u_errorName(status));
         return;
     }
-    for (loop = 0; loop < (int)(sizeof(strlist) / sizeof(char *)); loop ++) {
+    for (loop = 0; loop < UPRV_LENGTHOF(strlist); loop ++) {
         // printf("looping %d\n", loop);
         u_unescape(strlist[loop], str, 20);
         UnicodeString ustr(str);
@@ -3896,7 +3896,7 @@ void RBBITest::TestLineBreaks(void)
     if (U_FAILURE(status)) {
         return;
     }
-    for (loop = 0; loop < (int)(sizeof(strlist) / sizeof(char *)); loop ++) {
+    for (loop = 0; loop < UPRV_LENGTHOF(strlist); loop ++) {
         // printf("looping %d\n", loop);
         int32_t t = u_unescape(strlist[loop], str, STRSIZE);
         if (t >= STRSIZE) {
@@ -3966,7 +3966,7 @@ void RBBITest::TestSentBreaks(void)
         errcheckln(status, "Creation of break iterator failed %s", u_errorName(status));
         return;
     }
-    for (loop = 0; loop < (int)(sizeof(strlist) / sizeof(char *)); loop ++) {
+    for (loop = 0; loop < UPRV_LENGTHOF(strlist); loop ++) {
         u_unescape(strlist[loop], str, UPRV_LENGTHOF(str));
         UnicodeString ustr(str);
 
index 80bc1c578cfc390868d7acacab0a5461db7f43ff..dbf2eaa9fc852b7c61af03aea6ea3ca21a4d27a5 100644 (file)
@@ -1,7 +1,6 @@
-
 /***********************************************************************
- * COPYRIGHT: 
- * Copyright (c) 1997-2014, International Business Machines Corporation
+ * COPYRIGHT:
+ * Copyright (c) 1997-2016, International Business Machines Corporation
  * and others. All Rights Reserved.
  ***********************************************************************/
 
@@ -83,7 +82,7 @@ void test_FieldPosition_example( void )
     //***** this test is for compiler checks and visual verification only.
     double doubleNum[] = { 123456789.0, -12345678.9, 1234567.89, -123456.789,
         12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789};
-    int32_t dNumSize = (int32_t)(sizeof(doubleNum)/sizeof(double));
+    int32_t dNumSize = UPRV_LENGTHOF(doubleNum);
 
     UErrorCode status = U_ZERO_ERROR;
     DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
@@ -315,8 +314,8 @@ void test_Formattable( void )
     const Formattable ftarr1[] = { Formattable( (int32_t)1 ), Formattable( (int32_t)2 ) };
     const Formattable ftarr2[] = { Formattable( (int32_t)3 ), Formattable( (int32_t)4 ) };
 
-    const int32_t ftarr1_cnt = (int32_t)(sizeof(ftarr1) / sizeof(Formattable));
-    const int32_t ftarr2_cnt = (int32_t)(sizeof(ftarr2) / sizeof(Formattable));
+    const int32_t ftarr1_cnt = UPRV_LENGTHOF(ftarr1);
+    const int32_t ftarr2_cnt = UPRV_LENGTHOF(ftarr2);
 
     ft_arr.setArray( ftarr1, ftarr1_cnt );
     if ((ft_arr[0].getType() == Formattable::kLong) && (ft_arr[0].getLong() == (int32_t)1)) {
index 990ba358c6bce363403542fd9c869fc21d551eed..a4a6fc574d1365b4037c3a50835403942add8fea 100644 (file)
@@ -1058,7 +1058,7 @@ void TestMessageFormat::testFormat()
     {
         Formattable( UDate(8.71068e+011), Formattable::kIsDate )
     };
-    const int32_t ft_cnt = sizeof(ftarray) / sizeof(Formattable);
+    const int32_t ft_cnt = UPRV_LENGTHOF(ftarray);
     Formattable ft_arr( ftarray, ft_cnt );
 
     Formattable* fmt = new Formattable(UDate(8.71068e+011), Formattable::kIsDate);
index 5400a76b1c95f300a4bd0dc71951f026318d0317..1eb5a05d520382c60b1003fad90f339e0e744af8 100644 (file)
@@ -373,7 +373,7 @@ void TimeUnitTest::testGreekWithFallback() {
         Locale l = Locale::createFromName(locales[locIndex]);
 
         for ( unsigned int numberIndex = 0;
-            numberIndex < sizeof(numbers)/sizeof(int);
+            numberIndex < UPRV_LENGTHOF(numbers);
             ++numberIndex ) {
 
             for ( unsigned int styleIndex = 0;
index e8852a3e5decc2fdaaa12882ee7e6dd76e1c9e92..6f252d1092be58d5d3cf6773e325fd733c236325 100644 (file)
@@ -1111,7 +1111,7 @@ TimeZoneRuleTest::TestGetSimpleRules(void) {
         getUTCMillis(2005, UCAL_JULY, 1),
         getUTCMillis(2010, UCAL_NOVEMBER, 1),        
     };
-    int32_t numTimes = sizeof(testTimes)/sizeof(UDate);
+    int32_t numTimes = UPRV_LENGTHOF(testTimes);
     UErrorCode status = U_ZERO_ERROR;
     TestZIDEnumeration tzenum(!quick);
     InitialTimeZoneRule *initial;
index 801337cb49c6b2cefb7994035515dde2fdb9bc2a..474b7b971609a363ce29190a738c2e0d48d8be7c 100644 (file)
@@ -1015,7 +1015,7 @@ void UTextTest::ErrorTest()
 
         // Check setIndex
         int32_t i;
-        int32_t startMapLimit = sizeof(startMap) / sizeof(int32_t);
+        int32_t startMapLimit = UPRV_LENGTHOF(startMap);
         for (i=0; i<startMapLimit; i++) {
             utext_setNativeIndex(ut, i);
             int64_t cpIndex = utext_getNativeIndex(ut);
@@ -1086,7 +1086,7 @@ void UTextTest::ErrorTest()
         UText *ut = utext_openUnicodeString(NULL, &u16str, &status);
         TEST_SUCCESS(status);
 
-        int32_t startMapLimit = sizeof(startMap) / sizeof(int32_t);
+        int32_t startMapLimit = UPRV_LENGTHOF(startMap);
         int i;
         for (i=0; i<startMapLimit; i++) {
             utext_setNativeIndex(ut, i);
@@ -1154,7 +1154,7 @@ void UTextTest::ErrorTest()
         UText *ut = utext_openReplaceable(NULL, &u16str, &status);
         TEST_SUCCESS(status);
 
-        int32_t startMapLimit = sizeof(startMap) / sizeof(int32_t);
+        int32_t startMapLimit = UPRV_LENGTHOF(startMap);
         int i;
         for (i=0; i<startMapLimit; i++) {
             utext_setNativeIndex(ut, i);
index a0a2120803575523b800086265955d6583296f08..e54e8b6a3679742bc3fcc6943d282b6d9ab31482 100644 (file)
@@ -152,7 +152,7 @@ static void U_CALLCONV TestStream(void)
     ostrstream outLargeStream(testLargeStreamBuf, sizeof(testLargeStreamBuf));
 #endif
     UChar large_array[200];
-    int32_t large_array_length = sizeof(large_array)/sizeof(UChar);
+    int32_t large_array_length = UPRV_LENGTHOF(large_array);
     for (int32_t i = 0; i < large_array_length; i++) {
         large_array[i] = 0x41;
     }
index 6be40f4351eecce4de19279863170d1725f28253..1d680cebb1c338a49714ec7cff3c56653a5c291e 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-* Copyright (c) 2010-2011,International Business Machines
+* Copyright (c) 2010-2016,International Business Machines
 * Corporation and others.  All Rights Reserved.
 **********************************************************************
 **********************************************************************
@@ -18,6 +18,7 @@
 #include "unicode/smpdtfmt.h"
 #include "unicode/uchar.h"
 #include "unicode/basictz.h"
+#include "cmemory.h"
 #include "cstring.h"
 
 #include "unicode/uperf.h"
@@ -29,7 +30,7 @@
 #include "util.h"
 
 static const char* PATTERNS[] = {"z", "zzzz", "Z", "ZZZZ", "v", "vvvv", "V", "VVVV"};
-static const int NUM_PATTERNS = sizeof(PATTERNS)/sizeof(const char*);
+static const int NUM_PATTERNS = UPRV_LENGTHOF(PATTERNS);
 
 #include <iostream>
 #include <stdlib.h>
@@ -98,8 +99,8 @@ public:
         }
 
         // Set up test dates
-        UDate DATES[(sizeof(testDateData)/sizeof(int32_t))/3];
-        const int32_t nDates = (sizeof(testDateData)/sizeof(int32_t))/3;
+        UDate DATES[UPRV_LENGTHOF(testDateData)/3];
+        const int32_t nDates = UPRV_LENGTHOF(testDateData)/3;
         cal->clear();
         for (int32_t i = 0; i < nDates; i++) {
             cal->set(testDateData[i][0], testDateData[i][1], testDateData[i][2]);
@@ -228,4 +229,4 @@ public:
 };
 
 
-#endif // DateTimeRoundTripPerfTest
\ No newline at end of file
+#endif // DateTimeRoundTripPerfTest