diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-12-19 11:37:59 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-12-19 10:59:01 +0100 |
commit | 0cd3b7926cafc01d06b589124215e9cb7c148f19 (patch) | |
tree | 5b33e179bf7ec020ca0b99d0618fa997e44c543c | |
parent | fe17fd7b0fe2bb4a0db44fb46297ecafb2886366 (diff) |
tdf#65038: use trailing string characters for look-ahead assertions
... like commit eb973a46ba0e34026db2d2929f2aa10505623872 did for
look-behind assertions
Change-Id: I86ece5d3ee49b0c5d86f2cfab5fed2830d5ad777
Reviewed-on: https://gerrit.libreoffice.org/85487
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | i18npool/source/search/textsearch.cxx | 14 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 13 |
2 files changed, 24 insertions, 3 deletions
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx index b0361bee89a3..c74e158780f4 100644 --- a/i18npool/source/search/textsearch.cxx +++ b/i18npool/source/search/textsearch.cxx @@ -323,9 +323,16 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta const sal_Int32 nMaxLeadingLen = aSrchPara.searchString.startsWith("(?") ? 100 : 3; nInStartPos -= std::min(nMaxLeadingLen, startPos); } + sal_Int32 nInEndPos = endPos; + if (pRegexMatcher && endPos < searchStr.getLength()) + { + // tdf#65038: ditto for look-ahead assertions + const sal_Int32 nMaxTrailingLen = aSrchPara.searchString.endsWith(")") ? 100 : 3; + nInEndPos += std::min(nMaxTrailingLen, searchStr.getLength() - endPos); + } - css::uno::Sequence<sal_Int32> offset(endPos - nInStartPos); - in_str = xTranslit->transliterate( searchStr, nInStartPos, endPos - nInStartPos, offset ); + css::uno::Sequence<sal_Int32> offset(nInEndPos - nInStartPos); + in_str = xTranslit->transliterate(searchStr, nInStartPos, nInEndPos - nInStartPos, offset); // JP 20.6.2001: also the start and end positions must be corrected! sal_Int32 newStartPos = @@ -907,7 +914,8 @@ SearchResult TextSearch::RESrchFrwrd( const OUString& searchStr, // use the ICU RegexMatcher to find the matches UErrorCode nIcuErr = U_ZERO_ERROR; - const IcuUniString aSearchTargetStr( reinterpret_cast<const UChar*>(searchStr.getStr()), endPos); + const IcuUniString aSearchTargetStr(reinterpret_cast<const UChar*>(searchStr.getStr()), + searchStr.getLength()); pRegexMatcher->reset( aSearchTargetStr); // search until there is a valid match for(;;) diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index cc51519f61fd..4790a602bbbf 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -2284,6 +2284,19 @@ void SwUiWriterTest::testTextSearch() // check of the end result CPPUNIT_ASSERT_EQUAL(OUString("xCelqy xWorqd xThzq xis xa xtasq"), pCursor->GetNode().GetTextNode()->GetText()); + // regex: use positive look-ahead assertion + xReplaceDes->setSearchString("Wor(?=qd xThzq xis xa xtasq)"); + xReplaceDes->setReplaceString("&p"); // testing & reference + ReplaceCount = xReplace->replaceAll(xReplaceDes); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount); + // regex: use negative look-ahead assertion + xReplaceDes->setSearchString("x(?!Worpqd xThzq xis xa xtasq)"); + xReplaceDes->setReplaceString("m"); + ReplaceCount = xReplace->replaceAll(xReplaceDes); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ReplaceCount); // one of the 6 "x" must not be replaced + // check of the end result + CPPUNIT_ASSERT_EQUAL(OUString("mCelqy xWorpqd mThzq mis ma mtasq"), + pCursor->GetNode().GetTextNode()->GetText()); } void SwUiWriterTest::testTdf69282() |