Details
Description
RegularExpression::matches(txt, pMatch) does not work in 2.8, 3.0.1
since pMatch is not updated correctly anymore.
// Test code - works with 2.7.0
XMLCh * txt = L"2004-06-17";
Match m;
RegularExpression r("(\\-?\\d+(\\-
d
d{2}
)?)?)?(T
d
d{2}
(:
d
d{2}
:
d
)?");
if(r.matches(txt, &m))
{
for(int i = 1; i < m.getNoGroups(); i++)
{
int i1 = m.getStartPos; // Should be 0
if(i1 < 0) // Is -1
{ printf("This is wrong!\n"); return; } }
}
Problem can be tracked via
bool RegularExpression::matches(const XMLCh* const expression, const XMLSize_t start
, const XMLSize_t end, Match* const pMatch
, MemoryManager* const manager) const;
which does
Match* lMatch = pMatch; // use our pMatch
context.fMatch = lMatch; // put pMatch into context
/*
- Straightforward matching
*/
for (matchStart=context.fStart; matchStart<=limit; matchStart++) { if (0 <= (matchEnd = match(&context,fOperations,matchStart))) break; }
and at the end updates the context fMatch data
if (matchEnd >= 0) {
if (context.fMatch != 0)
{ context.fMatch->setStartPos(0, (int)matchStart); context.fMatch->setEndPos(0, matchEnd); } return true;
}
But: context.fMatch is NOT the original match pointer (pMatch), but a temporal one.
So the correct result is not propagated back to the caller anymore.