From 44841a6778821be3e68ab15819b39064b20e968f Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 16 Feb 2019 18:39:23 +0300 Subject: Simplify containers iterations in [f-l]* Use range-based loop or replace with STL functions Change-Id: Ib3fab47318d1bfbb4df8f886a8cd9596525a420f Reviewed-on: https://gerrit.libreoffice.org/67914 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- lotuswordpro/source/filter/lwpstory.cxx | 41 ++++++++------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) (limited to 'lotuswordpro') diff --git a/lotuswordpro/source/filter/lwpstory.cxx b/lotuswordpro/source/filter/lwpstory.cxx index b0f9586270e2..32d6342e47dc 100644 --- a/lotuswordpro/source/filter/lwpstory.cxx +++ b/lotuswordpro/source/filter/lwpstory.cxx @@ -68,6 +68,7 @@ #include "lwppagelayout.hxx" #include +#include #include @@ -183,17 +184,9 @@ void LwpStory::SetCurrentLayout(LwpPageLayout *pPageLayout) **************************************************************************/ LwpPageLayout* LwpStory::GetNextPageLayout() { - std::vector::iterator it; - for( it = m_LayoutList.begin(); it != m_LayoutList.end(); ++it ) - { - if(m_pCurrentLayout == *it) - { - if((it+1) !=m_LayoutList.end()) - { - return *(it+1); - } - } - } + std::vector::iterator it = std::find(m_LayoutList.begin(), m_LayoutList.end(), m_pCurrentLayout); + if (it != m_LayoutList.end() && (it+1) != m_LayoutList.end()) + return *(it+1); return nullptr; } /************************************************************************** @@ -222,22 +215,15 @@ void LwpStory::SortPageLayout() xLayout = GetLayout(xLayout.get()); } // sort the pagelayout according to their position - std::vector::iterator aIt; if (!aLayoutList.empty()) { - for( aIt = aLayoutList.begin(); aIt != aLayoutList.end() -1; ++aIt) + for( std::vector::iterator aIt = aLayoutList.begin(); aIt != aLayoutList.end() -1; ++aIt) { for( std::vector::iterator bIt = aIt +1; bIt != aLayoutList.end(); ++bIt ) { - if(**aIt < **bIt) + if(!(**aIt < **bIt)) { - continue; - } - else - { - LwpPageLayout* pTemp = *aIt; - *aIt = *bIt; - *bIt = pTemp; + std::swap(*aIt, *bIt); } } } @@ -477,17 +463,8 @@ OUString LwpStory::RegisterFirstFribStyle() bool LwpStory::IsBullStyleUsedBefore(const OUString& rStyleName, sal_uInt8 nPos) { - std::vector ::reverse_iterator rIter; - for (rIter = m_vBulletStyleNameList.rbegin(); rIter != m_vBulletStyleNameList.rend(); ++rIter) - { - OUString aName = (*rIter).first; - sal_uInt8 nPosition = (*rIter).second; - if (aName == rStyleName && nPosition == nPos) - { - return true; - } - } - return false; + return std::any_of(m_vBulletStyleNameList.rbegin(), m_vBulletStyleNameList.rend(), + [&rStyleName, &nPos](const NamePosPair& rPair) { return rPair.first == rStyleName && rPair.second == nPos; }); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit