Kaydet (Commit) 05044640 authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 03fcb4aa
...@@ -99,7 +99,7 @@ OUString SAL_CALL ...@@ -99,7 +99,7 @@ OUString SAL_CALL
OfficeInstallationDirectories::getOfficeInstallationDirectoryURL() OfficeInstallationDirectories::getOfficeInstallationDirectoryURL()
{ {
initDirs(); initDirs();
return *m_pOfficeBrandDir; return *m_xOfficeBrandDir;
} }
...@@ -108,7 +108,7 @@ OUString SAL_CALL ...@@ -108,7 +108,7 @@ OUString SAL_CALL
OfficeInstallationDirectories::getOfficeUserDataDirectoryURL() OfficeInstallationDirectories::getOfficeUserDataDirectoryURL()
{ {
initDirs(); initDirs();
return *m_pUserDir; return *m_xUserDir;
} }
...@@ -124,22 +124,22 @@ OfficeInstallationDirectories::makeRelocatableURL( const OUString& URL ) ...@@ -124,22 +124,22 @@ OfficeInstallationDirectories::makeRelocatableURL( const OUString& URL )
OUString aCanonicalURL( URL ); OUString aCanonicalURL( URL );
makeCanonicalFileURL( aCanonicalURL ); makeCanonicalFileURL( aCanonicalURL );
sal_Int32 nIndex = aCanonicalURL.indexOf( *m_pOfficeBrandDir ); sal_Int32 nIndex = aCanonicalURL.indexOf( *m_xOfficeBrandDir );
if ( nIndex != -1 ) if ( nIndex != -1 )
{ {
return return
aCanonicalURL.replaceAt( nIndex, aCanonicalURL.replaceAt( nIndex,
m_pOfficeBrandDir->getLength(), m_xOfficeBrandDir->getLength(),
g_aOfficeBrandDirMacro ); g_aOfficeBrandDirMacro );
} }
else else
{ {
nIndex = aCanonicalURL.indexOf( *m_pUserDir ); nIndex = aCanonicalURL.indexOf( *m_xUserDir );
if ( nIndex != -1 ) if ( nIndex != -1 )
{ {
return return
aCanonicalURL.replaceAt( nIndex, aCanonicalURL.replaceAt( nIndex,
m_pUserDir->getLength(), m_xUserDir->getLength(),
g_aUserDirMacro ); g_aUserDirMacro );
} }
} }
...@@ -162,7 +162,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL ) ...@@ -162,7 +162,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL )
return return
URL.replaceAt( nIndex, URL.replaceAt( nIndex,
g_aOfficeBrandDirMacro.getLength(), g_aOfficeBrandDirMacro.getLength(),
*m_pOfficeBrandDir ); *m_xOfficeBrandDir );
} }
else else
{ {
...@@ -174,7 +174,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL ) ...@@ -174,7 +174,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL )
return return
URL.replaceAt( nIndex, URL.replaceAt( nIndex,
g_aUserDirMacro.getLength(), g_aUserDirMacro.getLength(),
*m_pUserDir ); *m_xUserDir );
} }
} }
} }
...@@ -208,31 +208,28 @@ OfficeInstallationDirectories::getSupportedServiceNames() ...@@ -208,31 +208,28 @@ OfficeInstallationDirectories::getSupportedServiceNames()
void OfficeInstallationDirectories::initDirs() void OfficeInstallationDirectories::initDirs()
{ {
if ( m_pOfficeBrandDir == nullptr ) if ( !m_xOfficeBrandDir)
{ {
osl::MutexGuard aGuard( m_aMutex ); osl::MutexGuard aGuard( m_aMutex );
if ( m_pOfficeBrandDir == nullptr ) if ( !m_xOfficeBrandDir )
{ {
m_pOfficeBrandDir.reset( new OUString );
m_pUserDir.reset( new OUString );
uno::Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(m_xCtx); uno::Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(m_xCtx);
*m_pOfficeBrandDir = xExpander->expandMacros( "$BRAND_BASE_DIR" ); m_xOfficeBrandDir = xExpander->expandMacros( "$BRAND_BASE_DIR" );
OSL_ENSURE( !m_pOfficeBrandDir->isEmpty(), OSL_ENSURE( !m_xOfficeBrandDir->isEmpty(),
"Unable to obtain office brand installation directory!" ); "Unable to obtain office brand installation directory!" );
makeCanonicalFileURL( *m_pOfficeBrandDir ); makeCanonicalFileURL( *m_xOfficeBrandDir );
*m_pUserDir = m_xUserDir =
xExpander->expandMacros( xExpander->expandMacros(
"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" ) ":UserInstallation}" ); "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" ) ":UserInstallation}" );
OSL_ENSURE( !m_pUserDir->isEmpty(), OSL_ENSURE( !m_xUserDir->isEmpty(),
"Unable to obtain office user data directory!" ); "Unable to obtain office user data directory!" );
makeCanonicalFileURL( *m_pUserDir ); makeCanonicalFileURL( *m_xUserDir );
} }
} }
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XOfficeInstallationDirectories.hpp> #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
#include <memory> #include <memory>
#include <boost/optional.hpp>
namespace comphelper { namespace comphelper {
...@@ -70,8 +71,8 @@ private: ...@@ -70,8 +71,8 @@ private:
void initDirs(); void initDirs();
css::uno::Reference< css::uno::XComponentContext > m_xCtx; css::uno::Reference< css::uno::XComponentContext > m_xCtx;
std::unique_ptr<OUString> m_pOfficeBrandDir; boost::optional<OUString> m_xOfficeBrandDir;
std::unique_ptr<OUString> m_pUserDir; boost::optional<OUString> m_xUserDir;
}; };
} // namespace comphelper } // namespace comphelper
......
...@@ -132,7 +132,7 @@ bool ReplaceImpl(SwPaM & rCursor, OUString const& rReplacement, ...@@ -132,7 +132,7 @@ bool ReplaceImpl(SwPaM & rCursor, OUString const& rReplacement,
bool const bRegExp, SwDoc & rDoc, SwRootFrame const*const pLayout); bool const bRegExp, SwDoc & rDoc, SwRootFrame const*const pLayout);
/// Helperfunction to resolve backward references in regular expressions /// 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 ); SwPaM* pPam, SwRootFrame const* pLayout );
bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges, bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
......
...@@ -1313,11 +1313,11 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove, ...@@ -1313,11 +1313,11 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
const_cast<SwPaM &>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() ); const_cast<SwPaM &>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() );
} }
std::unique_ptr<OUString> pRepl(bRegExp boost::optional<OUString> xRepl;
? sw::ReplaceBackReferences(*pSearchOpt, &rCursor, m_pLayout) if (bRegExp)
: nullptr); xRepl = sw::ReplaceBackReferences(*pSearchOpt, &rCursor, m_pLayout);
sw::ReplaceImpl(rCursor, sw::ReplaceImpl(rCursor,
pRepl ? *pRepl : pSearchOpt->replaceString, bRegExp, xRepl ? *xRepl : pSearchOpt->replaceString, bRegExp,
*m_rCursor.GetDoc(), m_pLayout); *m_rCursor.GetDoc(), m_pLayout);
m_rCursor.SaveTableBoxContent( rCursor.GetPoint() ); m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
......
...@@ -941,11 +941,11 @@ int SwFindParaText::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove, ...@@ -941,11 +941,11 @@ int SwFindParaText::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
const_cast<SwPaM&>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() ); const_cast<SwPaM&>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() );
} }
std::unique_ptr<OUString> pRepl( bRegExp boost::optional<OUString> xRepl;
? sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout) if (bRegExp)
: nullptr ); xRepl = sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout);
bool const bReplaced = sw::ReplaceImpl(rCursor, bool const bReplaced = sw::ReplaceImpl(rCursor,
pRepl ? *pRepl : m_rSearchOpt.replaceString, xRepl ? *xRepl : m_rSearchOpt.replaceString,
bRegExp, *m_rCursor.GetDoc(), m_pLayout); bRegExp, *m_rCursor.GetDoc(), m_pLayout);
m_rCursor.SaveTableBoxContent( rCursor.GetPoint() ); m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
...@@ -1084,17 +1084,17 @@ bool ReplaceImpl( ...@@ -1084,17 +1084,17 @@ bool ReplaceImpl(
return bReplaced; return bReplaced;
} }
OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt, boost::optional<OUString> ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
SwPaM *const pPam, SwRootFrame const*const pLayout) SwPaM *const pPam, SwRootFrame const*const pLayout)
{ {
OUString *pRet = nullptr; boost::optional<OUString> xRet;
if( pPam && pPam->HasMark() && if( pPam && pPam->HasMark() &&
SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2 ) SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2 )
{ {
const SwContentNode* pTextNode = pPam->GetContentNode(); const SwContentNode* pTextNode = pPam->GetContentNode();
if (!pTextNode || !pTextNode->IsTextNode()) if (!pTextNode || !pTextNode->IsTextNode())
{ {
return pRet; return xRet;
} }
SwTextFrame const*const pFrame(pLayout SwTextFrame const*const pFrame(pLayout
? static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(pLayout)) ? static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(pLayout))
...@@ -1135,11 +1135,11 @@ OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt, ...@@ -1135,11 +1135,11 @@ OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
} }
OUString aReplaceStr( rSearchOpt.replaceString ); OUString aReplaceStr( rSearchOpt.replaceString );
aSText.ReplaceBackReferences( aReplaceStr, rStr, aResult ); aSText.ReplaceBackReferences( aReplaceStr, rStr, aResult );
pRet = new OUString( aReplaceStr ); xRet = aReplaceStr;
} }
} }
} }
return pRet; return xRet;
} }
} // namespace sw } // namespace sw
......
...@@ -309,15 +309,14 @@ void SwView::ExecSearch(SfxRequest& rReq) ...@@ -309,15 +309,14 @@ void SwView::ExecSearch(SfxRequest& rReq)
m_pWrtShell->Push(); m_pWrtShell->Push();
OUString aReplace( m_pSrchItem->GetReplaceString() ); OUString aReplace( m_pSrchItem->GetReplaceString() );
i18nutil::SearchOptions2 aTmp( m_pSrchItem->GetSearchOptions() ); i18nutil::SearchOptions2 aTmp( m_pSrchItem->GetSearchOptions() );
OUString *pBackRef = sw::ReplaceBackReferences(aTmp, boost::optional<OUString> xBackRef = sw::ReplaceBackReferences(aTmp,
m_pWrtShell->GetCursor(), m_pWrtShell->GetLayout()); m_pWrtShell->GetCursor(), m_pWrtShell->GetLayout());
if( pBackRef ) if( xBackRef )
m_pSrchItem->SetReplaceString( *pBackRef ); m_pSrchItem->SetReplaceString( *xBackRef );
Replace(); Replace();
if( pBackRef ) if( xBackRef )
{ {
m_pSrchItem->SetReplaceString( aReplace ); m_pSrchItem->SetReplaceString( aReplace );
delete pBackRef;
} }
if (bBack) if (bBack)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment