You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by hd...@apache.org on 2012/02/09 09:28:30 UTC
svn commit: r1242235 -
/incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx
Author: hdu
Date: Thu Feb 9 08:28:29 2012
New Revision: 1242235
URL: http://svn.apache.org/viewvc?rev=1242235&view=rev
Log:
#i118887# ignore zero-length matches in regexp search
Modified:
incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx
Modified: incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx?rev=1242235&r1=1242234&r2=1242235&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx Thu Feb 9 08:28:29 2012
@@ -754,9 +754,23 @@ SearchResult TextSearch::RESrchFrwrd( co
UErrorCode nIcuErr = U_ZERO_ERROR;
const IcuUniString aSearchTargetStr( searchStr.getStr(), endPos);
pRegexMatcher->reset( aSearchTargetStr);
- if( !pRegexMatcher->find( startPos, nIcuErr))
- return aRet;
+ // search until there is a valid match
+ for(;;)
+ {
+ if( !pRegexMatcher->find( startPos, nIcuErr))
+ return aRet;
+
+ // #i118887# ignore zero-length matches e.g. "a*" in "bc"
+ int nStartOfs = pRegexMatcher->start( nIcuErr);
+ int nEndOfs = pRegexMatcher->end( nIcuErr);
+ if( nStartOfs < nEndOfs)
+ break;
+ // try at next position if there was a zero-length match
+ if( ++startPos >= endPos)
+ return aRet;
+ }
+ // extract the result of the search
const int nGroupCount = pRegexMatcher->groupCount();
aRet.subRegExpressions = nGroupCount + 1;
aRet.startOffset.realloc( aRet.subRegExpressions);