[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/3.5/kdelibs/kjs
From: Luciano Montanaro <mikelima () cirulla ! net>
Date: 2005-12-21 16:31:54
Message-ID: 1135182714.518837.31174.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 490364 by montanaro:
Implement notempty flag for libc regexps.
Fixes string.replace() with global pattern, which is used for example by the
ads code for slashdot.
M +14 -10 regexp.cpp
--- branches/KDE/3.5/kdelibs/kjs/regexp.cpp #490363:490364
@@ -202,26 +202,30 @@
// map rmatch array to ovector used in PCRE case
nrSubPatterns = 0;
- for(uint j = 1; j < maxMatch && rmatch[j].rm_so >= 0 ; j++)
- nrSubPatterns++;
- int ovecsize = (nrSubPatterns+1)*3; // see above
+ for (uint j = 0; j < maxMatch && rmatch[j].rm_so >= 0 ; j++) {
+ nrSubPatterns++;
+ // if the nonEmpty flag is set, return a failed match if any of the
+ // subMatches happens to be an empty string.
+ if (m_notEmpty && rmatch[j].rm_so == rmatch[j].rm_eo)
+ return UString::null;
+ }
+ // Allow an ovector slot to return the (failed) match result.
+ if (nrSubPatterns == 0) nrSubPatterns = 1;
+
+ int ovecsize = (nrSubPatterns)*3; // see above
*ovector = new int[ovecsize];
- for (uint j = 0; j < nrSubPatterns + 1; j++) {
- if (j>maxMatch)
- break;
- (*ovector)[2*j] = rmatch[j].rm_so + i;
- (*ovector)[2*j+1] = rmatch[j].rm_eo + i;
+ for (uint j = 0; j < nrSubPatterns; j++) {
+ (*ovector)[2*j] = rmatch[j].rm_so + i;
+ (*ovector)[2*j+1] = rmatch[j].rm_eo + i;
}
#endif
*pos = (*ovector)[0];
-#ifdef HAVE_PCREPOSIX // TODO check this stuff in non-pcre mode
if ( *pos == (*ovector)[1] && (flgs & Global) )
{
// empty match, next try will be with m_notEmpty=true
m_notEmpty=true;
}
-#endif
return s.substr((*ovector)[0], (*ovector)[1] - (*ovector)[0]);
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic