summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorHerbert Dürr <hdu@apache.org>2013-01-14 09:50:06 +0000
committerEike Rathke <erack@redhat.com>2013-03-07 21:00:36 +0100
commitb514f0ce86e85d9be269ddf2e797befbbf3423f1 (patch)
tree073dc94eb5555c08c1a23ed921a41ae6a8380a19 /i18npool
parent783d3928b7d935e2a022f92318e00faa3efa6bc7 (diff)
i#121482# fix backwards regexp search for matches overlapping search start
(cherry picked from commit 854f4ad6c57be62bd922df08f603d8bfb7b918a5) Additionally fixed unit test, searching backward shall not produce a different result from searching forward. (erAck) Change-Id: I952509276875441005e6a4036e6c3089be627dd9
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/qa/cppunit/test_textsearch.cxx2
-rw-r--r--i18npool/source/search/textsearch.cxx8
2 files changed, 8 insertions, 2 deletions
diff --git a/i18npool/qa/cppunit/test_textsearch.cxx b/i18npool/qa/cppunit/test_textsearch.cxx
index c26550b950ca..d7a6c3349146 100644
--- a/i18npool/qa/cppunit/test_textsearch.cxx
+++ b/i18npool/qa/cppunit/test_textsearch.cxx
@@ -101,7 +101,7 @@ void TestTextSearch::testSearches()
sal_Int32 startPos = 2, endPos = 20 ;
OUString searchStr( "(ab)*a(c|d)+" );
sal_Int32 fStartRes = 10, fEndRes = 18 ;
- sal_Int32 bStartRes = 18, bEndRes = 14 ;
+ sal_Int32 bStartRes = 18, bEndRes = 10 ;
// set options
util::SearchOptions aOptions;
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index 2df126e831fb..65ab5e487bb4 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -774,9 +774,15 @@ SearchResult TextSearch::RESrchBkwrd( const OUString& searchStr,
// find the last match
int nLastPos = 0;
+ int nFoundEnd = 0;
do {
nLastPos = pRegexMatcher->start( nIcuErr);
- } while( pRegexMatcher->find( nLastPos + 1, nIcuErr));
+ nFoundEnd = pRegexMatcher->end( nIcuErr);
+ if( nFoundEnd >= startPos)
+ break;
+ if( nFoundEnd == nLastPos)
+ ++nFoundEnd;
+ } while( pRegexMatcher->find( nFoundEnd, nIcuErr));
// find last match again to get its details
pRegexMatcher->find( nLastPos, nIcuErr);