sw/source/core/crsr/findtxt.cxx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
New commits: commit 9bb369edf5471d0b29b5cea86d7203831f93d529 Author: Justin Luth <justin_l...@sil.org> Date: Wed Feb 7 20:17:31 2018 +0300 tdf#102374: regex allow ReplaceBackReferences for $ search Since searching for $ spans nodes, and normal searches don't find it (see bChkParaEnd and bChkEmptyPara), all "replace" items were being used verbatim instead of being transformed. So, a similar "just make it work" hack is needed here. This patch allows proper replacement for \[\&$t] as well as & and $0. Change-Id: I59d760e27acacff679decdcb7fcf337f3b4a1fa1 Reviewed-on: https://gerrit.libreoffice.org/49387 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Justin Luth <justin_l...@sil.org> Reviewed-by: Michael Stahl <mst...@redhat.com> diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx index cf98da007ba4..164fbb391e0b 100644 --- a/sw/source/core/crsr/findtxt.cxx +++ b/sw/source/core/crsr/findtxt.cxx @@ -758,15 +758,25 @@ OUString *ReplaceBackReferences( const i18nutil::SearchOptions2& rSearchOpt, SwP SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2 ) { const SwContentNode* pTextNode = pPam->GetContentNode(); - if( pTextNode && pTextNode->IsTextNode() && pTextNode == pPam->GetContentNode( false ) ) + const bool bParaEnd = rSearchOpt.searchString == "$" || rSearchOpt.searchString == "^$" || rSearchOpt.searchString == "$^"; + if ( pTextNode && pTextNode->IsTextNode() && (bParaEnd || pTextNode == pPam->GetContentNode( false )) ) { utl::TextSearch aSText( utl::TextSearch::UpgradeToSearchOptions2( rSearchOpt) ); - const OUString& rStr = pTextNode->GetTextNode()->GetText(); + OUString rStr = pTextNode->GetTextNode()->GetText(); sal_Int32 nStart = pPam->Start()->nContent.GetIndex(); sal_Int32 nEnd = pPam->End()->nContent.GetIndex(); SearchResult aResult; - if( aSText.SearchForward( rStr, &nStart, &nEnd, &aResult ) ) + if ( bParaEnd || aSText.SearchForward( rStr, &nStart, &nEnd, &aResult ) ) { + if ( bParaEnd ) + { + rStr = "\\n"; + aResult.subRegExpressions = 1; + aResult.startOffset.realloc(1); + aResult.endOffset.realloc(1); + aResult.startOffset[0] = 0; + aResult.endOffset[0] = rStr.getLength(); + } OUString aReplaceStr( rSearchOpt.replaceString ); aSText.ReplaceBackReferences( aReplaceStr, rStr, aResult ); pRet = new OUString( aReplaceStr ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits