summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2018-02-07 20:17:31 +0300
committerMichael Stahl <mstahl@redhat.com>2018-02-13 16:49:28 +0100
commit9bb369edf5471d0b29b5cea86d7203831f93d529 (patch)
tree7e9e4af3d8b5edeaaba1c02bede39117f722df9d
parent2524f4528988a118eb4729a48b86d85a2d50967a (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>
-rw-r--r--sw/source/core/crsr/findtxt.cxx16
1 files changed, 13 insertions, 3 deletions
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 );