diff options
author | Justin Luth <justin_luth@sil.org> | 2018-02-07 20:17:31 +0300 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2018-02-14 10:40:34 +0100 |
commit | 5054456a6ed8ef7cd2a05fb09e1954eb02eaf0f7 (patch) | |
tree | 42c50756503a2932f2d1ec9122d9a97a00892715 | |
parent | 106f66e921da871c26ce6b642f9f67024417b93d (diff) |
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 <ci@libreoffice.org>
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
(cherry picked from commit 9bb369edf5471d0b29b5cea86d7203831f93d529)
Reviewed-on: https://gerrit.libreoffice.org/49679
-rw-r--r-- | sw/source/core/crsr/findtxt.cxx | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx index d63d66cbf41d..7d5842b883b4 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 ); |