diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-08-15 21:32:27 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-20 17:12:11 +0200 |
commit | 0787ce8814e37972a0c968f60008d4e8722b6e27 (patch) | |
tree | 9d2803ebda8813e6b3f2bc2e6f8a74953b2931c1 /sw/source/ui | |
parent | d2c9c60fefb9687adbde4be61ed66a5123a2587f (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/source/ui')
-rw-r--r-- | sw/source/ui/index/cnttab.cxx | 23 | ||||
-rw-r--r-- | sw/source/ui/misc/glosbib.cxx | 57 |
2 files changed, 30 insertions, 50 deletions
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; } |