[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - sw/source
Justin Luth
justin_luth at sil.org
Wed Feb 14 09:40:56 UTC 2018
sw/source/core/crsr/findtxt.cxx | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
New commits:
commit 5054456a6ed8ef7cd2a05fb09e1954eb02eaf0f7
Author: Justin Luth <justin_luth at 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 <ci at libreoffice.org>
Reviewed-by: Justin Luth <justin_luth at sil.org>
Reviewed-by: Michael Stahl <mstahl at redhat.com>
(cherry picked from commit 9bb369edf5471d0b29b5cea86d7203831f93d529)
Reviewed-on: https://gerrit.libreoffice.org/49679
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 );
More information about the Libreoffice-commits
mailing list