i18npool/source/search/textsearch.cxx | 14 +++++++++++--- sw/qa/extras/uiwriter/uiwriter.cxx | 13 +++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-)
New commits: commit 0cd3b7926cafc01d06b589124215e9cb7c148f19 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Dec 19 11:37:59 2019 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Dec 19 10:59:01 2019 +0100 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.kagan...@collabora.com> 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() _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits