diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-21 14:58:14 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-22 08:21:12 +0100 |
commit | 05044640531055c86b34f1c6ec8055c8a0ca3df8 (patch) | |
tree | bd5a756138f618ee54f48f3f4df8d07ccd905e67 /sw | |
parent | 03fcb4aae62a9403f22ec3671b61555419d02514 (diff) |
use boost::optional for OUString
instead of storing on heap
Change-Id: I4ca2bb58ec4f71b161c9e6081f5e456de54d8153
Reviewed-on: https://gerrit.libreoffice.org/65537
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/crsrsh.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/crsr/findattr.cxx | 8 | ||||
-rw-r--r-- | sw/source/core/crsr/findtxt.cxx | 18 | ||||
-rw-r--r-- | sw/source/uibase/uiview/viewsrch.cxx | 9 |
4 files changed, 18 insertions, 19 deletions
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx index a5c8e1acc4d2..423ed92fb1b4 100644 --- a/sw/inc/crsrsh.hxx +++ b/sw/inc/crsrsh.hxx @@ -132,7 +132,7 @@ bool ReplaceImpl(SwPaM & rCursor, OUString const& rReplacement, bool const bRegExp, SwDoc & rDoc, SwRootFrame const*const pLayout); /// Helperfunction to resolve backward references in regular expressions -OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt, +boost::optional<OUString> ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt, SwPaM* pPam, SwRootFrame const* pLayout ); bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges, diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx index 2fa9c20cb01a..bb6b5d34fa38 100644 --- a/sw/source/core/crsr/findattr.cxx +++ b/sw/source/core/crsr/findattr.cxx @@ -1313,11 +1313,11 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove, const_cast<SwPaM &>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() ); } - std::unique_ptr<OUString> pRepl(bRegExp - ? sw::ReplaceBackReferences(*pSearchOpt, &rCursor, m_pLayout) - : nullptr); + boost::optional<OUString> xRepl; + if (bRegExp) + xRepl = sw::ReplaceBackReferences(*pSearchOpt, &rCursor, m_pLayout); sw::ReplaceImpl(rCursor, - pRepl ? *pRepl : pSearchOpt->replaceString, bRegExp, + xRepl ? *xRepl : pSearchOpt->replaceString, bRegExp, *m_rCursor.GetDoc(), m_pLayout); m_rCursor.SaveTableBoxContent( rCursor.GetPoint() ); diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx index 796eeeeb4454..eeba1415994c 100644 --- a/sw/source/core/crsr/findtxt.cxx +++ b/sw/source/core/crsr/findtxt.cxx @@ -941,11 +941,11 @@ int SwFindParaText::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove, const_cast<SwPaM&>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() ); } - std::unique_ptr<OUString> pRepl( bRegExp - ? sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout) - : nullptr ); + boost::optional<OUString> xRepl; + if (bRegExp) + xRepl = sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout); bool const bReplaced = sw::ReplaceImpl(rCursor, - pRepl ? *pRepl : m_rSearchOpt.replaceString, + xRepl ? *xRepl : m_rSearchOpt.replaceString, bRegExp, *m_rCursor.GetDoc(), m_pLayout); m_rCursor.SaveTableBoxContent( rCursor.GetPoint() ); @@ -1084,17 +1084,17 @@ bool ReplaceImpl( return bReplaced; } -OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt, +boost::optional<OUString> ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt, SwPaM *const pPam, SwRootFrame const*const pLayout) { - OUString *pRet = nullptr; + boost::optional<OUString> xRet; if( pPam && pPam->HasMark() && SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2 ) { const SwContentNode* pTextNode = pPam->GetContentNode(); if (!pTextNode || !pTextNode->IsTextNode()) { - return pRet; + return xRet; } SwTextFrame const*const pFrame(pLayout ? static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(pLayout)) @@ -1135,11 +1135,11 @@ OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt, } OUString aReplaceStr( rSearchOpt.replaceString ); aSText.ReplaceBackReferences( aReplaceStr, rStr, aResult ); - pRet = new OUString( aReplaceStr ); + xRet = aReplaceStr; } } } - return pRet; + return xRet; } } // namespace sw diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx index c4d6bf2fce8b..a127c1a12241 100644 --- a/sw/source/uibase/uiview/viewsrch.cxx +++ b/sw/source/uibase/uiview/viewsrch.cxx @@ -309,15 +309,14 @@ void SwView::ExecSearch(SfxRequest& rReq) m_pWrtShell->Push(); OUString aReplace( m_pSrchItem->GetReplaceString() ); i18nutil::SearchOptions2 aTmp( m_pSrchItem->GetSearchOptions() ); - OUString *pBackRef = sw::ReplaceBackReferences(aTmp, + boost::optional<OUString> xBackRef = sw::ReplaceBackReferences(aTmp, m_pWrtShell->GetCursor(), m_pWrtShell->GetLayout()); - if( pBackRef ) - m_pSrchItem->SetReplaceString( *pBackRef ); + if( xBackRef ) + m_pSrchItem->SetReplaceString( *xBackRef ); Replace(); - if( pBackRef ) + if( xBackRef ) { m_pSrchItem->SetReplaceString( aReplace ); - delete pBackRef; } if (bBack) { |