ICU-2902 regex, matches with no input behave as if input was an empty string

Change requested in code review.

X-SVN-Rev: 12045
This commit is contained in:
Andy Heninger 2003-05-22 00:51:23 +00:00
parent feeca769d5
commit 615e84ebe0
2 changed files with 28 additions and 3 deletions

View File

@ -23,6 +23,7 @@
#include "uvector.h"
#include "uvectr32.h"
#include "regeximp.h"
#include "regexst.h"
// #include <malloc.h> // Needed for heapcheck testing
@ -52,7 +53,7 @@ RegexMatcher::RegexMatcher(const RegexPattern *pat) {
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
}
reset();
reset(*RegexPattern::gStaticSets->fEmptyString);
}
@ -98,7 +99,7 @@ RegexMatcher::RegexMatcher(const UnicodeString &regexp,
if (fStack == NULL || fData == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
reset();
reset(*RegexPattern::gStaticSets->fEmptyString);
}

View File

@ -748,7 +748,31 @@ void RegexTest::API_Match() {
delete matcher;
delete pat;
}
//
// Matchers with no input string behave as if they had an empty input string.
//
{
UErrorCode status = U_ZERO_ERROR;
RegexMatcher m(".?", 0, status);
REGEX_CHECK_STATUS;
REGEX_ASSERT(m.find());
REGEX_ASSERT(m.start(status) == 0);
REGEX_ASSERT(m.input() == "");
}
{
UErrorCode status = U_ZERO_ERROR;
RegexPattern *p = RegexPattern::compile(".", 0, status);
RegexMatcher *m = p->matcher(status);
REGEX_CHECK_STATUS;
REGEX_ASSERT(m->find() == FALSE);
REGEX_ASSERT(m->input() == "");
delete m;
delete p;
}
}