#include "unicode/ustring.h"
#include "unicode/utext.h"
#include "cintltst.h"
-
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+#include "cmemory.h"
#define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \
log_data_err("Failure at file %s:%d - error = %s (Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status));}}
memset(&minus1, -1, sizeof(minus1));
/* Mimimalist open/close */
- u_uastrncpy(pat, "abc*", LENGTHOF(pat));
+ u_uastrncpy(pat, "abc*", UPRV_LENGTHOF(pat));
re = uregex_open(pat, -1, 0, 0, &status);
if (U_FAILURE(status)) {
log_data_err("Failed to open regular expression, %s:%d, error is \"%s\" (Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status));
/* The TEST_ASSERT_SUCCESS above should change too... */
if(U_SUCCESS(status)) {
- u_uastrncpy(pat, "abc*", LENGTHOF(pat));
+ u_uastrncpy(pat, "abc*", UPRV_LENGTHOF(pat));
TEST_ASSERT(u_strcmp(pat, p) == 0);
TEST_ASSERT(len==(int32_t)strlen("abc*"));
}
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);
{
const UChar *resultPat;
int32_t resultLen;
- u_uastrncpy(pat, "hello", LENGTHOF(pat));
+ u_uastrncpy(pat, "hello", UPRV_LENGTHOF(pat));
status = U_ZERO_ERROR;
re = uregex_open(pat, -1, 0, NULL, &status);
resultPat = uregex_pattern(re, &resultLen, &status);
UChar text2[50];
UBool result;
- u_uastrncpy(text1, "abcccd", LENGTHOF(text1));
- u_uastrncpy(text2, "abcccxd", LENGTHOF(text2));
+ u_uastrncpy(text1, "abcccd", UPRV_LENGTHOF(text1));
+ u_uastrncpy(text2, "abcccxd", UPRV_LENGTHOF(text2));
status = U_ZERO_ERROR;
- u_uastrncpy(pat, "abc*d", LENGTHOF(pat));
+ u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat));
re = uregex_open(pat, -1, 0, NULL, &status);
TEST_ASSERT_SUCCESS(status);
const UChar *result;
int32_t textLength;
- u_uastrncpy(text1, "abcccd", LENGTHOF(text1));
- u_uastrncpy(text2, "abcccxd", LENGTHOF(text2));
+ u_uastrncpy(text1, "abcccd", UPRV_LENGTHOF(text1));
+ u_uastrncpy(text2, "abcccxd", UPRV_LENGTHOF(text2));
status = U_ZERO_ERROR;
- u_uastrncpy(pat, "abc*d", LENGTHOF(pat));
+ u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat));
re = uregex_open(pat, -1, 0, NULL, &status);
uregex_setText(re, text1, -1, &status);
int len;
UChar nullString[] = {0,0,0};
- u_uastrncpy(text1, "abcccde", LENGTHOF(text1));
+ u_uastrncpy(text1, "abcccde", UPRV_LENGTHOF(text1));
status = U_ZERO_ERROR;
- u_uastrncpy(pat, "abc*d", LENGTHOF(pat));
+ u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat));
re = uregex_open(pat, -1, 0, NULL, &status);
uregex_setText(re, text1, -1, &status);
{
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);
UChar buf[80];
UBool result;
int32_t resultSz;
- 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);
/* Capture Group 0, the full match. Should succeed. */
status = U_ZERO_ERROR;
- resultSz = uregex_group(re, 0, buf, LENGTHOF(buf), &status);
+ resultSz = uregex_group(re, 0, buf, UPRV_LENGTHOF(buf), &status);
TEST_ASSERT_SUCCESS(status);
TEST_ASSERT_STRING("abc interior def", buf, TRUE);
TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def"));
/* Capture group #1. Should succeed. */
status = U_ZERO_ERROR;
- resultSz = uregex_group(re, 1, buf, LENGTHOF(buf), &status);
+ resultSz = uregex_group(re, 1, buf, UPRV_LENGTHOF(buf), &status);
TEST_ASSERT_SUCCESS(status);
TEST_ASSERT_STRING(" interior ", buf, TRUE);
TEST_ASSERT(resultSz == (int32_t)strlen(" interior "));
/* Capture group out of range. Error. */
status = U_ZERO_ERROR;
- uregex_group(re, 2, buf, LENGTHOF(buf), &status);
+ uregex_group(re, 2, buf, UPRV_LENGTHOF(buf), &status);
TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR);
/* NULL buffer, pure pre-flight */
TEST_ASSERT(uregex_regionStart(re, &status) == 3);
TEST_ASSERT(uregex_regionEnd(re, &status) == 6);
TEST_ASSERT(uregex_findNext(re, &status));
- TEST_ASSERT(uregex_group(re, 0, resultString, LENGTHOF(resultString), &status) == 3)
+ TEST_ASSERT(uregex_group(re, 0, resultString, UPRV_LENGTHOF(resultString), &status) == 3)
TEST_ASSERT_STRING("345", resultString, TRUE);
TEST_TEARDOWN;
UChar replText[80];
UChar buf[80];
int32_t resultSz;
- 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(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);
/* 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 <aa> x1x x...x.", buf, TRUE);
TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x."));
/* 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."));
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);
/* 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);
/* 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));
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);
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);
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);
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... */
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... */
int32_t spaceNeeded;
int32_t sz;
- u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", LENGTHOF(textToSplit));
+ u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", UPRV_LENGTHOF(textToSplit));
status = U_ZERO_ERROR;
re = uregex_openC("<(.*?)>", 0, NULL, &status);
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... */
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... */
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... */
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... */
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... */
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);
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);
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);
{
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);
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);
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);
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 <aa> <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);
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);
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);
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);
int32_t numFields;
int32_t i;
- u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", LENGTHOF(textToSplit));
+ u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", UPRV_LENGTHOF(textToSplit));
status = U_ZERO_ERROR;
re = uregex_openC("<(.*?)>", 0, NULL, &status);
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);
// 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);