Kaydet (Commit) 6055922e authored tarafından Matteo Casalin's avatar Matteo Casalin

OUString: constify, avoid temporaries and buffers

Change-Id: I0bbfbb7785b4b8553d7472da15726538040af22e
üst 5490dea9
...@@ -138,8 +138,7 @@ public: ...@@ -138,8 +138,7 @@ public:
SwSectionFmt & GetSectionFmtOrThrow() const { SwSectionFmt & GetSectionFmtOrThrow() const {
SwSectionFmt *const pFmt( GetSectionFmt() ); SwSectionFmt *const pFmt( GetSectionFmt() );
if (!pFmt) { if (!pFmt) {
throw uno::RuntimeException(OUString( throw uno::RuntimeException("SwXTextSection: disposed or invalid", 0);
"SwXTextSection: disposed or invalid"), 0);
} }
return *pFmt; return *pFmt;
} }
...@@ -334,12 +333,11 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception) ...@@ -334,12 +333,11 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
SwSectionData aSect(eType, pDoc->GetUniqueSectionName(&m_pImpl->m_sName)); SwSectionData aSect(eType, pDoc->GetUniqueSectionName(&m_pImpl->m_sName));
aSect.SetCondition(m_pImpl->m_pProps->m_sCondition); aSect.SetCondition(m_pImpl->m_pProps->m_sCondition);
OUStringBuffer sLinkNameBuf(m_pImpl->m_pProps->m_sLinkFileName); aSect.SetLinkFileName(m_pImpl->m_pProps->m_sLinkFileName +
sLinkNameBuf.append(sfx2::cTokenSeparator); OUString(sfx2::cTokenSeparator) +
sLinkNameBuf.append(m_pImpl->m_pProps->m_sSectionFilter); m_pImpl->m_pProps->m_sSectionFilter +
sLinkNameBuf.append(sfx2::cTokenSeparator); OUString(sfx2::cTokenSeparator) +
sLinkNameBuf.append(m_pImpl->m_pProps->m_sSectionRegion); m_pImpl->m_pProps->m_sSectionRegion);
aSect.SetLinkFileName(sLinkNameBuf.makeStringAndClear());
aSect.SetHidden(m_pImpl->m_pProps->m_bHidden); aSect.SetHidden(m_pImpl->m_pProps->m_bHidden);
aSect.SetProtectFlag(m_pImpl->m_pProps->m_bProtect); aSect.SetProtectFlag(m_pImpl->m_pProps->m_bProtect);
...@@ -582,15 +580,13 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException, ...@@ -582,15 +580,13 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException,
if (!pEntry) if (!pEntry)
{ {
throw beans::UnknownPropertyException( throw beans::UnknownPropertyException(
OUString("Unknown property: ") "Unknown property: " + pPropertyNames[nProperty],
+ pPropertyNames[nProperty],
static_cast<cppu::OWeakObject *>(& m_rThis)); static_cast<cppu::OWeakObject *>(& m_rThis));
} }
if (pEntry->nFlags & beans::PropertyAttribute::READONLY) if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
{ {
throw beans::PropertyVetoException( throw beans::PropertyVetoException(
OUString("Property is read-only: ") "Property is read-only: " + pPropertyNames[nProperty],
+ pPropertyNames[nProperty],
static_cast<cppu::OWeakObject *>(& m_rThis)); static_cast<cppu::OWeakObject *>(& m_rThis));
} }
switch (pEntry->nWID) switch (pEntry->nWID)
...@@ -619,16 +615,13 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException, ...@@ -619,16 +615,13 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException,
{ {
if (!m_pProps->m_bDDE) if (!m_pProps->m_bDDE)
{ {
OUStringBuffer buf; m_pProps->m_sLinkFileName =
buf.append(sfx2::cTokenSeparator); OUString(sfx2::cTokenSeparator) + OUString(sfx2::cTokenSeparator);
buf.append(sfx2::cTokenSeparator);
m_pProps->m_sLinkFileName = buf.makeStringAndClear();
m_pProps->m_bDDE = true; m_pProps->m_bDDE = true;
} }
OUString sLinkFileName(m_pProps->m_sLinkFileName); m_pProps->m_sLinkFileName = comphelper::string::setToken(
sLinkFileName = comphelper::string::setToken(sLinkFileName, m_pProps->m_sLinkFileName,
pEntry->nWID - WID_SECT_DDE_TYPE, sfx2::cTokenSeparator, sTmp); pEntry->nWID - WID_SECT_DDE_TYPE, sfx2::cTokenSeparator, sTmp);
m_pProps->m_sLinkFileName = sLinkFileName;
} }
else else
{ {
...@@ -683,22 +676,15 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException, ...@@ -683,22 +676,15 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException,
{ {
pSectionData->SetType(FILE_LINK_SECTION); pSectionData->SetType(FILE_LINK_SECTION);
} }
OUStringBuffer sFileNameBuf; const OUString sTmp(!aLink.FileURL.isEmpty()
if (!aLink.FileURL.isEmpty()) ? URIHelper::SmartRel2Abs(
{ pFmt->GetDoc()->GetDocShell()->GetMedium()->GetURLObject(),
sFileNameBuf.append( URIHelper::SmartRel2Abs( aLink.FileURL, URIHelper::GetMaybeFileHdl())
pFmt->GetDoc()->GetDocShell()->GetMedium() : OUString());
->GetURLObject(),
aLink.FileURL, URIHelper::GetMaybeFileHdl()));
}
sFileNameBuf.append(sfx2::cTokenSeparator);
sFileNameBuf.append(aLink.FilterName);
sFileNameBuf.append(sfx2::cTokenSeparator);
sFileNameBuf.append(
pSectionData->GetLinkFileName().getToken(2,
sfx2::cTokenSeparator));
const OUString sFileName( const OUString sFileName(
sFileNameBuf.makeStringAndClear()); sTmp + OUString(sfx2::cTokenSeparator) +
aLink.FilterName + OUString(sfx2::cTokenSeparator) +
pSectionData->GetLinkFileName().getToken(2, sfx2::cTokenSeparator));
pSectionData->SetLinkFileName(sFileName); pSectionData->SetLinkFileName(sFileName);
if (sFileName.getLength() < 3) if (sFileName.getLength() < 3)
{ {
...@@ -984,17 +970,16 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException, ...@@ -984,17 +970,16 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException,
if (!pEntry) if (!pEntry)
{ {
throw beans::UnknownPropertyException( throw beans::UnknownPropertyException(
OUString("Unknown property: ") "Unknown property: " + pPropertyNames[nProperty],
+ pPropertyNames[nProperty],
static_cast<cppu::OWeakObject *>(& m_rThis)); static_cast<cppu::OWeakObject *>(& m_rThis));
} }
switch(pEntry->nWID) switch(pEntry->nWID)
{ {
case WID_SECT_CONDITION: case WID_SECT_CONDITION:
{ {
OUString uTmp( (m_bIsDescriptor) const OUString uTmp( (m_bIsDescriptor)
? m_pProps->m_sCondition ? m_pProps->m_sCondition
: OUString(pSect->GetCondition())); : pSect->GetCondition());
pRet[nProperty] <<= uTmp; pRet[nProperty] <<= uTmp;
} }
break; break;
...@@ -1014,10 +999,8 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException, ...@@ -1014,10 +999,8 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException,
{ {
sRet = pSect->GetLinkFileName(); sRet = pSect->GetLinkFileName();
} }
sal_Int32 nDummy(0); pRet[nProperty] <<= sRet.getToken(pEntry->nWID - WID_SECT_DDE_TYPE,
sRet = sRet.getToken(pEntry->nWID - WID_SECT_DDE_TYPE, sfx2::cTokenSeparator);
sfx2::cTokenSeparator, nDummy);
pRet[nProperty] <<= sRet;
} }
break; break;
case WID_SECT_DDE_AUTOUPDATE: case WID_SECT_DDE_AUTOUPDATE:
...@@ -1044,7 +1027,7 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException, ...@@ -1044,7 +1027,7 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException,
} }
else if (FILE_LINK_SECTION == pSect->GetType()) else if (FILE_LINK_SECTION == pSect->GetType())
{ {
OUString sRet( pSect->GetLinkFileName() ); const OUString sRet( pSect->GetLinkFileName() );
sal_Int32 nIndex(0); sal_Int32 nIndex(0);
aLink.FileURL = aLink.FileURL =
sRet.getToken(0, sfx2::cTokenSeparator, nIndex); sRet.getToken(0, sfx2::cTokenSeparator, nIndex);
...@@ -1101,8 +1084,7 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException, ...@@ -1101,8 +1084,7 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException,
{ {
if (pFmt) if (pFmt)
{ {
pRet[nProperty] <<= pRet[nProperty] <<= pFmt->GetSection()->GetSectionName();
OUString(pFmt->GetSection()->GetSectionName());
} }
} }
break; break;
...@@ -1408,8 +1390,8 @@ throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception) ...@@ -1408,8 +1390,8 @@ throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
if (!pEntry) if (!pEntry)
{ {
throw beans::UnknownPropertyException( throw beans::UnknownPropertyException(
OUString("Unknown property: ") "Unknown property: " + pNames[i],
+ pNames[i], static_cast< cppu::OWeakObject* >(this)); static_cast< cppu::OWeakObject* >(this));
} }
switch (pEntry->nWID) switch (pEntry->nWID)
{ {
...@@ -1484,14 +1466,13 @@ throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception) ...@@ -1484,14 +1466,13 @@ throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
if (!pEntry) if (!pEntry)
{ {
throw beans::UnknownPropertyException( throw beans::UnknownPropertyException(
OUString("Unknown property: ") "Unknown property: " + rPropertyName,
+ rPropertyName, static_cast< cppu::OWeakObject* >(this)); static_cast< cppu::OWeakObject* >(this));
} }
if (pEntry->nFlags & beans::PropertyAttribute::READONLY) if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
{ {
throw uno::RuntimeException(OUString( throw uno::RuntimeException(
"setPropertyToDefault: property is read-only: ") "Property is read-only: " + rPropertyName,
+ rPropertyName,
static_cast<cppu::OWeakObject *>(this)); static_cast<cppu::OWeakObject *>(this));
} }
...@@ -1627,8 +1608,7 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException, ...@@ -1627,8 +1608,7 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException,
if (!pEntry) if (!pEntry)
{ {
throw beans::UnknownPropertyException( throw beans::UnknownPropertyException(
OUString("Unknown property: ") "Unknown property: " + rPropertyName,
+ rPropertyName,
static_cast<cppu::OWeakObject *>(this)); static_cast<cppu::OWeakObject *>(this));
} }
...@@ -1707,8 +1687,7 @@ throw (uno::RuntimeException, std::exception) ...@@ -1707,8 +1687,7 @@ throw (uno::RuntimeException, std::exception)
{ {
SwSection *const pSect = pFmt->GetSection(); SwSection *const pSect = pFmt->GetSection();
SwSectionData aSection(*pSect); SwSectionData aSection(*pSect);
OUString sNewName(rName); aSection.SetSectionName(rName);
aSection.SetSectionName(sNewName);
const SwSectionFmts& rFmts = pFmt->GetDoc()->GetSections(); const SwSectionFmts& rFmts = pFmt->GetDoc()->GetSections();
sal_uInt16 nApplyPos = USHRT_MAX; sal_uInt16 nApplyPos = USHRT_MAX;
...@@ -1718,7 +1697,7 @@ throw (uno::RuntimeException, std::exception) ...@@ -1718,7 +1697,7 @@ throw (uno::RuntimeException, std::exception)
{ {
nApplyPos = i; nApplyPos = i;
} }
else if (sNewName == rFmts[i]->GetSection()->GetSectionName()) else if (rName == rFmts[i]->GetSection()->GetSectionName())
{ {
throw uno::RuntimeException(); throw uno::RuntimeException();
} }
......
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