1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/******************************************************************** 2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * COPYRIGHT: 31b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * Copyright (c) 2004-2015, International Business Machines Corporation and 4b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * others. All Rights Reserved. 5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ********************************************************************/ 6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/******************************************************************************** 7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* File reapits.c 9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*********************************************************************************/ 11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*C API TEST FOR Regular Expressions */ 12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* This is an API test for ICU regular expressions in C. It doesn't test very many cases, and doesn't 14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* try to test the full functionality. It just calls each function and verifies that it 15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* works on a basic level. 16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* More complete testing of regular expression functionality is done with the C++ tests. 18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru**/ 19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h" 21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if !UCONFIG_NO_REGULAR_EXPRESSIONS 23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <stdlib.h> 25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <string.h> 26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/uloc.h" 27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/uregex.h" 28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ustring.h" 2950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "unicode/utext.h" 30b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cintltst.h" 31f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius#include "cmemory.h" 32b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 33b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \ 34f9878a236aa0d9662d8e40cafdaf2e04cd615835ccorneliuslog_data_err("Failure at file %s:%d - error = %s (Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status));}} 35b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 36b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define TEST_ASSERT(expr) {if ((expr)==FALSE) { \ 37f9878a236aa0d9662d8e40cafdaf2e04cd615835ccorneliuslog_err("Test Failure at file %s:%d - ASSERT(%s) failed.\n", __FILE__, __LINE__, #expr);}} 38b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 39c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru/* 40c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * TEST_SETUP and TEST_TEARDOWN 41c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * macros to handle the boilerplate around setting up regex test cases. 42c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * parameteres to setup: 43c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * pattern: The regex pattern, a (char *) null terminated C string. 44c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * testString: The string data, also a (char *) C string. 45c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * flags: Regex flags to set when compiling the pattern 46c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * 47c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * Put arbitrary test code between SETUP and TEARDOWN. 48c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * 're" is the compiled, ready-to-go regular expression. 49c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 50c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru#define TEST_SETUP(pattern, testString, flags) { \ 51c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UChar *srcString = NULL; \ 52c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru status = U_ZERO_ERROR; \ 53c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru re = uregex_openC(pattern, flags, NULL, &status); \ 54c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); \ 55c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru srcString = (UChar *)malloc((strlen(testString)+2)*sizeof(UChar)); \ 56c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru u_uastrncpy(srcString, testString, strlen(testString)+1); \ 57c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setText(re, srcString, -1, &status); \ 58c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); \ 59c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (U_SUCCESS(status)) { 60c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 61c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru#define TEST_TEARDOWN \ 62c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } \ 63c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); \ 64c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_close(re); \ 65c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru free(srcString); \ 66c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 67c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 68c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 6950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/** 7050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param expected utf-8 array of bytes to be expected 7150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 72b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void test_assert_string(const char *expected, const UChar *actual, UBool nulTerm, const char *file, int line) { 73b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru char buf_inside_macro[120]; 74b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t len = (int32_t)strlen(expected); 75b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool success; 76b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (nulTerm) { 77b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_austrncpy(buf_inside_macro, (actual), len+1); 78b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf_inside_macro[len+2] = 0; 79b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru success = (strcmp((expected), buf_inside_macro) == 0); 80b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 81b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_austrncpy(buf_inside_macro, (actual), len); 82b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf_inside_macro[len+1] = 0; 83b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru success = (strncmp((expected), buf_inside_macro, len) == 0); 84b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 85b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (success == FALSE) { 86b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("Failure at file %s, line %d, expected \"%s\", got \"%s\"\n", 87b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru file, line, (expected), buf_inside_macro); 88b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 89b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 90b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 91b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define TEST_ASSERT_STRING(expected, actual, nulTerm) test_assert_string(expected, actual, nulTerm, __FILE__, __LINE__) 92b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 93b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 9483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Corneliusstatic UBool equals_utf8_utext(const char *utf8, UText *utext) { 9583a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius int32_t u8i = 0; 9683a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius UChar32 u8c = 0; 9783a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius UChar32 utc = 0; 9883a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius UBool stringsEqual = TRUE; 9983a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius utext_setNativeIndex(utext, 0); 10083a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius for (;;) { 10183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius U8_NEXT_UNSAFE(utf8, u8i, u8c); 10283a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius utc = utext_next32(utext); 10383a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius if (u8c == 0 && utc == U_SENTINEL) { 10483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius break; 10583a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius } 10683a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius if (u8c != utc || u8c == 0) { 10783a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius stringsEqual = FALSE; 10883a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius break; 10983a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius } 11083a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius } 11183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius return stringsEqual; 11283a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius} 11383a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius 11483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius 11550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void test_assert_utext(const char *expected, UText *actual, const char *file, int line) { 11650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_setNativeIndex(actual, 0); 11783a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius if (!equals_utf8_utext(expected, actual)) { 11850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar32 c; 11950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Failure at file %s, line %d, expected \"%s\", got \"", file, line, expected); 12050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho c = utext_next32From(actual, 0); 12150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho while (c != U_SENTINEL) { 12250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (0x20<c && c <0x7e) { 12350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("%c", c); 12450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } else { 12550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("%#x", c); 12650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 12750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho c = UTEXT_NEXT32(actual); 12850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 12950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("\"\n"); 13050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 13150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 13250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 13383a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius/* 13483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius * TEST_ASSERT_UTEXT(const char *expected, const UText *actual) 13583a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius * Note: Expected is a UTF-8 encoded string, _not_ the system code page. 13683a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius */ 13750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#define TEST_ASSERT_UTEXT(expected, actual) test_assert_utext(expected, actual, __FILE__, __LINE__) 138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 13983a171d1a62abf406f7f44ae671823d5ec20db7dCraig Corneliusstatic UBool testUTextEqual(UText *uta, UText *utb) { 14083a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius UChar32 ca = 0; 14183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius UChar32 cb = 0; 14283a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius utext_setNativeIndex(uta, 0); 14383a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius utext_setNativeIndex(utb, 0); 14483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius do { 14583a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius ca = utext_next32(uta); 14683a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius cb = utext_next32(utb); 14783a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius if (ca != cb) { 14883a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius break; 14983a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius } 15083a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius } while (ca != U_SENTINEL); 15183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius return ca == cb; 15283a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius} 15383a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius 15483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius 155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestRegexCAPI(void); 158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestBug4315(void); 15950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestUTextAPI(void); 1602e615e9896b12236afe0ff2695e8afc2ee73f961clairehostatic void TestRefreshInput(void); 161b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic void TestBug8421(void); 162f9878a236aa0d9662d8e40cafdaf2e04cd615835ccorneliusstatic void TestBug10815(void); 163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid addURegexTest(TestNode** root); 165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid addURegexTest(TestNode** root) 167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru addTest(root, &TestRegexCAPI, "regex/TestRegexCAPI"); 169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru addTest(root, &TestBug4315, "regex/TestBug4315"); 17050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestUTextAPI, "regex/TestUTextAPI"); 1712e615e9896b12236afe0ff2695e8afc2ee73f961claireho addTest(root, &TestRefreshInput, "regex/TestRefreshInput"); 172b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho addTest(root, &TestBug8421, "regex/TestBug8421"); 173f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius addTest(root, &TestBug10815, "regex/TestBug10815"); 174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 176c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru/* 177c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * Call back function and context struct used for testing 178c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * regular expression user callbacks. This test is mostly the same as 179c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * the corresponding C++ test in intltest. 180c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 181c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querutypedef struct callBackContext { 182c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru int32_t maxCalls; 183c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru int32_t numCalls; 184c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru int32_t lastSteps; 185c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru} callBackContext; 186c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 187c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querustatic UBool U_EXPORT2 U_CALLCONV 188c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste QueruTestCallbackFn(const void *context, int32_t steps) { 189c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru callBackContext *info = (callBackContext *)context; 190c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (info->lastSteps+1 != steps) { 191c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru log_err("incorrect steps in callback. Expected %d, got %d\n", info->lastSteps+1, steps); 192c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 193c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru info->lastSteps = steps; 194c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru info->numCalls++; 195c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru return (info->numCalls < info->maxCalls); 196c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru} 197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 198c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru/* 199c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * Regular Expression C API Tests 200c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestRegexCAPI(void) { 202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru URegularExpression *re; 204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar pat[200]; 205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *minus1; 206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(&minus1, -1, sizeof(minus1)); 208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Mimimalist open/close */ 210f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(pat, "abc*", UPRV_LENGTHOF(pat)); 211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 0, 0, &status); 212c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (U_FAILURE(status)) { 21350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_data_err("Failed to open regular expression, %s:%d, error is \"%s\" (Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status)); 214c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru return; 215c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Open with all flag values set */ 219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 22183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS | UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD | UREGEX_LITERAL, 222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, &status); 223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Open with an invalid flag */ 227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 0x40000000, 0, &status); 229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_REGEX_INVALID_FLAG); 230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 23250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Open with an unimplemented flag */ 23350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 23483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius re = uregex_open(pat, -1, UREGEX_CANON_EQ, 0, &status); 23550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(status == U_REGEX_UNIMPLEMENTED); 23650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 23750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* openC with an invalid parameter */ 239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC(NULL, 241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS | UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD, 0, &status); 242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR && re == NULL); 243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* openC with an invalid parameter */ 245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_USELESS_COLLATOR_ERROR; 246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC(NULL, 247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS | UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD, 0, &status); 248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_USELESS_COLLATOR_ERROR && re == NULL); 249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* openC open from a C string */ 251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UChar *p; 253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t len; 254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC("abc*", 0, 0, &status); 256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru p = uregex_pattern(re, &len, &status); 258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS above should change too... */ 261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 262f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(pat, "abc*", UPRV_LENGTHOF(pat)); 263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(u_strcmp(pat, p) == 0); 264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(len==(int32_t)strlen("abc*")); 265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* TODO: Open with ParseError parameter */ 270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * clone 274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru URegularExpression *clone1; 277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru URegularExpression *clone2; 278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru URegularExpression *clone3; 279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar testString1[30]; 280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar testString2[30]; 281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool result; 282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC("abc*", 0, 0, &status); 286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru clone1 = uregex_clone(re, &status); 288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(clone1 != NULL); 290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru clone2 = uregex_clone(re, &status); 293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(clone2 != NULL); 295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru clone3 = uregex_clone(clone2, &status); 299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(clone3 != NULL); 301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 302f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(testString1, "abcccd", UPRV_LENGTHOF(pat)); 303f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(testString2, "xxxabcccd", UPRV_LENGTHOF(pat)); 304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(clone1, testString1, -1, &status); 307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_lookingAt(clone1, 0, &status); 309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result==TRUE); 311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 313b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(clone2, testString2, -1, &status); 314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_lookingAt(clone2, 0, &status); 316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result==FALSE); 318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_find(clone2, 0, &status); 319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result==TRUE); 321b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(clone1); 323b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(clone2); 324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(clone3); 325b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 328b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * pattern() 330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UChar *resultPat; 333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t resultLen; 334f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(pat, "hello", UPRV_LENGTHOF(pat)); 335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 0, NULL, &status); 337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultPat = uregex_pattern(re, &resultLen, &status); 338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS above should change too... */ 341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_SUCCESS(status)) { 342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultLen == -1); 343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(u_strcmp(resultPat, pat) == 0); 344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, 3, 0, NULL, &status); 350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultPat = uregex_pattern(re, &resultLen, &status); 351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS above should change too... */ 355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_SUCCESS(status)) { 356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultLen == 3); 357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(u_strncmp(resultPat, pat, 3) == 0); 358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(u_strlen(resultPat) == 3); 359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * flags() 366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t t; 369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 0, NULL, &status); 372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru t = uregex_flags(re, &status); 373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(t == 0); 375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 0, NULL, &status); 379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru t = uregex_flags(re, &status); 380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(t == 0); 382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, UREGEX_CASE_INSENSITIVE | UREGEX_DOTALL, NULL, &status); 386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru t = uregex_flags(re, &status); 387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(t == (UREGEX_CASE_INSENSITIVE | UREGEX_DOTALL)); 389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * setText() and lookingAt() 394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text1[50]; 397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text2[50]; 398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool result; 399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 400f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "abcccd", UPRV_LENGTHOF(text1)); 401f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2, "abcccxd", UPRV_LENGTHOF(text2)); 402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 403f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat)); 404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 0, NULL, &status); 405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 406b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 407b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Operation before doing a setText should fail... */ 408b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 409b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_lookingAt(re, 0, &status); 410b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT( status== U_REGEX_INVALID_STATE); 411b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 412b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 413b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 414b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_lookingAt(re, 0, &status); 415b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 416b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 417b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 419b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text2, -1, &status); 420b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_lookingAt(re, 0, &status); 421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == FALSE); 422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 423b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_lookingAt(re, 0, &status); 427b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, 5, &status); 432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_lookingAt(re, 0, &status); 433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == FALSE); 434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, 6, &status); 438b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_lookingAt(re, 0, &status); 439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * getText() 448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text1[50]; 451b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text2[50]; 452b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UChar *result; 453b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t textLength; 454b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 455f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "abcccd", UPRV_LENGTHOF(text1)); 456f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2, "abcccxd", UPRV_LENGTHOF(text2)); 457b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 458f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat)); 459b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 0, NULL, &status); 460b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 462b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_getText(re, &textLength, &status); 463b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == text1); 464b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(textLength == -1); 465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 466b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text2, 7, &status); 469b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_getText(re, &textLength, &status); 470b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == text2); 471b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(textLength == 7); 472b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 474b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text2, 4, &status); 476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_getText(re, &textLength, &status); 477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == text2); 478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(textLength == 4); 479b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 482b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 484b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * matches() 485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text1[50]; 488b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool result; 489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int len; 490b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar nullString[] = {0,0,0}; 491b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 492f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "abcccde", UPRV_LENGTHOF(text1)); 493b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 494f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(pat, "abc*d", UPRV_LENGTHOF(pat)); 495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_open(pat, -1, 0, NULL, &status); 496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_matches(re, 0, &status); 499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == FALSE); 500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 502b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, 6, &status); 504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_matches(re, 0, &status); 505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, 6, &status); 510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_matches(re, 1, &status); 511b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == FALSE); 512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 513b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC(".?", 0, NULL, &status); 517b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru len = u_strlen(text1); 519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_matches(re, len, &status); 520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 523b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, nullString, -1, &status); 525b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 526b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_matches(re, 0, &status); 527b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 528b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 529b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 530b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 531b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 532b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 533b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 534b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * lookingAt() Used in setText test. 535b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 536b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 537b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 538b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 539b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * find(), findNext, start, end, reset 540b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 541b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 542b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text1[50]; 543b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool result; 544f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "012rx5rx890rxrx...", UPRV_LENGTHOF(text1)); 545b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 546b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC("rx", 0, NULL, &status); 547b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 548b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 549b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_find(re, 0, &status); 550b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 551b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 3); 552b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 5); 553b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 554b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 555b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_find(re, 9, &status); 556b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 11); 558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 13); 559b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 560b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 561b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_find(re, 14, &status); 562b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == FALSE); 563b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 564b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 565b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 566b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_reset(re, 0, &status); 567b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 568b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_findNext(re, &status); 569b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 570b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 3); 571b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 5); 572b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 573b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 574b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_findNext(re, &status); 575b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 576b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 6); 577b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 8); 578b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 579b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 580b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 581b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_reset(re, 12, &status); 582b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 583b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_findNext(re, &status); 584b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == TRUE); 585b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 13); 586b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 15); 587b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 588b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 589b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_findNext(re, &status); 590b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == FALSE); 591b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 592b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 593b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 594b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 595b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 596b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 597b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * groupCount 598b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 599b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 600b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t result; 601b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 602b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 603b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC("abc", 0, NULL, &status); 604b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_groupCount(re, &status); 605b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 606b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == 0); 607b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 608b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 609b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 610b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC("abc(def)(ghi(j))", 0, NULL, &status); 611b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_groupCount(re, &status); 612b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 613b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result == 3); 614b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 615b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 616b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 617b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 618b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 619b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 620b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * group() 621b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 622b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 623b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text1[80]; 624b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar buf[80]; 625b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool result; 626b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t resultSz; 627f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "noise abc interior def, and this is off the end", UPRV_LENGTHOF(text1)); 628b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 629b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 630b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC("abc(.*?)def", 0, NULL, &status); 631b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 632b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 633b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 634b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 635b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru result = uregex_find(re, 0, &status); 636b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(result==TRUE); 637b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 638b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Capture Group 0, the full match. Should succeed. */ 639b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 640f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius resultSz = uregex_group(re, 0, buf, UPRV_LENGTHOF(buf), &status); 641b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 642b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("abc interior def", buf, TRUE); 643b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def")); 644b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 645b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Capture group #1. Should succeed. */ 646b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 647f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius resultSz = uregex_group(re, 1, buf, UPRV_LENGTHOF(buf), &status); 648b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 649b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" interior ", buf, TRUE); 650b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen(" interior ")); 651b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 652b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Capture group out of range. Error. */ 653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 654f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_group(re, 2, buf, UPRV_LENGTHOF(buf), &status); 655b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR); 656b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 657b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* NULL buffer, pure pre-flight */ 658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 659b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultSz = uregex_group(re, 0, NULL, 0, &status); 660b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 661b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def")); 662b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 663b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Too small buffer, truncated string */ 664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(buf, -1, sizeof(buf)); 666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultSz = uregex_group(re, 0, buf, 5, &status); 667b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 668b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("abc i", buf, FALSE); 669b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(buf[5] == (UChar)0xffff); 670b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def")); 671b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 672b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Output string just fits buffer, no NUL term. */ 673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 674b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultSz = uregex_group(re, 0, buf, (int32_t)strlen("abc interior def"), &status); 675b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); 676b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("abc interior def", buf, FALSE); 677b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("abc interior def")); 678b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(buf[strlen("abc interior def")] == (UChar)0xffff); 679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 681b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 682b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 683c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 684c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* 685c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * Regions 686c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 687c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 688c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 689c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* SetRegion(), getRegion() do something */ 690c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP(".*", "0123456789ABCDEF", 0) 691c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UChar resultString[40]; 692c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_regionStart(re, &status) == 0); 693c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_regionEnd(re, &status) == 16); 694c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 3, 6, &status); 695c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_regionStart(re, &status) == 3); 696c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_regionEnd(re, &status) == 6); 697c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_findNext(re, &status)); 698f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT(uregex_group(re, 0, resultString, UPRV_LENGTHOF(resultString), &status) == 3) 699c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_STRING("345", resultString, TRUE); 700c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 701c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 702c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* find(start=-1) uses regions */ 703c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP(".*", "0123456789ABCDEF", 0); 704c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 4, 6, &status); 705c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, -1, &status) == TRUE); 706c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 4); 707c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 6); 708c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 709c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 710c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* find (start >=0) does not use regions */ 711c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP(".*", "0123456789ABCDEF", 0); 712c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 4, 6, &status); 713c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, 0, &status) == TRUE); 714c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 0); 715c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 16); 716c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 717c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 718c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* findNext() obeys regions */ 719c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP(".", "0123456789ABCDEF", 0); 720c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 4, 6, &status); 721c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_findNext(re,&status) == TRUE); 722c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 4); 723c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_findNext(re, &status) == TRUE); 724c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 5); 725c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_findNext(re, &status) == FALSE); 726c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 727c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 728c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* matches(start=-1) uses regions */ 729c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* Also, verify that non-greedy *? succeeds in finding the full match. */ 730c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP(".*?", "0123456789ABCDEF", 0); 731c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 4, 6, &status); 732c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_matches(re, -1, &status) == TRUE); 733c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 4); 734c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 6); 735c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 736c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 737c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* matches (start >=0) does not use regions */ 738c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP(".*?", "0123456789ABCDEF", 0); 739c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 4, 6, &status); 740c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_matches(re, 0, &status) == TRUE); 741c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 0); 742c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 16); 743c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 744c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 745c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* lookingAt(start=-1) uses regions */ 746c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* Also, verify that non-greedy *? finds the first (shortest) match. */ 747c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP(".*?", "0123456789ABCDEF", 0); 748c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 4, 6, &status); 749c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_lookingAt(re, -1, &status) == TRUE); 750c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 4); 751c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 4); 752c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 753c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 754c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* lookingAt (start >=0) does not use regions */ 755c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP(".*?", "0123456789ABCDEF", 0); 756c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 4, 6, &status); 757c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_lookingAt(re, 0, &status) == TRUE); 758c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_start(re, 0, &status) == 0); 759c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 0); 760c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 761c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 762c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* hitEnd() */ 763c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("[a-f]*", "abcdefghij", 0); 764c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, 0, &status) == TRUE); 765c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_hitEnd(re, &status) == FALSE); 766c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 767c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 768c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("[a-f]*", "abcdef", 0); 769c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, 0, &status) == TRUE); 770c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_hitEnd(re, &status) == TRUE); 771c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 772c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 773c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* requireEnd */ 774c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("abcd", "abcd", 0); 775c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, 0, &status) == TRUE); 776c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_requireEnd(re, &status) == FALSE); 777c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 778c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 779c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("abcd$", "abcd", 0); 780c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, 0, &status) == TRUE); 781c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_requireEnd(re, &status) == TRUE); 782c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 783c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 784c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* anchoringBounds */ 785c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("abc$", "abcdef", 0); 786c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_hasAnchoringBounds(re, &status) == TRUE); 787c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_useAnchoringBounds(re, FALSE, &status); 788c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_hasAnchoringBounds(re, &status) == FALSE); 789c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 790c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, -1, &status) == FALSE); 791c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_useAnchoringBounds(re, TRUE, &status); 792c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 0, 3, &status); 793c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, -1, &status) == TRUE); 794c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 3); 795c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 796c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 797c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* Transparent Bounds */ 798c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("abc(?=def)", "abcdef", 0); 799c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_hasTransparentBounds(re, &status) == FALSE); 800c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_useTransparentBounds(re, TRUE, &status); 801c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_hasTransparentBounds(re, &status) == TRUE); 802c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 803c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_useTransparentBounds(re, FALSE, &status); 804c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, -1, &status) == TRUE); /* No Region */ 805c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setRegion(re, 0, 3, &status); 806c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, -1, &status) == FALSE); /* with region, opaque bounds */ 807c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_useTransparentBounds(re, TRUE, &status); 808c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_find(re, -1, &status) == TRUE); /* with region, transparent bounds */ 809c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_end(re, 0, &status) == 3); 810c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 811c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 812b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 813b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 814b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * replaceFirst() 815b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 816b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 817b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text1[80]; 818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text2[80]; 819b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar replText[80]; 820b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar buf[80]; 821b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t resultSz; 822f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); 823f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); 824f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(replText, "<$1>", UPRV_LENGTHOF(replText)); 825b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 827b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC("x(.*?)x", 0, NULL, &status); 828b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 829b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Normal case, with match */ 831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 832f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius resultSz = uregex_replaceFirst(re, replText, -1, buf, UPRV_LENGTHOF(buf), &status); 833b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 834b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("Replace <aa> x1x x...x.", buf, TRUE); 835b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x.")); 836b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 837b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* No match. Text should copy to output with no changes. */ 838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 839b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text2, -1, &status); 840f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius resultSz = uregex_replaceFirst(re, replText, -1, buf, UPRV_LENGTHOF(buf), &status); 841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 842b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("No match here.", buf, TRUE); 843b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("No match here.")); 844b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 845b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Match, output just fills buffer, no termination warning. */ 846b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 847b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 848b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(buf, -1, sizeof(buf)); 849b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultSz = uregex_replaceFirst(re, replText, -1, buf, strlen("Replace <aa> x1x x...x."), &status); 850b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); 851b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("Replace <aa> x1x x...x.", buf, FALSE); 852b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x.")); 853b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(buf[resultSz] == (UChar)0xffff); 854b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 855b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Do the replaceFirst again, without first resetting anything. 856b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Should give the same results. 857b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 858b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 859b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(buf, -1, sizeof(buf)); 860b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultSz = uregex_replaceFirst(re, replText, -1, buf, strlen("Replace <aa> x1x x...x."), &status); 861b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); 862b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("Replace <aa> x1x x...x.", buf, FALSE); 863b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x.")); 864b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(buf[resultSz] == (UChar)0xffff); 865b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 866b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* NULL buffer, zero buffer length */ 867b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 868b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultSz = uregex_replaceFirst(re, replText, -1, NULL, 0, &status); 869b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 870b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x.")); 871b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 872b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Buffer too small by one */ 873b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 874b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(buf, -1, sizeof(buf)); 875b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru resultSz = uregex_replaceFirst(re, replText, -1, buf, strlen("Replace <aa> x1x x...x.")-1, &status); 876b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 877b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("Replace <aa> x1x x...x", buf, FALSE); 878b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(resultSz == (int32_t)strlen("Replace xaax x1x x...x.")); 879b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(buf[resultSz] == (UChar)0xffff); 880b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 881b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 882b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 883b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 884b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 885b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 886b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * replaceAll() 887b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 888b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 889b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar text1[80]; /* "Replace xaax x1x x...x." */ 890b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar text2[80]; /* "No match Here" */ 891b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar replText[80]; /* "<$1>" */ 892b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar replText2[80]; /* "<<$1>>" */ 893b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru const char * pattern = "x(.*?)x"; 894b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru const char * expectedResult = "Replace <aa> <1> <...>."; 895b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru const char * expectedResult2 = "Replace <<aa>> <<1>> <<...>>."; 896b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar buf[80]; 897b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t resultSize; 898b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t expectedResultSize; 899b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t expectedResultSize2; 900b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i; 901b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 902f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); 903f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); 904f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(replText, "<$1>", UPRV_LENGTHOF(replText)); 905f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(replText2, "<<$1>>", UPRV_LENGTHOF(replText2)); 906b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru expectedResultSize = strlen(expectedResult); 907b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru expectedResultSize2 = strlen(expectedResult2); 908b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 909b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 910b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru re = uregex_openC(pattern, 0, NULL, &status); 911b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 912b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 913b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Normal case, with match */ 914b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 915f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius resultSize = uregex_replaceAll(re, replText, -1, buf, UPRV_LENGTHOF(buf), &status); 916b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 917b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT_STRING(expectedResult, buf, TRUE); 918b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(resultSize == expectedResultSize); 919b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 920b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* No match. Text should copy to output with no changes. */ 921b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 922b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text2, -1, &status); 923f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius resultSize = uregex_replaceAll(re, replText, -1, buf, UPRV_LENGTHOF(buf), &status); 924b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 925b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("No match here.", buf, TRUE); 926b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(resultSize == u_strlen(text2)); 927b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 928b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Match, output just fills buffer, no termination warning. */ 929b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 930b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text1, -1, &status); 931b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(buf, -1, sizeof(buf)); 932b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru resultSize = uregex_replaceAll(re, replText, -1, buf, expectedResultSize, &status); 933b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); 934b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT_STRING(expectedResult, buf, FALSE); 935b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(resultSize == expectedResultSize); 936b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(buf[resultSize] == (UChar)0xffff); 937b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 938b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Do the replaceFirst again, without first resetting anything. 939b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Should give the same results. 940b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 941b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 942b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(buf, -1, sizeof(buf)); 943b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru resultSize = uregex_replaceAll(re, replText, -1, buf, strlen("Replace xaax x1x x...x."), &status); 944b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_STRING_NOT_TERMINATED_WARNING); 945b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("Replace <aa> <1> <...>.", buf, FALSE); 946b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(resultSize == (int32_t)strlen("Replace <aa> <1> <...>.")); 947b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(buf[resultSize] == (UChar)0xffff); 948b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 949b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* NULL buffer, zero buffer length */ 950b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 951b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru resultSize = uregex_replaceAll(re, replText, -1, NULL, 0, &status); 952b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 953b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(resultSize == (int32_t)strlen("Replace <aa> <1> <...>.")); 954b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 955b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Buffer too small. Try every size, which will tickle edge cases 956b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * in uregex_appendReplacement (used by replaceAll) */ 957b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i=0; i<expectedResultSize; i++) { 958b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru char expected[80]; 959b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 960b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(buf, -1, sizeof(buf)); 961b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru resultSize = uregex_replaceAll(re, replText, -1, buf, i, &status); 962b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 963b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru strcpy(expected, expectedResult); 964b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru expected[i] = 0; 965b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(expected, buf, FALSE); 966b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(resultSize == expectedResultSize); 967b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(buf[i] == (UChar)0xffff); 968b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 969b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 970b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* Buffer too small. Same as previous test, except this time the replacement 971b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * text is longer than the match capture group, making the length of the complete 972b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * replacement longer than the original string. 973b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 974b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for (i=0; i<expectedResultSize2; i++) { 975b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru char expected[80]; 976b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru status = U_ZERO_ERROR; 977b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru memset(buf, -1, sizeof(buf)); 978b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru resultSize = uregex_replaceAll(re, replText2, -1, buf, i, &status); 979b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 980b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru strcpy(expected, expectedResult2); 981b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru expected[i] = 0; 982b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT_STRING(expected, buf, FALSE); 983b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(resultSize == expectedResultSize2); 984b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(buf[i] == (UChar)0xffff); 985b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 986b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 987b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 988b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 989b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 990b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 991b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 992b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 993b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * appendReplacement() 994b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 995b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 996b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text[100]; 997b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar repl[100]; 998b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar buf[100]; 999b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *bufPtr; 1000b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t bufCap; 1001b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1002b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1003b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1004b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC(".*", 0, 0, &status); 1005b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1006b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1007f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text, "whatever", UPRV_LENGTHOF(text)); 1008f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(repl, "some other", UPRV_LENGTHOF(repl)); 1009b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, text, -1, &status); 1010b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1011b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* match covers whole target string */ 1012b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_find(re, 0, &status); 1013b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1014b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru bufPtr = buf; 1015f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius bufCap = UPRV_LENGTHOF(buf); 1016b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); 1017b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1018b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("some other", buf, TRUE); 1019b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1020b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Match has \u \U escapes */ 1021b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_find(re, 0, &status); 1022b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1023b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru bufPtr = buf; 1024f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius bufCap = UPRV_LENGTHOF(buf); 10251b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ \\$ \\abc", UPRV_LENGTHOF(repl)); 1026b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); 1027b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1028b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); 1029b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1030b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* Bug 6813, parameter check of NULL destCapacity; crashed before fix. */ 1031b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru status = U_ZERO_ERROR; 1032b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uregex_find(re, 0, &status); 1033b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1034b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru bufPtr = buf; 1035b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru status = U_BUFFER_OVERFLOW_ERROR; 1036b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uregex_appendReplacement(re, repl, -1, &bufPtr, NULL, &status); 1037b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 1038b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1039b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 1040b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1041b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1042b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1043b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1044b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * appendTail(). Checked in ReplaceFirst(), replaceAll(). 1045b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1046b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1047b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1048b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * split() 1049b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1050b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1051b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar textToSplit[80]; 1052b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar text2[80]; 1053b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar buf[200]; 1054b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *fields[10]; 1055b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t numFields; 1056b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t requiredCapacity; 1057b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t spaceNeeded; 1058b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t sz; 1059b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1060f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(textToSplit, "first : second: third", UPRV_LENGTHOF(textToSplit)); 1061f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); 1062b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1063b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1064b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC(":", 0, NULL, &status); 1065b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1066b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1067b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Simple split */ 1068b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1069b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, textToSplit, -1, &status); 1070b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1071b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1072b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1073b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_SUCCESS(status)) { 1074b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(fields, -1, sizeof(fields)); 1075b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields = 1076f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 10, &status); 1077b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1078b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1079b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1080b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1081b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(numFields == 3); 1082b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("first ", fields[0], TRUE); 1083b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" second", fields[1], TRUE); 1084b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" third", fields[2], TRUE); 1085b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(fields[3] == NULL); 1086b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1087b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru spaceNeeded = u_strlen(textToSplit) - 1088b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (numFields - 1) + /* Field delimiters do not appear in output */ 1089b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields; /* Each field gets a NUL terminator */ 1090b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1091b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(spaceNeeded == requiredCapacity); 1092b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1093b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1094b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1095b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 1096b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1097b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1098b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Split with too few output strings available */ 1099b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC(":", 0, NULL, &status); 1101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, textToSplit, -1, &status); 1102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(fields, -1, sizeof(fields)); 1107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields = 1108f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 2, &status); 1109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(numFields == 2); 1114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("first ", fields[0], TRUE); 1115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" second: third", fields[1], TRUE); 1116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); 1117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru spaceNeeded = u_strlen(textToSplit) - 1119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (numFields - 1) + /* Field delimiters do not appear in output */ 1120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields; /* Each field gets a NUL terminator */ 1121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(spaceNeeded == requiredCapacity); 1123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Split with a range of output buffer sizes. */ 1125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru spaceNeeded = u_strlen(textToSplit) - 1126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (numFields - 1) + /* Field delimiters do not appear in output */ 1127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields; /* Each field gets a NUL terminator */ 1128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (sz=0; sz < spaceNeeded+1; sz++) { 1130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(fields, -1, sizeof(fields)); 1131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields = 1133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_split(re, buf, sz, &requiredCapacity, fields, 10, &status); 1134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (sz >= spaceNeeded) { 1135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("first ", fields[0], TRUE); 1137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" second", fields[1], TRUE); 1138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" third", fields[2], TRUE); 1139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 1141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(numFields == 3); 1143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(fields[3] == NULL); 1144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(spaceNeeded == requiredCapacity); 1145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 1150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Split(), part 2. Patterns with capture groups. The capture group text 1156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * comes out as additional fields. */ 1157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar textToSplit[80]; 1159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar buf[200]; 1160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *fields[10]; 1161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t numFields; 1162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t requiredCapacity; 1163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t spaceNeeded; 1164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t sz; 1165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1166f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", UPRV_LENGTHOF(textToSplit)); 1167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru re = uregex_openC("<(.*?)>", 0, NULL, &status); 1170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, textToSplit, -1, &status); 1172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(fields, -1, sizeof(fields)); 1177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields = 1178f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 10, &status); 1179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(numFields == 5); 1184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("first ", fields[0], TRUE); 1185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("tag-a", fields[1], TRUE); 1186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" second", fields[2], TRUE); 1187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("tag-b", fields[3], TRUE); 1188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" third", fields[4], TRUE); 1189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(fields[5] == NULL); 1190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /* "." at NUL positions */ 1191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(spaceNeeded == requiredCapacity); 1192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Split with too few output strings available (2) */ 1196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(fields, -1, sizeof(fields)); 1198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields = 1199f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 2, &status); 1200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(numFields == 2); 1205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("first ", fields[0], TRUE); 1206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" second<tag-b> third", fields[1], TRUE); 1207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); 1208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru spaceNeeded = strlen("first . second<tag-b> third."); /* "." at NUL positions */ 1210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(spaceNeeded == requiredCapacity); 1211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Split with too few output strings available (3) */ 1214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(fields, -1, sizeof(fields)); 1216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields = 1217f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 3, &status); 1218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(numFields == 3); 1223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("first ", fields[0], TRUE); 1224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("tag-a", fields[1], TRUE); 1225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" second<tag-b> third", fields[2], TRUE); 1226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(!memcmp(&fields[3],&minus1,sizeof(UChar*))); 1227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru spaceNeeded = strlen("first .tag-a. second<tag-b> third."); /* "." at NUL positions */ 1229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(spaceNeeded == requiredCapacity); 1230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Split with just enough output strings available (5) */ 1233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(fields, -1, sizeof(fields)); 1235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields = 1236f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 5, &status); 1237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(numFields == 5); 1242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("first ", fields[0], TRUE); 1243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("tag-a", fields[1], TRUE); 1244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" second", fields[2], TRUE); 1245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("tag-b", fields[3], TRUE); 1246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" third", fields[4], TRUE); 1247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(!memcmp(&fields[5],&minus1,sizeof(UChar*))); 1248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /* "." at NUL positions */ 1250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(spaceNeeded == requiredCapacity); 1251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Split, end of text is a field delimiter. */ 1254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru sz = strlen("first <tag-a> second<tag-b>"); 1256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(re, textToSplit, sz, &status); 1257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru memset(fields, -1, sizeof(fields)); 1262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numFields = 1263f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_split(re, buf, UPRV_LENGTHOF(buf), &requiredCapacity, fields, 9, &status); 1264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* The TEST_ASSERT_SUCCESS call above should change too... */ 1267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_SUCCESS(status)) { 1268b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT(numFields == 5); 1269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("first ", fields[0], TRUE); 1270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("tag-a", fields[1], TRUE); 1271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING(" second", fields[2], TRUE); 1272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("tag-b", fields[3], TRUE); 1273b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT_STRING("", fields[4], TRUE); 1274b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT(fields[5] == NULL); 1275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(fields[8] == NULL); 1276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(!memcmp(&fields[9],&minus1,sizeof(UChar*))); 1277b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho spaceNeeded = strlen("first .tag-a. second.tag-b.."); /* "." at NUL positions */ 1278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(spaceNeeded == requiredCapacity); 1279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(re); 1283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1285c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* 1286c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * set/getTimeLimit 1287c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 1288c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("abc$", "abcdef", 0); 1289c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_getTimeLimit(re, &status) == 0); 1290c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setTimeLimit(re, 1000, &status); 1291c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_getTimeLimit(re, &status) == 1000); 1292c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1293c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setTimeLimit(re, -1, &status); 1294c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); 1295c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru status = U_ZERO_ERROR; 1296c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_getTimeLimit(re, &status) == 1000); 1297c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 1298c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1299c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* 1300c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * set/get Stack Limit 1301c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 1302c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("abc$", "abcdef", 0); 1303c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_getStackLimit(re, &status) == 8000000); 1304c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setStackLimit(re, 40000, &status); 1305c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_getStackLimit(re, &status) == 40000); 1306c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1307c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setStackLimit(re, -1, &status); 1308c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR); 1309c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru status = U_ZERO_ERROR; 1310c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_getStackLimit(re, &status) == 40000); 1311c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 1312c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1313c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1314c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* 1315c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * Get/Set callback functions 1316c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * This test is copied from intltest regex/Callbacks 1317c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * The pattern and test data will run long enough to cause the callback 1318c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * to be invoked. The nested '+' operators give exponential time 1319c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * behavior with increasing string length. 1320c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 1321c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_SETUP("((.)+\\2)+x", "aaaaaaaaaaaaaaaaaaab", 0) 1322c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru callBackContext cbInfo = {4, 0, 0}; 1323c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const void *pContext = &cbInfo; 1324c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru URegexMatchCallback *returnedFn = &TestCallbackFn; 1325c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1326c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* Getting the callback fn when it hasn't been set must return NULL */ 1327c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_getMatchCallback(re, &returnedFn, &pContext, &status); 1328c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1329c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(returnedFn == NULL); 1330c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(pContext == NULL); 1331c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1332c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* Set thecallback and do a match. */ 1333c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* The callback function should record that it has been called. */ 1334c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_setMatchCallback(re, &TestCallbackFn, &cbInfo, &status); 1335c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1336c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(cbInfo.numCalls == 0); 1337c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(uregex_matches(re, -1, &status) == FALSE); 1338c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT_SUCCESS(status); 1339c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(cbInfo.numCalls > 0); 1340c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1341c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* Getting the callback should return the values that were set above. */ 1342c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru uregex_getMatchCallback(re, &returnedFn, &pContext, &status); 1343c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(returnedFn == &TestCallbackFn); 1344c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_ASSERT(pContext == &cbInfo); 1345c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1346c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TEST_TEARDOWN; 1347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1349c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1350c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestBug4315(void) { 1352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode theICUError = U_ZERO_ERROR; 1353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru URegularExpression *theRegEx; 1354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *textBuff; 1355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *thePattern; 1356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar theString[100]; 1357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *destFields[24]; 1358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t neededLength1; 1359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t neededLength2; 1360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t wordCount = 0; 1362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t destFieldsSize = 24; 1363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru thePattern = "ck "; 1365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_uastrcpy(theString, "The quick brown fox jumped over the slow black turtle."); 1366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* open a regex */ 1368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru theRegEx = uregex_openC(thePattern, 0, NULL, &theICUError); 1369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(theICUError); 1370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* set the input string */ 1372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_setText(theRegEx, theString, u_strlen(theString), &theICUError); 1373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(theICUError); 1374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* split */ 1376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /*explicitly pass NULL and 0 to force the overflow error -> this is where the 1377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * error occurs! */ 1378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wordCount = uregex_split(theRegEx, NULL, 0, &neededLength1, destFields, 1379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destFieldsSize, &theICUError); 1380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(theICUError == U_BUFFER_OVERFLOW_ERROR); 1382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(wordCount==3); 1383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(theICUError == U_BUFFER_OVERFLOW_ERROR) 1385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru theICUError = U_ZERO_ERROR; 1387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru textBuff = (UChar *) malloc(sizeof(UChar) * (neededLength1 + 1)); 1388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wordCount = uregex_split(theRegEx, textBuff, neededLength1+1, &neededLength2, 1389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destFields, destFieldsSize, &theICUError); 1390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(wordCount==3); 1391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_SUCCESS(theICUError); 1392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(neededLength1 == neededLength2); 1393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("The qui", destFields[0], TRUE); 1394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("brown fox jumped over the slow bla", destFields[1], TRUE); 1395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT_STRING("turtle.", destFields[2], TRUE); 1396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TEST_ASSERT(destFields[3] == NULL); 1397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(textBuff); 1398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uregex_close(theRegEx); 1400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 140250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/* Based on TestRegexCAPI() */ 140350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestUTextAPI(void) { 140450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode status = U_ZERO_ERROR; 140550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho URegularExpression *re; 140650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText patternText = UTEXT_INITIALIZER; 140750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar pat[200]; 140850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char patternTextUTF8[5] = { 0x61, 0x62, 0x63, 0x2a, 0x00 }; 140950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 141050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Mimimalist open/close */ 141150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&patternText, patternTextUTF8, -1, &status); 141250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openUText(&patternText, 0, 0, &status); 141350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(status)) { 141450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_data_err("Failed to open regular expression, %s:%d, error is \"%s\" (Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status)); 141550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&patternText); 141650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return; 141750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 141850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 141950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 142050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Open with all flag values set */ 142150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 142250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openUText(&patternText, 142350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS | UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD, 142450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0, &status); 142550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 142650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 142750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 142850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Open with an invalid flag */ 142950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 143050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openUText(&patternText, 0x40000000, 0, &status); 143150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(status == U_REGEX_INVALID_FLAG); 143250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 143350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 143450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* open with an invalid parameter */ 143550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 143650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openUText(NULL, 143750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS | UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD, 0, &status); 143850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR && re == NULL); 143950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 144050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 144150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * clone 144250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 144350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 144450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho URegularExpression *clone1; 144550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho URegularExpression *clone2; 144650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho URegularExpression *clone3; 144750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar testString1[30]; 144850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar testString2[30]; 144950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UBool result; 145050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 145150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 145250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 145350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openUText(&patternText, 0, 0, &status); 145450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 145550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho clone1 = uregex_clone(re, &status); 145650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 145750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(clone1 != NULL); 145850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 145950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 146050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho clone2 = uregex_clone(re, &status); 146150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 146250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(clone2 != NULL); 146350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 146450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 146550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 146650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho clone3 = uregex_clone(clone2, &status); 146750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 146850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(clone3 != NULL); 146950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 1470f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(testString1, "abcccd", UPRV_LENGTHOF(pat)); 1471f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(testString2, "xxxabcccd", UPRV_LENGTHOF(pat)); 147250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 147350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 147450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(clone1, testString1, -1, &status); 147550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 147650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_lookingAt(clone1, 0, &status); 147750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 147850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result==TRUE); 147950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 148050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 148150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(clone2, testString2, -1, &status); 148250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 148350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_lookingAt(clone2, 0, &status); 148450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 148550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result==FALSE); 148650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_find(clone2, 0, &status); 148750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 148850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result==TRUE); 148950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 149050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(clone1); 149150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(clone2); 149250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(clone3); 149350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 149450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 149550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 149650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 149750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * pattern() and patternText() 149850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 149950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 150050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const UChar *resultPat; 150150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t resultLen; 150250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText *resultText; 150350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_hello[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00 }; /* hello */ 150450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_hel[] = { 0x68, 0x65, 0x6c, 0x00 }; /* hel */ 1505f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(pat, "hello", UPRV_LENGTHOF(pat)); /* for comparison */ 150650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 150750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 150850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&patternText, str_hello, -1, &status); 150950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_open(pat, -1, 0, NULL, &status); 151050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultPat = uregex_pattern(re, &resultLen, &status); 151150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 151250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 151350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS above should change too... */ 151450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_SUCCESS(status)) { 151550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(resultLen == -1); 151650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(u_strcmp(resultPat, pat) == 0); 151750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 151850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 151950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultText = uregex_patternUText(re, &status); 152050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 152150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_hello, resultText); 152250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 152350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 152450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 152550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 152650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_open(pat, 3, 0, NULL, &status); 152750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultPat = uregex_pattern(re, &resultLen, &status); 152850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 152950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 153050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS above should change too... */ 153150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_SUCCESS(status)) { 153250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(resultLen == 3); 153350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(u_strncmp(resultPat, pat, 3) == 0); 153450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(u_strlen(resultPat) == 3); 153550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 153650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 153750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultText = uregex_patternUText(re, &status); 153850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 153950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_hel, resultText); 154050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 154150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 154250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 154350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 154450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 154550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * setUText() and lookingAt() 154650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 154750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 154850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText text1 = UTEXT_INITIALIZER; 154950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText text2 = UTEXT_INITIALIZER; 155050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UBool result; 155150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_abcccd[] = { 0x62, 0x63, 0x64, 0x64, 0x64, 0x65, 0x00 }; /* abcccd */ 155250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_abcccxd[] = { 0x62, 0x63, 0x64, 0x64, 0x64, 0x79, 0x65, 0x00 }; /* abcccxd */ 155350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_abcd[] = { 0x62, 0x63, 0x64, 0x2b, 0x65, 0x00 }; /* abc*d */ 155450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 155550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&text1, str_abcccd, -1, &status); 155650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&text2, str_abcccxd, -1, &status); 155750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 155850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&patternText, str_abcd, -1, &status); 155950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openUText(&patternText, 0, NULL, &status); 156050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 156150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 156250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Operation before doing a setText should fail... */ 156350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 156450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_lookingAt(re, 0, &status); 156550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT( status== U_REGEX_INVALID_STATE); 156650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 156750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 156850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setUText(re, &text1, &status); 156950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_lookingAt(re, 0, &status); 157050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 157150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 157250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 157350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 157450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setUText(re, &text2, &status); 157550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_lookingAt(re, 0, &status); 157650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == FALSE); 157750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 157850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 157950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 158050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setUText(re, &text1, &status); 158150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_lookingAt(re, 0, &status); 158250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 158350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 158450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 158550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 158650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&text1); 158750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&text2); 158850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 158950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 159050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 159150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 159250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * getText() and getUText() 159350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 159450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 159550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText text1 = UTEXT_INITIALIZER; 159650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText text2 = UTEXT_INITIALIZER; 159750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text2Chars[20]; 159850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText *resultText; 159950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const UChar *result; 160050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t textLength; 160150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_abcccd[] = { 0x62, 0x63, 0x64, 0x64, 0x64, 0x65, 0x00 }; /* abcccd */ 160250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_abcccxd[] = { 0x62, 0x63, 0x64, 0x64, 0x64, 0x79, 0x65, 0x00 }; /* abcccxd */ 160350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_abcd[] = { 0x62, 0x63, 0x64, 0x2b, 0x65, 0x00 }; /* abc*d */ 160450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 160550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 160650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 160750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&text1, str_abcccd, -1, &status); 1608f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2Chars, str_abcccxd, UPRV_LENGTHOF(text2Chars)); 160950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUChars(&text2, text2Chars, -1, &status); 161050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 161150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&patternText, str_abcd, -1, &status); 161250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openUText(&patternText, 0, NULL, &status); 161350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 161450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* First set a UText */ 161550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setUText(re, &text1, &status); 161650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultText = uregex_getUText(re, NULL, &status); 161750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 161850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(resultText != &text1); 161950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_setNativeIndex(resultText, 0); 162050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_setNativeIndex(&text1, 0); 162183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius TEST_ASSERT(testUTextEqual(resultText, &text1)); 162250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(resultText); 162350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 162450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_getText(re, &textLength, &status); /* flattens UText into buffer */ 162559d709d503bab6e2b61931737e662dd293b40578ccornelius (void)result; /* Suppress set but not used warning. */ 162650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(textLength == -1 || textLength == 6); 162750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultText = uregex_getUText(re, NULL, &status); 162850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 162950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(resultText != &text1); 163050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_setNativeIndex(resultText, 0); 163150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_setNativeIndex(&text1, 0); 163283a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius TEST_ASSERT(testUTextEqual(resultText, &text1)); 163350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(resultText); 163450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 163550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Then set a UChar * */ 163650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text2Chars, 7, &status); 163750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultText = uregex_getUText(re, NULL, &status); 163850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 163950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_setNativeIndex(resultText, 0); 164050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_setNativeIndex(&text2, 0); 164183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius TEST_ASSERT(testUTextEqual(resultText, &text2)); 164250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(resultText); 164350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_getText(re, &textLength, &status); 164450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(textLength == 7); 164550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 164650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 164750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&text1); 164850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&text2); 164950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 165050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 165150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 165250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * matches() 165350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 165450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 165550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText text1 = UTEXT_INITIALIZER; 165650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UBool result; 165750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText nullText = UTEXT_INITIALIZER; 165850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_abcccde[] = { 0x61, 0x62, 0x63, 0x63, 0x63, 0x64, 0x65, 0x00 }; /* abcccde */ 165950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_abcd[] = { 0x61, 0x62, 0x63, 0x2a, 0x64, 0x00 }; /* abc*d */ 166050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 166150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 166250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&text1, str_abcccde, -1, &status); 166350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&patternText, str_abcd, -1, &status); 166450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openUText(&patternText, 0, NULL, &status); 166550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 166650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setUText(re, &text1, &status); 166750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_matches(re, 0, &status); 166850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == FALSE); 166950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 167050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 167150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 167250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 167350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC(".?", 0, NULL, &status); 167450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setUText(re, &text1, &status); 167550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_matches(re, 7, &status); 167650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 167750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 167850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 167950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 168050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&nullText, "", -1, &status); 168150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setUText(re, &nullText, &status); 168250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 168350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_matches(re, 0, &status); 168450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 168550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 168650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 168750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 168850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&text1); 168950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&nullText); 169050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 169150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 169250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 169350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 169450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * lookingAt() Used in setText test. 169550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 169650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 169750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 169850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 169950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * find(), findNext, start, end, reset 170050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 170150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 170250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text1[50]; 170350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UBool result; 1704f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "012rx5rx890rxrx...", UPRV_LENGTHOF(text1)); 170550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 170650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC("rx", 0, NULL, &status); 170750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 170850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text1, -1, &status); 170950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_find(re, 0, &status); 171050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 171150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_start(re, 0, &status) == 3); 171250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_end(re, 0, &status) == 5); 171350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 171450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 171550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_find(re, 9, &status); 171650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 171750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_start(re, 0, &status) == 11); 171850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_end(re, 0, &status) == 13); 171950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 172050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 172150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_find(re, 14, &status); 172250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == FALSE); 172350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 172450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 172550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 172650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_reset(re, 0, &status); 172750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 172850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_findNext(re, &status); 172950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 173050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_start(re, 0, &status) == 3); 173150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_end(re, 0, &status) == 5); 173250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 173350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 173450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_findNext(re, &status); 173550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 173650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_start(re, 0, &status) == 6); 173750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_end(re, 0, &status) == 8); 173850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 173950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 174050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 174150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_reset(re, 12, &status); 174250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 174350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_findNext(re, &status); 174450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == TRUE); 174550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_start(re, 0, &status) == 13); 174650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(uregex_end(re, 0, &status) == 15); 174750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 174850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 174950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_findNext(re, &status); 175050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result == FALSE); 175150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 175250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 175350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 175450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 175550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 175650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 17571b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * groupUText() 175850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 175950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 176050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text1[80]; 176150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText *actual; 176250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UBool result; 17631b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert int64_t groupLen = 0; 17641b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert UChar groupBuf[20]; 176550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 1766f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "noise abc interior def, and this is off the end", UPRV_LENGTHOF(text1)); 176750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 176850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 176950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC("abc(.*?)def", 0, NULL, &status); 177050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 177150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 177250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text1, -1, &status); 177350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_find(re, 0, &status); 177450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(result==TRUE); 177550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 177627f654740f2a26ad62a5c155af9199af9e69b889claireho /* Capture Group 0 with shallow clone API. Should succeed. */ 177727f654740f2a26ad62a5c155af9199af9e69b889claireho status = U_ZERO_ERROR; 17781b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert actual = uregex_groupUText(re, 0, NULL, &groupLen, &status); 17791b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert TEST_ASSERT_SUCCESS(status); 178027f654740f2a26ad62a5c155af9199af9e69b889claireho 17811b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert TEST_ASSERT(utext_getNativeIndex(actual) == 6); /* index of "abc " within "noise abc ..." */ 17821b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert TEST_ASSERT(groupLen == 16); /* length of "abc interior def" */ 17831b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert utext_extract(actual, 6 /*start index */, 6+16 /*limit index*/, groupBuf, sizeof(groupBuf), &status); 178427f654740f2a26ad62a5c155af9199af9e69b889claireho 17851b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert TEST_ASSERT_STRING("abc interior def", groupBuf, TRUE); 178627f654740f2a26ad62a5c155af9199af9e69b889claireho utext_close(actual); 178727f654740f2a26ad62a5c155af9199af9e69b889claireho 178850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Capture group #1. Should succeed. */ 178950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 17901b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert 17911b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert actual = uregex_groupUText(re, 1, NULL, &groupLen, &status); 179250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 17931b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert TEST_ASSERT(9 == utext_getNativeIndex(actual)); /* index of " interior " within "noise abc interior def ... " */ 17941b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert /* (within the string text1) */ 17951b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert TEST_ASSERT(10 == groupLen); /* length of " interior " */ 17961b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert utext_extract(actual, 9 /*start index*/, 9+10 /*limit index*/, groupBuf, sizeof(groupBuf), &status); 17971b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert TEST_ASSERT_STRING(" interior ", groupBuf, TRUE); 17981b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert 179950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(actual); 180050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 180150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Capture group out of range. Error. */ 180250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 18031b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert actual = uregex_groupUText(re, 2, NULL, &groupLen, &status); 180450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR); 180550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(actual); 180650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 180750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 180850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 180950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 181050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 181150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * replaceFirst() 181250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 181350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 181450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text1[80]; 181550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text2[80]; 181650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText replText = UTEXT_INITIALIZER; 181750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText *result; 181850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_Replxxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x20, 0x3c, 0x61, 0x61, 0x3e, 0x20, 0x78, 0x31, 0x78, 0x20, 0x78, 0x2e, 0x2e, 0x2e, 0x78, 0x2e, 0x00 }; /* Replace <aa> x1x x...x. */ 181950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ 18201b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert const char str_u00411U00000042a[] = { 0x5c, 0x5c, 0x5c, 0x75, 0x30, 0x30, 0x34, 0x31, 0x24, 0x31, 18211b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert 0x5c, 0x55, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x32, 0x5c, 0x24, 0x5c, 0x61, 0x00 }; /* \\\u0041$1\U00000042\$\a */ 182250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_1x[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ 182350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 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. */ 182450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 1825f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); 1826f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); 182750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&replText, str_1x, -1, &status); 182850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 182950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC("x(.*?)x", 0, NULL, &status); 183050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 183150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 183250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Normal case, with match */ 183350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text1, -1, &status); 183450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_replaceFirstUText(re, &replText, NULL, &status); 183550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 183650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_Replxxx, result); 183750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(result); 183850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 183950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* No match. Text should copy to output with no changes. */ 184050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text2, -1, &status); 184150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_replaceFirstUText(re, &replText, NULL, &status); 184250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 184350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_Nomatchhere, result); 184450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(result); 184550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 184650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Unicode escapes */ 184750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text1, -1, &status); 184850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&replText, str_u00411U00000042a, -1, &status); 184950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_replaceFirstUText(re, &replText, NULL, &status); 185050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 185150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_ReplaceAaaBax1xxx, result); 185250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(result); 185350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 185450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 185550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&replText); 185650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 185750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 185850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 185950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 186050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * replaceAll() 186150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 186250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 186350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text1[80]; 186450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text2[80]; 186550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText replText = UTEXT_INITIALIZER; 186650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText *result; 186750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_1[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ 186850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 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> <...>. */ 186950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ 187050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 1871f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); 1872f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); 187350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_openUTF8(&replText, str_1, -1, &status); 187450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 187550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC("x(.*?)x", 0, NULL, &status); 187650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 187750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 187850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Normal case, with match */ 187950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text1, -1, &status); 188050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_replaceAllUText(re, &replText, NULL, &status); 188150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 188250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_Replaceaa1, result); 188350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(result); 188450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 188550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* No match. Text should copy to output with no changes. */ 188650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text2, -1, &status); 188750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = uregex_replaceAllUText(re, &replText, NULL, &status); 188850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 188950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_Nomatchhere, result); 189050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(result); 189150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 189250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 189350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&replText); 189450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 189550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 189650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 189750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 189850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * appendReplacement() 189950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 190050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 190150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text[100]; 190250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar repl[100]; 190350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar buf[100]; 190450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *bufPtr; 190550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t bufCap; 190650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 190750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 190850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC(".*", 0, 0, &status); 190950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 191050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 1911f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text, "whatever", UPRV_LENGTHOF(text)); 1912f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(repl, "some other", UPRV_LENGTHOF(repl)); 191350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, text, -1, &status); 191450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 191550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* match covers whole target string */ 191650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_find(re, 0, &status); 191750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 191850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho bufPtr = buf; 1919f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius bufCap = UPRV_LENGTHOF(buf); 192050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); 192150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 192250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_STRING("some other", buf, TRUE); 192350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 192450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Match has \u \U escapes */ 192550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_find(re, 0, &status); 192650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 192750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho bufPtr = buf; 1928f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius bufCap = UPRV_LENGTHOF(buf); 19291b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ \\$ \\abc", UPRV_LENGTHOF(repl)); 193050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); 193150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 193250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); 193350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 193450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 193550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 193650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 193750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 193850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 193950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * appendReplacement(), appendTail() checked in replaceFirst(), replaceAll(). 194050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 194150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 194250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 194350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * splitUText() 194450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 194550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 194650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar textToSplit[80]; 194750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar text2[80]; 194850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText *fields[10]; 194950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t numFields; 195050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t i; 195150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 1952f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(textToSplit, "first : second: third", UPRV_LENGTHOF(textToSplit)); 1953f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); 195450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 195550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 195650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC(":", 0, NULL, &status); 195750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 195850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 195950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Simple split */ 196050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 196150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, textToSplit, -1, &status); 196250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 196350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 196450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 196550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_SUCCESS(status)) { 196650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(fields, 0, sizeof(fields)); 196750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numFields = uregex_splitUText(re, fields, 10, &status); 196850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 196950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 197050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 197150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 197250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_first[] = { 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x00 }; /* 'first ' */ 197350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_second[] = { 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x00 }; /* ' second' */ 197450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_third[] = { 0x20, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x00 }; /* ' third' */ 197550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(numFields == 3); 197650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_first, fields[0]); 197750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_second, fields[1]); 197850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_third, fields[2]); 197950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(fields[3] == NULL); 198050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 198150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < numFields; i++) { 198250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(fields[i]); 198350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 198450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 198550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 198650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 198750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 198850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 198950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Split with too few output strings available */ 199050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 199150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC(":", 0, NULL, &status); 199250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, textToSplit, -1, &status); 199350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 199450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 199550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 199650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 199750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[0] = NULL; 199850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[1] = NULL; 199950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[2] = &patternText; 200050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numFields = uregex_splitUText(re, fields, 2, &status); 200150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 200250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 200350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 200450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 200550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_first[] = { 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x00 }; /* first */ 200650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_secondthird[] = { 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x3a, 0x20, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x00 }; /* second: third */ 200750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(numFields == 2); 200850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_first, fields[0]); 200950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_secondthird, fields[1]); 201050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(fields[2] == &patternText); 201150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 201250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < numFields; i++) { 201350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(fields[i]); 201450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 201550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 201650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 201750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 201850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 201950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 202050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* splitUText(), part 2. Patterns with capture groups. The capture group text 202150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * comes out as additional fields. */ 202250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho { 202350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar textToSplit[80]; 202450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UText *fields[10]; 202550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t numFields; 202650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t i; 202750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 2028f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", UPRV_LENGTHOF(textToSplit)); 202950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 203050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 203150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho re = uregex_openC("<(.*?)>", 0, NULL, &status); 203250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 203350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, textToSplit, -1, &status); 203450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 203550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 203650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 203750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 203850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(fields, 0, sizeof(fields)); 203950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numFields = uregex_splitUText(re, fields, 10, &status); 204050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 204150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 204250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 204350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 204450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_first[] = { 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x00 }; /* first */ 204550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_taga[] = { 0x74, 0x61, 0x67, 0x2d, 0x61, 0x00 }; /* tag-a */ 204650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_second[] = { 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x00 }; /* second */ 204750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_tagb[] = { 0x74, 0x61, 0x67, 0x2d, 0x62, 0x00 }; /* tag-b */ 204850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_third[] = { 0x20, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x00 }; /* third */ 204950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 205050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(numFields == 5); 205150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_first, fields[0]); 205250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_taga, fields[1]); 205350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_second, fields[2]); 205450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_tagb, fields[3]); 205550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_third, fields[4]); 205650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(fields[5] == NULL); 205750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 205850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < numFields; i++) { 205950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(fields[i]); 206050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 206150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 206250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 206350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Split with too few output strings available (2) */ 206450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 206550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[0] = NULL; 206650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[1] = NULL; 206750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[2] = &patternText; 206850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numFields = uregex_splitUText(re, fields, 2, &status); 206950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 207050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 207150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 207250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 207350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_first[] = { 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x00 }; /* first */ 207450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_secondtagbthird[] = { 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x3c, 0x74, 0x61, 0x67, 0x2d, 0x62, 0x3e, 0x20, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x00 }; /* second<tag-b> third */ 207550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(numFields == 2); 207650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_first, fields[0]); 207750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_secondtagbthird, fields[1]); 207850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(fields[2] == &patternText); 207950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 208050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < numFields; i++) { 208150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(fields[i]); 208250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 208350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 208450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 208550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Split with too few output strings available (3) */ 208650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 208750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[0] = NULL; 208850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[1] = NULL; 208950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[2] = NULL; 209050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[3] = &patternText; 209150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numFields = uregex_splitUText(re, fields, 3, &status); 209250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 209350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 209450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 209550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 209650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_first[] = { 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x00 }; /* first */ 209750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_taga[] = { 0x74, 0x61, 0x67, 0x2d, 0x61, 0x00 }; /* tag-a */ 209850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_secondtagbthird[] = { 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x3c, 0x74, 0x61, 0x67, 0x2d, 0x62, 0x3e, 0x20, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x00 }; /* second<tag-b> third */ 209950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(numFields == 3); 210050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_first, fields[0]); 210150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_taga, fields[1]); 210250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_secondtagbthird, fields[2]); 210350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(fields[3] == &patternText); 210450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 210550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < numFields; i++) { 210650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(fields[i]); 210750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 210850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 210950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Split with just enough output strings available (5) */ 211050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 211150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[0] = NULL; 211250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[1] = NULL; 211350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[2] = NULL; 211450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[3] = NULL; 211550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[4] = NULL; 211650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[5] = &patternText; 211750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numFields = uregex_splitUText(re, fields, 5, &status); 211850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 211950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 212050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 212150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 212250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_first[] = { 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x00 }; /* first */ 212350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_taga[] = { 0x74, 0x61, 0x67, 0x2d, 0x61, 0x00 }; /* tag-a */ 212450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_second[] = { 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x00 }; /* second */ 212550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_tagb[] = { 0x74, 0x61, 0x67, 0x2d, 0x62, 0x00 }; /* tag-b */ 212650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_third[] = { 0x20, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x00 }; /* third */ 212750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 212850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(numFields == 5); 212950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_first, fields[0]); 213050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_taga, fields[1]); 213150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_second, fields[2]); 213250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_tagb, fields[3]); 213350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_third, fields[4]); 213450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(fields[5] == &patternText); 213550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 213650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < numFields; i++) { 213750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(fields[i]); 213850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 213950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 214050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* Split, end of text is a field delimiter. */ 214150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 214250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_setText(re, textToSplit, strlen("first <tag-a> second<tag-b>"), &status); 214350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 214450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 214550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 214650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 214750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(fields, 0, sizeof(fields)); 214850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho fields[9] = &patternText; 214950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numFields = uregex_splitUText(re, fields, 9, &status); 215050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_SUCCESS(status); 215150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 215250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* The TEST_ASSERT_SUCCESS call above should change too... */ 215350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_SUCCESS(status)) { 215450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_first[] = { 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x00 }; /* first */ 215550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_taga[] = { 0x74, 0x61, 0x67, 0x2d, 0x61, 0x00 }; /* tag-a */ 215650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_second[] = { 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x00 }; /* second */ 215750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char str_tagb[] = { 0x74, 0x61, 0x67, 0x2d, 0x62, 0x00 }; /* tag-b */ 2158b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho const char str_empty[] = { 0x00 }; 215950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 2160b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT(numFields == 5); 216150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_first, fields[0]); 216250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_taga, fields[1]); 216350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_second, fields[2]); 216450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT_UTEXT(str_tagb, fields[3]); 2165b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT_UTEXT(str_empty, fields[4]); 2166b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT(fields[5] == NULL); 216750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(fields[8] == NULL); 216850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho TEST_ASSERT(fields[9] == &patternText); 216950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 217050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < numFields; i++) { 217150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(fields[i]); 217250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 217350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 217450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 217550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uregex_close(re); 217650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 217750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho utext_close(&patternText); 217850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 217950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 2180b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 21812e615e9896b12236afe0ff2695e8afc2ee73f961clairehostatic void TestRefreshInput(void) { 21822e615e9896b12236afe0ff2695e8afc2ee73f961claireho /* 21832e615e9896b12236afe0ff2695e8afc2ee73f961claireho * RefreshInput changes out the input of a URegularExpression without 21842e615e9896b12236afe0ff2695e8afc2ee73f961claireho * changing anything else in the match state. Used with Java JNI, 21852e615e9896b12236afe0ff2695e8afc2ee73f961claireho * when Java moves the underlying string storage. This test 21862e615e9896b12236afe0ff2695e8afc2ee73f961claireho * runs a find() loop, moving the text after the first match. 21872e615e9896b12236afe0ff2695e8afc2ee73f961claireho * The right number of matches should still be found. 21882e615e9896b12236afe0ff2695e8afc2ee73f961claireho */ 21892e615e9896b12236afe0ff2695e8afc2ee73f961claireho UChar testStr[] = {0x41, 0x20, 0x42, 0x20, 0x43, 0x0}; /* = "A B C" */ 21902e615e9896b12236afe0ff2695e8afc2ee73f961claireho UChar movedStr[] = { 0, 0, 0, 0, 0, 0}; 21912e615e9896b12236afe0ff2695e8afc2ee73f961claireho UErrorCode status = U_ZERO_ERROR; 21922e615e9896b12236afe0ff2695e8afc2ee73f961claireho URegularExpression *re; 21932e615e9896b12236afe0ff2695e8afc2ee73f961claireho UText ut1 = UTEXT_INITIALIZER; 21942e615e9896b12236afe0ff2695e8afc2ee73f961claireho UText ut2 = UTEXT_INITIALIZER; 2195b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 21962e615e9896b12236afe0ff2695e8afc2ee73f961claireho re = uregex_openC("[ABC]", 0, 0, &status); 21972e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT_SUCCESS(status); 21982e615e9896b12236afe0ff2695e8afc2ee73f961claireho 21992e615e9896b12236afe0ff2695e8afc2ee73f961claireho utext_openUChars(&ut1, testStr, -1, &status); 22002e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT_SUCCESS(status); 22012e615e9896b12236afe0ff2695e8afc2ee73f961claireho uregex_setUText(re, &ut1, &status); 22022e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT_SUCCESS(status); 22032e615e9896b12236afe0ff2695e8afc2ee73f961claireho 22042e615e9896b12236afe0ff2695e8afc2ee73f961claireho /* Find the first match "A" in the original string */ 22052e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT(uregex_findNext(re, &status)); 22062e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT(uregex_start(re, 0, &status) == 0); 2207b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 22082e615e9896b12236afe0ff2695e8afc2ee73f961claireho /* Move the string, kill the original string. */ 22092e615e9896b12236afe0ff2695e8afc2ee73f961claireho u_strcpy(movedStr, testStr); 22102e615e9896b12236afe0ff2695e8afc2ee73f961claireho u_memset(testStr, 0, u_strlen(testStr)); 22112e615e9896b12236afe0ff2695e8afc2ee73f961claireho utext_openUChars(&ut2, movedStr, -1, &status); 22122e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT_SUCCESS(status); 22132e615e9896b12236afe0ff2695e8afc2ee73f961claireho uregex_refreshUText(re, &ut2, &status); 22142e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT_SUCCESS(status); 22152e615e9896b12236afe0ff2695e8afc2ee73f961claireho 22162e615e9896b12236afe0ff2695e8afc2ee73f961claireho /* Find the following two matches, now working in the moved string. */ 22172e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT(uregex_findNext(re, &status)); 22182e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT(uregex_start(re, 0, &status) == 2); 22192e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT(uregex_findNext(re, &status)); 22202e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT(uregex_start(re, 0, &status) == 4); 22212e615e9896b12236afe0ff2695e8afc2ee73f961claireho TEST_ASSERT(FALSE == uregex_findNext(re, &status)); 22222e615e9896b12236afe0ff2695e8afc2ee73f961claireho 22232e615e9896b12236afe0ff2695e8afc2ee73f961claireho uregex_close(re); 22242e615e9896b12236afe0ff2695e8afc2ee73f961claireho} 22252e615e9896b12236afe0ff2695e8afc2ee73f961claireho 2226b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2227b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic void TestBug8421(void) { 2228b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho /* Bug 8421: setTimeLimit on a regular expresssion before setting text to be matched 2229b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho * was failing. 2230b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho */ 2231b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho URegularExpression *re; 2232b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UErrorCode status = U_ZERO_ERROR; 2233b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int32_t limit = -1; 2234b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2235b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho re = uregex_openC("abc", 0, 0, &status); 2236b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT_SUCCESS(status); 2237b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2238b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho limit = uregex_getTimeLimit(re, &status); 2239b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT_SUCCESS(status); 2240b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT(limit == 0); 2241b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2242b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho uregex_setTimeLimit(re, 100, &status); 2243b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT_SUCCESS(status); 2244b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho limit = uregex_getTimeLimit(re, &status); 2245b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT_SUCCESS(status); 2246b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TEST_ASSERT(limit == 100); 2247b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2248b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho uregex_close(re); 2249b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho} 2250b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2251f9878a236aa0d9662d8e40cafdaf2e04cd615835ccorneliusstatic UBool U_CALLCONV FindCallback(const void* context , int64_t matchIndex) { 2252f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return FALSE; 2253f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius} 2254f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2255f9878a236aa0d9662d8e40cafdaf2e04cd615835ccorneliusstatic UBool U_CALLCONV MatchCallback(const void *context, int32_t steps) { 2256f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return FALSE; 2257f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius} 2258f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2259f9878a236aa0d9662d8e40cafdaf2e04cd615835ccorneliusstatic void TestBug10815() { 2260f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius /* Bug 10815: uregex_findNext() does not set U_REGEX_STOPPED_BY_CALLER 2261f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius * when the callback function specified by uregex_setMatchCallback() returns FALSE 2262f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius */ 2263f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius URegularExpression *re; 2264f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius UErrorCode status = U_ZERO_ERROR; 2265f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius UChar text[100]; 2266f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2267f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2268f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius // findNext() with a find progress callback function. 2269f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2270f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius re = uregex_openC(".z", 0, 0, &status); 2271f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT_SUCCESS(status); 2272f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2273f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text, "Hello, World.", UPRV_LENGTHOF(text)); 2274f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_setText(re, text, -1, &status); 2275f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT_SUCCESS(status); 2276f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2277f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_setFindProgressCallback(re, FindCallback, NULL, &status); 2278f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT_SUCCESS(status); 2279f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2280f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_findNext(re, &status); 2281f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT(status == U_REGEX_STOPPED_BY_CALLER); 2282f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2283f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_close(re); 2284f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2285f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius // findNext() with a match progress callback function. 2286f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2287f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius status = U_ZERO_ERROR; 2288f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius re = uregex_openC("((xxx)*)*y", 0, 0, &status); 2289f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT_SUCCESS(status); 2290f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2291f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius // Pattern + this text gives an exponential time match. Without the callback to stop the match, 2292f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius // it will appear to be stuck in a (near) infinite loop. 2293f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius u_uastrncpy(text, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", UPRV_LENGTHOF(text)); 2294f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_setText(re, text, -1, &status); 2295f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT_SUCCESS(status); 2296f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2297f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_setMatchCallback(re, MatchCallback, NULL, &status); 2298f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT_SUCCESS(status); 2299f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2300f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_findNext(re, &status); 2301f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius TEST_ASSERT(status == U_REGEX_STOPPED_BY_CALLER); 2302f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2303f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius uregex_close(re); 2304f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius} 2305f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 2306b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */ 2308