summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2018-08-15 21:32:27 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-20 17:12:11 +0200
commit0787ce8814e37972a0c968f60008d4e8722b6e27 (patch)
tree9d2803ebda8813e6b3f2bc2e6f8a74953b2931c1 /sw
parentd2c9c60fefb9687adbde4be61ed66a5123a2587f (diff)
Simplify containers iterations, tdf#96099 follow-up
Use range-based loop or replace with std::any_of, std::find and std::find_if where applicable. Change-Id: I2f80788c49d56094c29b102eb96a7a7c079567c6 Reviewed-on: https://gerrit.libreoffice.org/59143 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/filter/ww8/writerhelper.cxx7
-rw-r--r--sw/source/filter/ww8/wrtw8esh.cxx21
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx7
-rw-r--r--sw/source/filter/ww8/wrtw8sty.cxx5
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx21
-rw-r--r--sw/source/filter/ww8/ww8graf2.cxx12
-rw-r--r--sw/source/filter/ww8/ww8par5.cxx9
-rw-r--r--sw/source/ui/index/cnttab.cxx23
-rw-r--r--sw/source/ui/misc/glosbib.cxx57
9 files changed, 57 insertions, 105 deletions
diff --git a/sw/source/filter/ww8/writerhelper.cxx b/sw/source/filter/ww8/writerhelper.cxx
index 03821f0b1696..2ea8b649d46c 100644
--- a/sw/source/filter/ww8/writerhelper.cxx
+++ b/sw/source/filter/ww8/writerhelper.cxx
@@ -866,11 +866,10 @@ namespace sw
{
if (!mbHasRoot)
return;
- auto aEnd = maTables.end();
- for (auto aIter = maTables.begin(); aIter != aEnd; ++aIter)
+ for (auto& aTable : maTables)
{
// If already a layout exists, then the BoxFrames must recreated at this table
- SwTableNode *pTable = aIter->first->GetTableNode();
+ SwTableNode *pTable = aTable.first->GetTableNode();
OSL_ENSURE(pTable, "Why no expected table");
if (pTable)
{
@@ -878,7 +877,7 @@ namespace sw
if (pFrameFormat != nullptr)
{
- SwNodeIndex *pIndex = aIter->second;
+ SwNodeIndex *pIndex = aTable.second;
pTable->DelFrames();
pTable->MakeFrames(pIndex);
}
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx
index d212c27bb204..aca4539fd21e 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -637,19 +637,16 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
WW8Fib& rFib = *rWrt.pFib;
WW8_CP nCpOffs = GetCpOffset(rFib);
- auto aEnd = maDrawObjs.cend();
- auto aIter = maDrawObjs.cbegin();
-
- for ( ; aIter < aEnd; ++aIter)
- SwWW8Writer::WriteLong(*rWrt.pTableStrm, aIter->mnCp - nCpOffs);
+ for (const auto& rDrawObj : maDrawObjs)
+ SwWW8Writer::WriteLong(*rWrt.pTableStrm, rDrawObj.mnCp - nCpOffs);
SwWW8Writer::WriteLong(*rWrt.pTableStrm, rFib.m_ccpText + rFib.m_ccpFootnote +
rFib.m_ccpHdr + rFib.m_ccpEdn + rFib.m_ccpTxbx + rFib.m_ccpHdrTxbx + 1);
- for (aIter = maDrawObjs.cbegin(); aIter < aEnd; ++aIter)
+ for (const auto& rDrawObj : maDrawObjs)
{
// write the fspa-struct
- const ww8::Frame &rFrameFormat = aIter->maContent;
+ const ww8::Frame &rFrameFormat = rDrawObj.maContent;
const SwFrameFormat &rFormat = rFrameFormat.GetFrameFormat();
const SdrObject* pObj = rFormat.FindRealSdrObject();
@@ -710,7 +707,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
}
else
{
- aRect -= aIter->maParentPos;
+ aRect -= rDrawObj.maParentPos;
aObjPos = aRect.TopLeft();
if (text::VertOrientation::NONE == rVOr.GetVertOrient())
{
@@ -726,7 +723,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
aRect.SetPos( aObjPos );
}
- sal_Int32 nThick = aIter->mnThick;
+ sal_Int32 nThick = rDrawObj.mnThick;
//If we are being exported as an inline hack, set
//corner to 0 and forget about border thickness for positioning
@@ -737,7 +734,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
}
// spid
- SwWW8Writer::WriteLong(*rWrt.pTableStrm, aIter->mnShapeId);
+ SwWW8Writer::WriteLong(*rWrt.pTableStrm, rDrawObj.mnShapeId);
SwTwips nLeft = aRect.Left() + nThick;
SwTwips nRight = aRect.Right() - nThick;
@@ -2255,11 +2252,9 @@ SwEscherEx::SwEscherEx(SvStream* pStrm, WW8Export& rWW8Wrt)
MakeZOrderArrAndFollowIds(pSdrObjs->GetObjArr(), aSorted);
sal_uInt32 nShapeId=0;
- auto aEnd = aSorted.end();
- for (auto aIter = aSorted.begin(); aIter != aEnd; ++aIter)
+ for (auto& pObj : aSorted)
{
sal_Int32 nBorderThick=0;
- DrawObj *pObj = (*aIter);
OSL_ENSURE(pObj, "impossible");
if (!pObj)
continue;
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 1be3d5557355..51fe41d0458c 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -496,11 +496,10 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bRuby , bool bWriteCombChars
if( rNd.GetpSwpHints() == nullptr )
m_rExport.SetCurItemSet(&aExportSet);
- auto aEnd = aRangeItems.cend();
- for ( auto aI = aRangeItems.cbegin(); aI != aEnd; ++aI )
+ for ( const auto& aRangeItem : aRangeItems )
{
- if ( !bRuby || !lcl_isFontsizeItem( *aI->second ) )
- aExportItems[aI->first] = aI->second;
+ if ( !bRuby || !lcl_isFontsizeItem( *(aRangeItem.second) ) )
+ aExportItems[aRangeItem.first] = aRangeItem.second;
}
if ( !aExportItems.empty() )
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index dc57e91f6c5f..5b6fda114083 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -892,9 +892,8 @@ std::vector< const wwFont* > wwFontHelper::AsVector() const
{
std::vector<const wwFont *> aFontList( maFonts.size() );
- auto aEnd = maFonts.cend();
- for ( auto aIter = maFonts.cbegin(); aIter != aEnd; ++aIter )
- aFontList[aIter->second] = &aIter->first;
+ for ( const auto& aFont : maFonts )
+ aFontList[aFont.second] = &aFont.first;
return aFontList;
}
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 9dbb588c24d4..c5cab3f6edf6 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -209,10 +209,9 @@ bool WW8Export::CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich
void MSWordExportBase::ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16 nScript, const SvxFontItem *pFont, bool bWriteCombChars )
{
- auto aEnd = rItems.cend();
- for ( auto aI = rItems.cbegin(); aI != aEnd; ++aI )
+ for ( const auto& rItem : rItems )
{
- const SfxPoolItem *pItem = aI->second;
+ const SfxPoolItem *pItem = rItem.second;
sal_uInt16 nWhich = pItem->Which();
if ( ( isCHRATR( nWhich ) || isTXTATR( nWhich ) ) && CollapseScriptsforWordOk( nScript, nWhich ) )
{
@@ -297,10 +296,9 @@ void MSWordExportBase::OutputItemSet( const SfxItemSet& rSet, bool bPapFormat, b
ExportPoolItemsToCHP(aItems, nScript, nullptr);
if ( bPapFormat )
{
- auto aEnd = aItems.cend();
- for ( auto aI = aItems.cbegin(); aI != aEnd; ++aI )
+ for ( const auto& rItem : aItems )
{
- pItem = aI->second;
+ pItem = rItem.second;
sal_uInt16 nWhich = pItem->Which();
// Handle fill attributes just like frame attributes for now.
if ( (nWhich >= RES_PARATR_BEGIN && nWhich < RES_FRMATR_END && nWhich != RES_PARATR_NUMRULE ) ||
@@ -345,15 +343,8 @@ bool MSWordExportBase::ContentContainsChapterField(const SwFormatContent &rConte
sal_uLong nStart = aIdx.GetIndex();
sal_uLong nEnd = aEnd.GetIndex();
//If the header/footer contains a chapter field
- auto aIEnd = m_aChapterFieldLocs.cend();
- for ( auto aI = m_aChapterFieldLocs.cbegin(); aI != aIEnd; ++aI )
- {
- if ( ( nStart <= *aI ) && ( *aI <= nEnd ) )
- {
- bRet = true;
- break;
- }
- }
+ bRet = std::any_of(m_aChapterFieldLocs.cbegin(), m_aChapterFieldLocs.cend(),
+ [nStart, nEnd](sal_uLong i) { return ( nStart <= i ) && ( i <= nEnd ); });
}
return bRet;
}
diff --git a/sw/source/filter/ww8/ww8graf2.cxx b/sw/source/filter/ww8/ww8graf2.cxx
index 2680a957a71a..ab1183600fc1 100644
--- a/sw/source/filter/ww8/ww8graf2.cxx
+++ b/sw/source/filter/ww8/ww8graf2.cxx
@@ -216,15 +216,9 @@ void wwZOrderer::InsertTextLayerObject(SdrObject* pObject)
*/
sal_uLong wwZOrderer::GetDrawingObjectPos(short nWwHeight)
{
- auto aIter = maDrawHeight.begin();
- auto aEnd = maDrawHeight.end();
-
- while (aIter != aEnd)
- {
- if ((*aIter & 0x1fff) > (nWwHeight & 0x1fff))
- break;
- ++aIter;
- }
+ auto aIter = std::find_if(
+ maDrawHeight.begin(), maDrawHeight.end(),
+ [nWwHeight](short aHeight){ return (aHeight & 0x1fff) > (nWwHeight & 0x1fff); });
aIter = maDrawHeight.insert(aIter, nWwHeight);
return std::distance(maDrawHeight.begin(), aIter);
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index f0ab52c3b900..9ca995ad4486 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -870,13 +870,8 @@ long SwWW8ImplReader::Read_Field(WW8PLCFManResult* pRes)
bool bNested = false;
if (!m_aFieldStack.empty())
{
- auto aEnd = m_aFieldStack.cend();
- for(auto aIter = m_aFieldStack.cbegin(); aIter != aEnd; ++aIter)
- {
- bNested = !AcceptableNestedField(aIter->mnFieldId);
- if (bNested)
- break;
- }
+ bNested = std::any_of(m_aFieldStack.cbegin(), m_aFieldStack.cend(),
+ [](const WW8FieldEntry& aField) { return !AcceptableNestedField(aField.mnFieldId); });
}
WW8FieldDesc aF;
diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index b3030f87d711..d5187dae1b0c 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -2811,11 +2811,11 @@ void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
if(m_pForm)
{
- for (auto iter = m_aControlList.begin(); iter != m_aControlList.end(); ++iter)
- iter->disposeAndClear();
+ for (auto& aControl : m_aControlList)
+ aControl.disposeAndClear();
//apply current level settings to the form
- for (auto it = m_aControlList.begin(); it != m_aControlList.end(); ++it)
- it->disposeAndClear();
+ for (auto& aControl : m_aControlList)
+ aControl.disposeAndClear();
m_aControlList.clear();
}
@@ -3395,10 +3395,8 @@ OUString SwTokenWindow::GetPattern() const
{
OUStringBuffer sRet;
- for (auto it = m_aControlList.cbegin(); it != m_aControlList.cend(); ++it)
+ for (const Control* pCtrl : m_aControlList)
{
- const Control *pCtrl = *it;
-
const SwFormToken &rNewToken = pCtrl->GetType() == WindowType::EDIT
? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pCtrl))->GetFormToken()
: static_cast<const SwTOXButton*>(pCtrl)->GetFormToken();
@@ -3415,10 +3413,8 @@ bool SwTokenWindow::Contains(FormTokenType eSearchFor) const
{
bool bRet = false;
- for (auto it = m_aControlList.cbegin(); it != m_aControlList.cend(); ++it)
+ for (const Control* pCtrl : m_aControlList)
{
- const Control *pCtrl = *it;
-
const SwFormToken &rNewToken = pCtrl->GetType() == WindowType::EDIT
? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pCtrl))->GetFormToken()
: static_cast<const SwTOXButton*>(pCtrl)->GetFormToken();
@@ -3555,9 +3551,9 @@ IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton&, rBtn, void )
IMPL_LINK(SwTokenWindow, TbxFocusBtnHdl, Control&, rControl, void )
{
SwTOXButton* pBtn = static_cast<SwTOXButton*>(&rControl);
- for (auto it = m_aControlList.begin(); it != m_aControlList.end(); ++it)
+ for (auto& aControl : m_aControlList)
{
- Control *pControl = it->get();
+ Control *pControl = aControl.get();
if (pControl && WindowType::EDIT != pControl->GetType())
static_cast<SwTOXButton*>(pControl)->Check(pBtn == pControl);
@@ -3602,9 +3598,8 @@ sal_uInt32 SwTokenWindow::GetControlIndex(FormTokenType eType) const
}
sal_uInt32 nIndex = 0;
- for (auto it = m_aControlList.cbegin(); it != m_aControlList.cend(); ++it)
+ for (const Control* pControl : m_aControlList)
{
- const Control* pControl = *it;
const SwFormToken& rNewToken = WindowType::EDIT == pControl->GetType()
? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pControl))->GetFormToken()
: static_cast<const SwTOXButton*>(pControl)->GetFormToken();
diff --git a/sw/source/ui/misc/glosbib.cxx b/sw/source/ui/misc/glosbib.cxx
index f5afb1da7a2c..38e26e86d5b8 100644
--- a/sw/source/ui/misc/glosbib.cxx
+++ b/sw/source/ui/misc/glosbib.cxx
@@ -138,9 +138,9 @@ void SwGlossaryGroupDlg::Apply()
OUString aActGroup = SwGlossaryDlg::GetCurrGroup();
- for (auto it(m_RemovedArr.cbegin()); it != m_RemovedArr.cend(); ++it)
+ for (const auto& removedStr : m_RemovedArr)
{
- const OUString sDelGroup = it->getToken(0, '\t');
+ const OUString sDelGroup = removedStr.getToken(0, '\t');
if( sDelGroup == aActGroup )
{
//when the current group is deleted, the current group has to be relocated
@@ -151,7 +151,7 @@ void SwGlossaryGroupDlg::Apply()
pGlosHdl->SetCurGroup(pUserData->sGroupName);
}
}
- OUString sTitle( it->getToken(1, '\t') );
+ OUString sTitle( removedStr.getToken(1, '\t') );
const OUString sMsg(SwResId(STR_QUERY_DELETE_GROUP1)
+ sTitle
+ SwResId(STR_QUERY_DELETE_GROUP2));
@@ -176,9 +176,8 @@ void SwGlossaryGroupDlg::Apply()
sCreatedGroup = sNew;
}
}
- for (auto it(m_InsertedArr.cbegin()); it != m_InsertedArr.cend(); ++it)
+ for (auto& sNewGroup : m_InsertedArr)
{
- OUString sNewGroup = *it;
OUString sNewTitle = sNewGroup.getToken(0, GLOS_DELIM);
if( sNewGroup != aActGroup )
{
@@ -243,27 +242,21 @@ IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, Button*, pButton, void )
OUString const sEntry(pUserData->sGroupName);
// if the name to be deleted is among the new ones - get rid of it
bool bDelete = true;
- for (auto it(m_InsertedArr.begin()); it != m_InsertedArr.end(); ++it)
+ auto it = std::find(m_InsertedArr.begin(), m_InsertedArr.end(), sEntry);
+ if (it != m_InsertedArr.end())
{
- if (*it == sEntry)
- {
- m_InsertedArr.erase(it);
- bDelete = false;
- break;
- }
-
+ m_InsertedArr.erase(it);
+ bDelete = false;
}
// it should probably be renamed?
if(bDelete)
{
- for (auto it(m_RenamedArr.begin()); it != m_RenamedArr.end(); ++it)
+ it = std::find_if(m_RenamedArr.begin(), m_RenamedArr.end(),
+ [&sEntry](OUString& s) { return s.getToken(0, RENAME_TOKEN_DELIM) == sEntry; });
+ if (it != m_RenamedArr.end())
{
- if (it->getToken(0, RENAME_TOKEN_DELIM) == sEntry)
- {
- m_RenamedArr.erase(it);
- bDelete = false;
- break;
- }
+ m_RenamedArr.erase(it);
+ bDelete = false;
}
}
if(bDelete)
@@ -292,15 +285,12 @@ IMPL_LINK_NOARG(SwGlossaryGroupDlg, RenameHdl, Button*, void)
// if the name to be renamed is among the new ones - replace
bool bDone = false;
- for (auto it(m_InsertedArr.begin()); it != m_InsertedArr.end(); ++it)
+ auto it = std::find(m_InsertedArr.begin(), m_InsertedArr.end(), sEntry);
+ if (it != m_InsertedArr.end())
{
- if (*it == sEntry)
- {
- m_InsertedArr.erase(it);
- m_InsertedArr.push_back(sNewName);
- bDone = true;
- break;
- }
+ m_InsertedArr.erase(it);
+ m_InsertedArr.push_back(sNewName);
+ bDone = true;
}
if(!bDone)
{
@@ -385,14 +375,9 @@ bool SwGlossaryGroupDlg::IsDeleteAllowed(const OUString &rGroup)
// as well! Because for non existing region names ReadOnly issues
// true.
- for (auto it(m_InsertedArr.cbegin()); it != m_InsertedArr.cend(); ++it)
- {
- if (*it == rGroup)
- {
- bDel = true;
- break;
- }
- }
+ auto it = std::find(m_InsertedArr.cbegin(), m_InsertedArr.cend(), rGroup);
+ if (it != m_InsertedArr.cend())
+ bDel = true;
return bDel;
}