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
OfficeInstallationDirectories::getOfficeInstallationDirectoryURL()
{
initDirs();
return *m_pOfficeBrandDir;
return *m_xOfficeBrandDir;
}
......@@ -108,7 +108,7 @@ OUString SAL_CALL
OfficeInstallationDirectories::getOfficeUserDataDirectoryURL()
{
initDirs();
return *m_pUserDir;
return *m_xUserDir;
}
......@@ -124,22 +124,22 @@ OfficeInstallationDirectories::makeRelocatableURL( const OUString& URL )
OUString aCanonicalURL( URL );
makeCanonicalFileURL( aCanonicalURL );
sal_Int32 nIndex = aCanonicalURL.indexOf( *m_pOfficeBrandDir );
sal_Int32 nIndex = aCanonicalURL.indexOf( *m_xOfficeBrandDir );
if ( nIndex != -1 )
{
return
aCanonicalURL.replaceAt( nIndex,
m_pOfficeBrandDir->getLength(),
m_xOfficeBrandDir->getLength(),
g_aOfficeBrandDirMacro );
}
else
{
nIndex = aCanonicalURL.indexOf( *m_pUserDir );
nIndex = aCanonicalURL.indexOf( *m_xUserDir );
if ( nIndex != -1 )
{
return
aCanonicalURL.replaceAt( nIndex,
m_pUserDir->getLength(),
m_xUserDir->getLength(),
g_aUserDirMacro );
}
}
......@@ -162,7 +162,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL )
return
URL.replaceAt( nIndex,
g_aOfficeBrandDirMacro.getLength(),
*m_pOfficeBrandDir );
*m_xOfficeBrandDir );
}
else
{
......@@ -174,7 +174,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL )
return
URL.replaceAt( nIndex,
g_aUserDirMacro.getLength(),
*m_pUserDir );
*m_xUserDir );
}
}
}
......@@ -208,31 +208,28 @@ OfficeInstallationDirectories::getSupportedServiceNames()
void OfficeInstallationDirectories::initDirs()
{
if ( m_pOfficeBrandDir == nullptr )
if ( !m_xOfficeBrandDir)
{
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);
*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!" );
makeCanonicalFileURL( *m_pOfficeBrandDir );
makeCanonicalFileURL( *m_xOfficeBrandDir );
*m_pUserDir =
m_xUserDir =
xExpander->expandMacros(
"${$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!" );
makeCanonicalFileURL( *m_pUserDir );
makeCanonicalFileURL( *m_xUserDir );
}
}
}
......
......@@ -27,6 +27,7 @@
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
#include <memory>
#include <boost/optional.hpp>
namespace comphelper {
......@@ -70,8 +71,8 @@ private:
void initDirs();
css::uno::Reference< css::uno::XComponentContext > m_xCtx;
std::unique_ptr<OUString> m_pOfficeBrandDir;
std::unique_ptr<OUString> m_pUserDir;
boost::optional<OUString> m_xOfficeBrandDir;
boost::optional<OUString> m_xUserDir;
};
} // namespace comphelper
......
......@@ -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,
......
......@@ -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() );
......
......@@ -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
......
......@@ -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)
{
......
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