incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject svn commit: r1228084 - /incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx
Date Fri, 06 Jan 2012 11:12:56 GMT
Author: hdu
Date: Fri Jan  6 11:12:55 2012
New Revision: 1228084

URL: http://svn.apache.org/viewvc?rev=1228084&view=rev
Log:
#i118723# fill in regexp matcher group details

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=1228084&r1=1228083&r2=1228084&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/search/textsearch.cxx Fri Jan  6 11:12:55 2012
@@ -741,11 +741,16 @@ SearchResult TextSearch::RESrchFrwrd( co
 	if( !pRegexMatcher->find( startPos, nIcuErr))
 		return aRet;
 
-	aRet.subRegExpressions = 1;
+	const int nGroupCount = pRegexMatcher->groupCount();
+	aRet.subRegExpressions = nGroupCount + 1;
 	aRet.startOffset.realloc( aRet.subRegExpressions);
 	aRet.endOffset.realloc( aRet.subRegExpressions);
 	aRet.startOffset[0] = pRegexMatcher->start( nIcuErr);
 	aRet.endOffset[0]   = pRegexMatcher->end( nIcuErr);
+	for( int i = 1; i <= nGroupCount; ++i) {
+		aRet.startOffset[i] = pRegexMatcher->start( i, nIcuErr);
+		aRet.endOffset[i]   = pRegexMatcher->end( i, nIcuErr);
+	}
 
 	return aRet;
 }
@@ -765,21 +770,34 @@ SearchResult TextSearch::RESrchBkwrd( co
 
 	// use the ICU RegexMatcher to find the matches
 	// TODO: use ICU's backward searching once it becomes available
+	//       as its replacement using forward search is not as good as the real thing
 	UErrorCode nIcuErr = U_ZERO_ERROR;
 	const IcuUniString aSearchTargetStr( searchStr.getStr(), startPos);
 	pRegexMatcher->reset( aSearchTargetStr);
 	if( !pRegexMatcher->find( endPos, nIcuErr))
 		return aRet;
 
-	aRet.subRegExpressions = 1;
+	// find the last match
+	int nLastPos = 0;
+	do {
+		nLastPos = pRegexMatcher->start( nIcuErr);
+	} while( pRegexMatcher->find( nLastPos + 1, nIcuErr));
+
+	// find last match again to get its details
+	pRegexMatcher->find( nLastPos, nIcuErr);
+
+	// fill in the details of the last match
+	const int nGroupCount = pRegexMatcher->groupCount();
+	aRet.subRegExpressions = nGroupCount + 1;
 	aRet.startOffset.realloc( aRet.subRegExpressions);
 	aRet.endOffset.realloc( aRet.subRegExpressions);
-
-	do {
-		// NOTE: backward search seems to be expected to have startOfs/endOfs inverted!
-		aRet.startOffset[0] = pRegexMatcher->end( nIcuErr);
-		aRet.endOffset[0]   = pRegexMatcher->start( nIcuErr);
-	} while( pRegexMatcher->find( aRet.endOffset[0]+1, nIcuErr));
+	// NOTE: existing users of backward search seem to expect startOfs/endOfs being inverted!
+	aRet.startOffset[0] = pRegexMatcher->end( nIcuErr);
+	aRet.endOffset[0]   = pRegexMatcher->start( nIcuErr);
+	for( int i = 1; i <= nGroupCount; ++i) {
+		aRet.startOffset[i] = pRegexMatcher->end( i, nIcuErr);
+		aRet.endOffset[i]   = pRegexMatcher->start( i, nIcuErr);
+	}
 
 	return aRet;
 }



Mime
View raw message