diff --git a/icu4c/source/common/loclikely.cpp b/icu4c/source/common/loclikely.cpp index aa4a95b85c4..e5887081308 100644 --- a/icu4c/source/common/loclikely.cpp +++ b/icu4c/source/common/loclikely.cpp @@ -28,8 +28,6 @@ #include "ulocimp.h" #include "ustr_imp.h" -#define UPRV_LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) - /** * This function looks for the localeID in the likelySubtags resource. * diff --git a/icu4c/source/common/ucnvmbcs.cpp b/icu4c/source/common/ucnvmbcs.cpp index a3706feaf3b..f03f8a88c07 100644 --- a/icu4c/source/common/ucnvmbcs.cpp +++ b/icu4c/source/common/ucnvmbcs.cpp @@ -58,8 +58,6 @@ #include "cstring.h" #include "umutex.h" -#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) - /* control optimizations according to the platform */ #define MBCS_UNROLL_SINGLE_TO_BMP 1 #define MBCS_UNROLL_SINGLE_FROM_BMP 0 @@ -1126,7 +1124,7 @@ _extFromU(UConverter *cnv, const UConverterSharedData *sharedData, int32_t i; range=gb18030Ranges[0]; - for(i=0; itoUBytes[0], cnv->toUBytes[1], cnv->toUBytes[2], cnv->toUBytes[3]); range=gb18030Ranges[0]; - for(i=0; i", LENGTHOF(replText)); + u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); + u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); + u_uastrncpy(replText, "<$1>", UPRV_LENGTHOF(replText)); status = U_ZERO_ERROR; re = uregex_openC("x(.*?)x", 0, NULL, &status); @@ -830,7 +829,7 @@ static void TestRegexCAPI(void) { /* Normal case, with match */ uregex_setText(re, text1, -1, &status); - resultSz = uregex_replaceFirst(re, replText, -1, buf, LENGTHOF(buf), &status); + resultSz = uregex_replaceFirst(re, replText, -1, buf, UPRV_LENGTHOF(buf), &status); TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING("Replace x1x x...x.", buf, TRUE); TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x.")); @@ -838,7 +837,7 @@ static void TestRegexCAPI(void) { /* No match. Text should copy to output with no changes. */ status = U_ZERO_ERROR; uregex_setText(re, text2, -1, &status); - resultSz = uregex_replaceFirst(re, replText, -1, buf, LENGTHOF(buf), &status); + resultSz = uregex_replaceFirst(re, replText, -1, buf, UPRV_LENGTHOF(buf), &status); TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING("No match here.", buf, TRUE); TEST_ASSERT(resultSz == (int32_t)strlen("No match here.")); @@ -900,10 +899,10 @@ static void TestRegexCAPI(void) { int32_t expectedResultSize2; int32_t i; - u_uastrncpy(text1, "Replace xaax x1x x...x.", LENGTHOF(text1)); - u_uastrncpy(text2, "No match here.", LENGTHOF(text2)); - u_uastrncpy(replText, "<$1>", LENGTHOF(replText)); - u_uastrncpy(replText2, "<<$1>>", LENGTHOF(replText2)); + u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); + u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); + u_uastrncpy(replText, "<$1>", UPRV_LENGTHOF(replText)); + u_uastrncpy(replText2, "<<$1>>", UPRV_LENGTHOF(replText2)); expectedResultSize = strlen(expectedResult); expectedResultSize2 = strlen(expectedResult2); @@ -913,7 +912,7 @@ static void TestRegexCAPI(void) { /* Normal case, with match */ uregex_setText(re, text1, -1, &status); - resultSize = uregex_replaceAll(re, replText, -1, buf, LENGTHOF(buf), &status); + resultSize = uregex_replaceAll(re, replText, -1, buf, UPRV_LENGTHOF(buf), &status); TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING(expectedResult, buf, TRUE); TEST_ASSERT(resultSize == expectedResultSize); @@ -921,7 +920,7 @@ static void TestRegexCAPI(void) { /* No match. Text should copy to output with no changes. */ status = U_ZERO_ERROR; uregex_setText(re, text2, -1, &status); - resultSize = uregex_replaceAll(re, replText, -1, buf, LENGTHOF(buf), &status); + resultSize = uregex_replaceAll(re, replText, -1, buf, UPRV_LENGTHOF(buf), &status); TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING("No match here.", buf, TRUE); TEST_ASSERT(resultSize == u_strlen(text2)); @@ -1005,15 +1004,15 @@ static void TestRegexCAPI(void) { re = uregex_openC(".*", 0, 0, &status); TEST_ASSERT_SUCCESS(status); - u_uastrncpy(text, "whatever", LENGTHOF(text)); - u_uastrncpy(repl, "some other", LENGTHOF(repl)); + u_uastrncpy(text, "whatever", UPRV_LENGTHOF(text)); + u_uastrncpy(repl, "some other", UPRV_LENGTHOF(repl)); uregex_setText(re, text, -1, &status); /* match covers whole target string */ uregex_find(re, 0, &status); TEST_ASSERT_SUCCESS(status); bufPtr = buf; - bufCap = LENGTHOF(buf); + bufCap = UPRV_LENGTHOF(buf); uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING("some other", buf, TRUE); @@ -1022,8 +1021,8 @@ static void TestRegexCAPI(void) { uregex_find(re, 0, &status); TEST_ASSERT_SUCCESS(status); bufPtr = buf; - bufCap = LENGTHOF(buf); - u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", LENGTHOF(repl)); + bufCap = UPRV_LENGTHOF(buf); + u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", UPRV_LENGTHOF(repl)); uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); @@ -1058,8 +1057,8 @@ static void TestRegexCAPI(void) { int32_t spaceNeeded; int32_t sz; - u_uastrncpy(textToSplit, "first : second: third", LENGTHOF(textToSplit)); - u_uastrncpy(text2, "No match here.", LENGTHOF(text2)); + u_uastrncpy(textToSplit, "first : second: third", UPRV_LENGTHOF(textToSplit)); + u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); status = U_ZERO_ERROR; re = uregex_openC(":", 0, NULL, &status); @@ -1074,7 +1073,7 @@ static void TestRegexCAPI(void) { if (U_SUCCESS(status)) { memset(fields, -1, sizeof(fields)); numFields = - uregex_split(re, buf, LENGTHOF(buf), &requiredCapacity, fields, 10, &status); + uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 10, &status); TEST_ASSERT_SUCCESS(status); /* The TEST_ASSERT_SUCCESS call above should change too... */ @@ -1106,7 +1105,7 @@ static void TestRegexCAPI(void) { if(U_SUCCESS(status)) { memset(fields, -1, sizeof(fields)); numFields = - uregex_split(re, buf, LENGTHOF(buf), &requiredCapacity, fields, 2, &status); + uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 2, &status); TEST_ASSERT_SUCCESS(status); /* The TEST_ASSERT_SUCCESS call above should change too... */ @@ -1164,7 +1163,7 @@ static void TestRegexCAPI(void) { int32_t spaceNeeded; int32_t sz; - u_uastrncpy(textToSplit, "first second third", LENGTHOF(textToSplit)); + u_uastrncpy(textToSplit, "first second third", UPRV_LENGTHOF(textToSplit)); status = U_ZERO_ERROR; re = uregex_openC("<(.*?)>", 0, NULL, &status); @@ -1176,7 +1175,7 @@ static void TestRegexCAPI(void) { if(U_SUCCESS(status)) { memset(fields, -1, sizeof(fields)); numFields = - uregex_split(re, buf, LENGTHOF(buf), &requiredCapacity, fields, 10, &status); + uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 10, &status); TEST_ASSERT_SUCCESS(status); /* The TEST_ASSERT_SUCCESS call above should change too... */ @@ -1197,7 +1196,7 @@ static void TestRegexCAPI(void) { status = U_ZERO_ERROR; memset(fields, -1, sizeof(fields)); numFields = - uregex_split(re, buf, LENGTHOF(buf), &requiredCapacity, fields, 2, &status); + uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 2, &status); TEST_ASSERT_SUCCESS(status); /* The TEST_ASSERT_SUCCESS call above should change too... */ @@ -1215,7 +1214,7 @@ static void TestRegexCAPI(void) { status = U_ZERO_ERROR; memset(fields, -1, sizeof(fields)); numFields = - uregex_split(re, buf, LENGTHOF(buf), &requiredCapacity, fields, 3, &status); + uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 3, &status); TEST_ASSERT_SUCCESS(status); /* The TEST_ASSERT_SUCCESS call above should change too... */ @@ -1234,7 +1233,7 @@ static void TestRegexCAPI(void) { status = U_ZERO_ERROR; memset(fields, -1, sizeof(fields)); numFields = - uregex_split(re, buf, LENGTHOF(buf), &requiredCapacity, fields, 5, &status); + uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 5, &status); TEST_ASSERT_SUCCESS(status); /* The TEST_ASSERT_SUCCESS call above should change too... */ @@ -1261,7 +1260,7 @@ static void TestRegexCAPI(void) { if(U_SUCCESS(status)) { memset(fields, -1, sizeof(fields)); numFields = - uregex_split(re, buf, LENGTHOF(buf), &requiredCapacity, fields, 9, &status); + uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 9, &status); TEST_ASSERT_SUCCESS(status); /* The TEST_ASSERT_SUCCESS call above should change too... */ @@ -1468,8 +1467,8 @@ static void TestUTextAPI(void) { TEST_ASSERT_SUCCESS(status); TEST_ASSERT(clone3 != NULL); - u_uastrncpy(testString1, "abcccd", LENGTHOF(pat)); - u_uastrncpy(testString2, "xxxabcccd", LENGTHOF(pat)); + u_uastrncpy(testString1, "abcccd", UPRV_LENGTHOF(pat)); + u_uastrncpy(testString2, "xxxabcccd", UPRV_LENGTHOF(pat)); status = U_ZERO_ERROR; uregex_setText(clone1, testString1, -1, &status); @@ -1503,7 +1502,7 @@ static void TestUTextAPI(void) { UText *resultText; const char str_hello[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00 }; /* hello */ const char str_hel[] = { 0x68, 0x65, 0x6c, 0x00 }; /* hel */ - u_uastrncpy(pat, "hello", LENGTHOF(pat)); /* for comparison */ + u_uastrncpy(pat, "hello", UPRV_LENGTHOF(pat)); /* for comparison */ status = U_ZERO_ERROR; utext_openUTF8(&patternText, str_hello, -1, &status); @@ -1606,7 +1605,7 @@ static void TestUTextAPI(void) { status = U_ZERO_ERROR; utext_openUTF8(&text1, str_abcccd, -1, &status); - u_uastrncpy(text2Chars, str_abcccxd, LENGTHOF(text2Chars)); + u_uastrncpy(text2Chars, str_abcccxd, UPRV_LENGTHOF(text2Chars)); utext_openUChars(&text2, text2Chars, -1, &status); utext_openUTF8(&patternText, str_abcd, -1, &status); @@ -1702,7 +1701,7 @@ static void TestUTextAPI(void) { { UChar text1[50]; UBool result; - u_uastrncpy(text1, "012rx5rx890rxrx...", LENGTHOF(text1)); + u_uastrncpy(text1, "012rx5rx890rxrx...", UPRV_LENGTHOF(text1)); status = U_ZERO_ERROR; re = uregex_openC("rx", 0, NULL, &status); @@ -1766,7 +1765,7 @@ static void TestUTextAPI(void) { const char str_interior[] = { 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x69, 0x6f, 0x72, 0x20, 0x00 }; /* ' interior ' */ - u_uastrncpy(text1, "noise abc interior def, and this is off the end", LENGTHOF(text1)); + u_uastrncpy(text1, "noise abc interior def, and this is off the end", UPRV_LENGTHOF(text1)); status = U_ZERO_ERROR; re = uregex_openC("abc(.*?)def", 0, NULL, &status); @@ -1844,8 +1843,8 @@ static void TestUTextAPI(void) { const char str_1x[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ const char str_ReplaceAaaBax1xxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x20, 0x5c, 0x41, 0x61, 0x61, 0x42, 0x24, 0x61, 0x20, 0x78, 0x31, 0x78, 0x20, 0x78, 0x2e, 0x2e, 0x2e, 0x78, 0x2e, 0x00 }; /* Replace \AaaB$a x1x x...x. */ status = U_ZERO_ERROR; - u_uastrncpy(text1, "Replace xaax x1x x...x.", LENGTHOF(text1)); - u_uastrncpy(text2, "No match here.", LENGTHOF(text2)); + u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); + u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); utext_openUTF8(&replText, str_1x, -1, &status); re = uregex_openC("x(.*?)x", 0, NULL, &status); @@ -1890,8 +1889,8 @@ static void TestUTextAPI(void) { const char str_Replaceaa1[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x20, 0x3c, 0x61, 0x61, 0x3e, 0x20, 0x3c, 0x31, 0x3e, 0x20, 0x3c, 0x2e, 0x2e, 0x2e, 0x3e, 0x2e, 0x00 }; /* Replace <1> <...>. */ const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ status = U_ZERO_ERROR; - u_uastrncpy(text1, "Replace xaax x1x x...x.", LENGTHOF(text1)); - u_uastrncpy(text2, "No match here.", LENGTHOF(text2)); + u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); + u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); utext_openUTF8(&replText, str_1, -1, &status); re = uregex_openC("x(.*?)x", 0, NULL, &status); @@ -1930,15 +1929,15 @@ static void TestUTextAPI(void) { re = uregex_openC(".*", 0, 0, &status); TEST_ASSERT_SUCCESS(status); - u_uastrncpy(text, "whatever", LENGTHOF(text)); - u_uastrncpy(repl, "some other", LENGTHOF(repl)); + u_uastrncpy(text, "whatever", UPRV_LENGTHOF(text)); + u_uastrncpy(repl, "some other", UPRV_LENGTHOF(repl)); uregex_setText(re, text, -1, &status); /* match covers whole target string */ uregex_find(re, 0, &status); TEST_ASSERT_SUCCESS(status); bufPtr = buf; - bufCap = LENGTHOF(buf); + bufCap = UPRV_LENGTHOF(buf); uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING("some other", buf, TRUE); @@ -1947,8 +1946,8 @@ static void TestUTextAPI(void) { uregex_find(re, 0, &status); TEST_ASSERT_SUCCESS(status); bufPtr = buf; - bufCap = LENGTHOF(buf); - u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", LENGTHOF(repl)); + bufCap = UPRV_LENGTHOF(buf); + u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", UPRV_LENGTHOF(repl)); uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); @@ -1971,8 +1970,8 @@ static void TestUTextAPI(void) { int32_t numFields; int32_t i; - u_uastrncpy(textToSplit, "first : second: third", LENGTHOF(textToSplit)); - u_uastrncpy(text2, "No match here.", LENGTHOF(text2)); + u_uastrncpy(textToSplit, "first : second: third", UPRV_LENGTHOF(textToSplit)); + u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); status = U_ZERO_ERROR; re = uregex_openC(":", 0, NULL, &status); @@ -2047,7 +2046,7 @@ static void TestUTextAPI(void) { int32_t numFields; int32_t i; - u_uastrncpy(textToSplit, "first second third", LENGTHOF(textToSplit)); + u_uastrncpy(textToSplit, "first second third", UPRV_LENGTHOF(textToSplit)); status = U_ZERO_ERROR; re = uregex_openC("<(.*?)>", 0, NULL, &status); @@ -2292,7 +2291,7 @@ static void TestBug10815() { re = uregex_openC(".z", 0, 0, &status); TEST_ASSERT_SUCCESS(status); - u_uastrncpy(text, "Hello, World.", LENGTHOF(text)); + u_uastrncpy(text, "Hello, World.", UPRV_LENGTHOF(text)); uregex_setText(re, text, -1, &status); TEST_ASSERT_SUCCESS(status); @@ -2312,7 +2311,7 @@ static void TestBug10815() { // Pattern + this text gives an exponential time match. Without the callback to stop the match, // it will appear to be stuck in a (near) infinite loop. - u_uastrncpy(text, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", LENGTHOF(text)); + u_uastrncpy(text, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", UPRV_LENGTHOF(text)); uregex_setText(re, text, -1, &status); TEST_ASSERT_SUCCESS(status); diff --git a/icu4c/source/test/intltest/numfmtspectest.cpp b/icu4c/source/test/intltest/numfmtspectest.cpp index d98f78b4475..e9dd50af8ac 100644 --- a/icu4c/source/test/intltest/numfmtspectest.cpp +++ b/icu4c/source/test/intltest/numfmtspectest.cpp @@ -20,8 +20,6 @@ #include "unicode/dtfmtsym.h" #include "uassert.h" -#define LENGTHOF(array) (int32_t)(sizeof(array) / sizeof((array)[0])) - static const UChar kJPY[] = {0x4A, 0x50, 0x59}; static void fixNonBreakingSpace(UnicodeString &str) {