mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-09 07:22:11 +00:00
ICU-4086 regex match/lookingAt/find at end of string with zero length match not working.
X-SVN-Rev: 16328
This commit is contained in:
parent
015097925c
commit
e04ddd2239
3 changed files with 52 additions and 8 deletions
|
@ -496,7 +496,7 @@ UBool RegexMatcher::find(int32_t start, UErrorCode &status) {
|
|||
return FALSE;
|
||||
}
|
||||
int32_t inputLen = fInput->length();
|
||||
if (start < 0 || start >= inputLen) {
|
||||
if (start < 0 || start > inputLen) {
|
||||
status = U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -583,7 +583,7 @@ UBool RegexMatcher::lookingAt(int32_t start, UErrorCode &status) {
|
|||
status = fDeferredStatus;
|
||||
return FALSE;
|
||||
}
|
||||
if (start < 0 || start >= fInput->length()) {
|
||||
if (start < 0 || start > fInput->length()) {
|
||||
status = U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -622,7 +622,7 @@ UBool RegexMatcher::matches(int32_t start, UErrorCode &status) {
|
|||
status = fDeferredStatus;
|
||||
return FALSE;
|
||||
}
|
||||
if (start < 0 || start >= fInput->length()) {
|
||||
if (start < 0 || start > fInput->length()) {
|
||||
status = U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -319,8 +319,11 @@ static void TestRegexCAPI(void) {
|
|||
* matches()
|
||||
*/
|
||||
{
|
||||
UChar text1[50];
|
||||
UBool result;
|
||||
UChar text1[50];
|
||||
UBool result;
|
||||
int len;
|
||||
UChar nullString[] = {0,0,0};
|
||||
|
||||
u_uastrncpy(text1, "abcccde", sizeof(text1)/2);
|
||||
status = U_ZERO_ERROR;
|
||||
u_uastrncpy(pat, "abc*d", sizeof(pat)/2);
|
||||
|
@ -344,6 +347,21 @@ static void TestRegexCAPI(void) {
|
|||
TEST_ASSERT_SUCCESS(status);
|
||||
uregex_close(re);
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
re = uregex_openC(".?", 0, NULL, &status);
|
||||
uregex_setText(re, text1, -1, &status);
|
||||
len = u_strlen(text1);
|
||||
result = uregex_matches(re, len, &status);
|
||||
TEST_ASSERT(result == TRUE);
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
uregex_setText(re, nullString, -1, &status);
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
result = uregex_matches(re, 0, &status);
|
||||
TEST_ASSERT(result == TRUE);
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
uregex_close(re);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -663,11 +663,33 @@ void RegexTest::API_Match() {
|
|||
REGEX_ASSERT(m1->matches(4, status) == TRUE);
|
||||
REGEX_ASSERT(m1->matches(-1, status) == FALSE);
|
||||
REGEX_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR);
|
||||
|
||||
// Match() at end of string should fail, but should not
|
||||
// be an error.
|
||||
status = U_ZERO_ERROR;
|
||||
len = m1->input().length();
|
||||
REGEX_ASSERT(m1->matches(len, status) == FALSE);
|
||||
REGEX_CHECK_STATUS;
|
||||
|
||||
// Match beyond end of string should fail with an error.
|
||||
status = U_ZERO_ERROR;
|
||||
REGEX_ASSERT(m1->matches(len+1, status) == FALSE);
|
||||
REGEX_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR);
|
||||
|
||||
|
||||
// Successful match at end of string.
|
||||
{
|
||||
status = U_ZERO_ERROR;
|
||||
RegexMatcher m("A?", 0, status); // will match zero length string.
|
||||
REGEX_CHECK_STATUS;
|
||||
m.reset(inStr1);
|
||||
len = inStr1.length();
|
||||
REGEX_ASSERT(m.matches(len, status) == TRUE);
|
||||
REGEX_CHECK_STATUS;
|
||||
m.reset(empty);
|
||||
REGEX_ASSERT(m.matches(0, status) == TRUE);
|
||||
REGEX_CHECK_STATUS;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// lookingAt(pos, status)
|
||||
|
@ -683,6 +705,8 @@ void RegexTest::API_Match() {
|
|||
status = U_ZERO_ERROR;
|
||||
len = m1->input().length();
|
||||
REGEX_ASSERT(m1->lookingAt(len, status) == FALSE);
|
||||
REGEX_CHECK_STATUS;
|
||||
REGEX_ASSERT(m1->lookingAt(len+1, status) == FALSE);
|
||||
REGEX_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR);
|
||||
|
||||
delete m1;
|
||||
|
@ -791,11 +815,13 @@ void RegexTest::API_Match() {
|
|||
REGEX_ASSERT(matcher->start(status) == 12);
|
||||
REGEX_ASSERT(matcher->find(13, status) == FALSE);
|
||||
REGEX_ASSERT(matcher->find(16, status) == FALSE);
|
||||
REGEX_ASSERT(matcher->find(17, status) == FALSE);
|
||||
REGEX_ASSERT_FAIL(matcher->start(status), U_REGEX_INVALID_STATE);
|
||||
REGEX_CHECK_STATUS;
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
REGEX_ASSERT_FAIL(matcher->find(-1, status), U_INDEX_OUTOFBOUNDS_ERROR);
|
||||
REGEX_ASSERT_FAIL(matcher->find(17, status), U_INDEX_OUTOFBOUNDS_ERROR);
|
||||
status = U_ZERO_ERROR;
|
||||
REGEX_ASSERT_FAIL(matcher->find(18, status), U_INDEX_OUTOFBOUNDS_ERROR);
|
||||
|
||||
REGEX_ASSERT(matcher->groupCount() == 0);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue