From c775efffa7ddcee607bd7622a19a627545a6bc67 Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Tue, 13 Mar 2018 22:29:24 +0100 Subject: Modernize a bit filter (part1) mainly by using for-range loops + some algo simplifications Change-Id: Ibbf2c4bb504b93cb9d7b2314deb6e65257c56029 Reviewed-on: https://gerrit.libreoffice.org/51243 Tested-by: Jenkins Reviewed-by: Julien Nabet --- filter/source/config/cache/cacheitem.cxx | 48 ++++------ filter/source/config/cache/cacheupdatelistener.cxx | 8 +- filter/source/config/cache/filtercache.cxx | 106 ++++++++------------- filter/source/config/cache/filterfactory.cxx | 38 +++----- filter/source/config/cache/typedetection.cxx | 62 +++++------- filter/source/flash/swfexporter.cxx | 6 +- filter/source/flash/swfwriter.cxx | 30 +++--- filter/source/flash/swfwriter1.cxx | 9 +- filter/source/flash/swfwriter2.cxx | 24 +++-- filter/source/graphicfilter/eps/eps.cxx | 35 ++++--- filter/source/msfilter/escherex.cxx | 42 ++++---- 11 files changed, 156 insertions(+), 252 deletions(-) (limited to 'filter') diff --git a/filter/source/config/cache/cacheitem.cxx b/filter/source/config/cache/cacheitem.cxx index f67fb4114b8a..4caca1823b58 100644 --- a/filter/source/config/cache/cacheitem.cxx +++ b/filter/source/config/cache/cacheitem.cxx @@ -40,15 +40,13 @@ CacheItem::CacheItem() void CacheItem::update(const CacheItem& rUpdateItem) { - for(const_iterator pItUpdate = rUpdateItem.begin(); - pItUpdate != rUpdateItem.end() ; - ++pItUpdate ) + for (auto const& elem : rUpdateItem) { - iterator pItThis = find(pItUpdate->first); + iterator pItThis = find(elem.first); if (pItThis == end()) - (*this)[pItUpdate->first] = pItUpdate->second; // add new prop + (*this)[elem.first] = elem.second; // add new prop else - pItThis->second = pItUpdate->second; // change value of existing prop + pItThis->second = elem.second; // change value of existing prop } } @@ -204,11 +202,9 @@ bool isSubSet(const css::uno::Any& aSubSet, OUStringList stl_s1(comphelper::sequenceToContainer(uno_s1)); OUStringList stl_s2(comphelper::sequenceToContainer(uno_s2)); - for (OUStringList::const_iterator it1 = stl_s1.begin(); - it1 != stl_s1.end() ; - ++it1 ) + for (auto const& elem : stl_s1) { - if (::std::find(stl_s2.begin(), stl_s2.end(), *it1) == stl_s2.end()) + if (::std::find(stl_s2.begin(), stl_s2.end(), elem) == stl_s2.end()) { return false; } @@ -227,16 +223,14 @@ bool isSubSet(const css::uno::Any& aSubSet, ::comphelper::SequenceAsHashMap stl_p1(uno_p1); ::comphelper::SequenceAsHashMap stl_p2(uno_p2); - for (::comphelper::SequenceAsHashMap::const_iterator it1 = stl_p1.begin(); - it1 != stl_p1.end() ; - ++it1 ) + for (auto const& elem : stl_p1) { - ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_p2.find(it1->first); + ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_p2.find(elem.first); if (it2 == stl_p2.end()) { return false; } - if (!isSubSet(it1->second, it2->second)) + if (!isSubSet(elem.second, it2->second)) { return false; } @@ -255,16 +249,14 @@ bool isSubSet(const css::uno::Any& aSubSet, ::comphelper::SequenceAsHashMap stl_n1(uno_n1); ::comphelper::SequenceAsHashMap stl_n2(uno_n2); - for (::comphelper::SequenceAsHashMap::const_iterator it1 = stl_n1.begin(); - it1 != stl_n1.end() ; - ++it1 ) + for (auto const& elem : stl_n1) { - ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_n2.find(it1->first); + ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_n2.find(elem.first); if (it2 == stl_n2.end()) { return false; } - if (!isSubSet(it1->second, it2->second)) + if (!isSubSet(elem.second, it2->second)) { return false; } @@ -283,19 +275,17 @@ bool isSubSet(const css::uno::Any& aSubSet, bool CacheItem::haveProps(const CacheItem& lProps) const { - for (const_iterator pIt = lProps.begin(); - pIt != lProps.end() ; - ++pIt ) + for (auto const& prop : lProps) { // i) one required property does not exist at this item => return false - const_iterator pItThis = find(pIt->first); + const_iterator pItThis = find(prop.first); if (pItThis == end()) { return false; } // ii) one item does not have the right value => return false - if (!isSubSet(pIt->second, pItThis->second)) + if (!isSubSet(prop.second, pItThis->second)) { return false; } @@ -310,15 +300,13 @@ bool CacheItem::haveProps(const CacheItem& lProps) const bool CacheItem::dontHaveProps(const CacheItem& lProps) const { - for (const_iterator pIt = lProps.begin(); - pIt != lProps.end() ; - ++pIt ) + for (auto const& prop : lProps) { // i) one item does not exist in general // => continue with next one, because // "excluding" means... "don't have it". // And "not exists" matches to "don't have it". - const_iterator pItThis = find(pIt->first); + const_iterator pItThis = find(prop.first); if (pItThis == end()) { continue; @@ -327,7 +315,7 @@ bool CacheItem::dontHaveProps(const CacheItem& lProps) const // ii) one item have the right value => return false // because this item has the requested property... // But we checked for "don't have it" here. - if (isSubSet(pIt->second, pItThis->second)) + if (isSubSet(prop.second, pItThis->second)) { return false; } diff --git a/filter/source/config/cache/cacheupdatelistener.cxx b/filter/source/config/cache/cacheupdatelistener.cxx index 1698037791ea..851f1fced49b 100644 --- a/filter/source/config/cache/cacheupdatelistener.cxx +++ b/filter/source/config/cache/cacheupdatelistener.cxx @@ -146,15 +146,11 @@ void SAL_CALL CacheUpdateListener::changesOccurred(const css::util::ChangesEven } bool bNotifyRefresh = false; - OUStringList::const_iterator pIt; - for ( pIt = lChangedItems.begin(); - pIt != lChangedItems.end() ; - ++pIt ) + for (auto const& changedItem : lChangedItems) { - const OUString& sItem = *pIt; try { - m_rCache.refreshItem(eType, sItem); + m_rCache.refreshItem(eType, changedItem); } catch(const css::container::NoSuchElementException&) { diff --git a/filter/source/config/cache/filtercache.cxx b/filter/source/config/cache/filtercache.cxx index 8db4a79ff5af..f6d80f97540c 100644 --- a/filter/source/config/cache/filtercache.cxx +++ b/filter/source/config/cache/filtercache.cxx @@ -263,16 +263,14 @@ OUStringList FilterCache::getMatchingItemsByProps( EItemType eType , // search items, which provides all needed properties of set "lIProps" // but not of set "lEProps"! - for (CacheItemList::const_iterator pIt = rList.begin(); - pIt != rList.end() ; - ++pIt ) + for (auto const& elem : rList) { if ( - (pIt->second.haveProps(lIProps) ) && - (pIt->second.dontHaveProps(lEProps)) + (elem.second.haveProps(lIProps) ) && + (elem.second.dontHaveProps(lEProps)) ) { - lKeys.push_back(pIt->first); + lKeys.push_back(elem.first); } } @@ -307,11 +305,9 @@ OUStringList FilterCache::getItemNames(EItemType eType) const const CacheItemList& rList = impl_getItemList(eType); OUStringList lKeys; - for (CacheItemList::const_iterator pIt = rList.begin(); - pIt != rList.end() ; - ++pIt ) + for (auto const& elem : rList) { - lKeys.push_back(pIt->first); + lKeys.push_back(elem.first); } return lKeys; // <- SAFE @@ -608,17 +604,14 @@ void FilterCache::impl_flushByList(const css::uno::Reference< css::container::XN css::uno::Reference< css::container::XNameContainer > xAddRemoveSet(xSet, css::uno::UNO_QUERY); css::uno::Reference< css::lang::XSingleServiceFactory > xFactory(xSet, css::uno::UNO_QUERY); - for (OUStringList::const_iterator pIt = lItems.begin(); - pIt != lItems.end() ; - ++pIt ) + for (auto const& item : lItems) { - const OUString& sItem = *pIt; - EItemFlushState eState = impl_specifyFlushOperation(xSet, rCache, sItem); + EItemFlushState eState = impl_specifyFlushOperation(xSet, rCache, item); switch(eState) { case E_ITEM_REMOVED : { - xAddRemoveSet->removeByName(sItem); + xAddRemoveSet->removeByName(item); } break; @@ -632,16 +625,16 @@ void FilterCache::impl_flushByList(const css::uno::Reference< css::container::XN throw css::uno::Exception("Can not add item. Set is finalized or mandatory!", css::uno::Reference< css::uno::XInterface >()); - CacheItemList::const_iterator pItem = rCache.find(sItem); + CacheItemList::const_iterator pItem = rCache.find(item); impl_saveItem(xItem, eType, pItem->second); - xAddRemoveSet->insertByName(sItem, css::uno::makeAny(xItem)); + xAddRemoveSet->insertByName(item, css::uno::makeAny(xItem)); } break; case E_ITEM_CHANGED : { css::uno::Reference< css::container::XNameReplace > xItem; - xSet->getByName(sItem) >>= xItem; + xSet->getByName(item) >>= xItem; // special case. no exception - but not a valid item => it must be finalized or mandatory! // Reject flush operation by throwing an exception. At least one item couldn't be flushed. @@ -649,7 +642,7 @@ void FilterCache::impl_flushByList(const css::uno::Reference< css::container::XN throw css::uno::Exception("Can not change item. Its finalized or mandatory!", css::uno::Reference< css::uno::XInterface >()); - CacheItemList::const_iterator pItem = rCache.find(sItem); + CacheItemList::const_iterator pItem = rCache.find(item); impl_saveItem(xItem, eType, pItem->second); } break; @@ -680,14 +673,12 @@ void FilterCache::detectFlatForURL(const css::util::URL& aURL , // Do it as first one - because: if a type match by a // pattern a following deep detection can be suppressed! // Further we can stop after first match ... - for (CacheItemRegistration::const_iterator pPattReg = m_lURLPattern2Types.begin(); - pPattReg != m_lURLPattern2Types.end() ; - ++pPattReg ) + for (auto const& pattern : m_lURLPattern2Types) { - WildCard aPatternCheck(pPattReg->first); + WildCard aPatternCheck(pattern.first); if (aPatternCheck.Matches(aURL.Main)) { - const OUStringList& rTypesForPattern = pPattReg->second; + const OUStringList& rTypesForPattern = pattern.second; FlatDetectionInfo aInfo; aInfo.sType = *(rTypesForPattern.begin()); @@ -707,12 +698,10 @@ void FilterCache::detectFlatForURL(const css::util::URL& aURL , if (pExtReg != m_lExtensions2Types.end()) { const OUStringList& rTypesForExtension = pExtReg->second; - for (OUStringList::const_iterator pIt = rTypesForExtension.begin(); - pIt != rTypesForExtension.end() ; - ++pIt ) + for (auto const& elem : rTypesForExtension) { FlatDetectionInfo aInfo; - aInfo.sType = *pIt; + aInfo.sType = elem; aInfo.bMatchByExtension = true; rFlatTypes.push_back(aInfo); @@ -987,12 +976,10 @@ void FilterCache::impl_validateAndOptimize() sal_Int32 nErrors = 0; OUStringBuffer sLog(256); - CacheItemList::iterator pIt; - - for (pIt = m_lTypes.begin(); pIt != m_lTypes.end(); ++pIt) + for (auto const& elem : m_lTypes) { - OUString sType = pIt->first; - CacheItem aType = pIt->second; + OUString sType = elem.first; + CacheItem aType = elem.second; // get its registration for file Extensions AND(!) URLPattern ... // It doesn't matter if these items exists or if our @@ -1173,27 +1160,23 @@ void FilterCache::impl_validateAndOptimize() // and remove all types from list a), which already // referenced by a loader b) OUStringList lTypes = getItemNames(E_TYPE); - for ( pIt = m_lFrameLoaders.begin(); - pIt != m_lFrameLoaders.end() ; - ++pIt ) + for (auto & frameLoader : m_lFrameLoaders) { // Note: of course the default loader must be ignored here. // Because we replace its registration later completely with all // types, which are not referenced by any other loader. // So we can avoid our code against the complexity of a diff! - OUString sLoader = pIt->first; + OUString sLoader = frameLoader.first; if (sLoader == sDefaultFrameLoader) continue; - CacheItem& rLoader = pIt->second; + CacheItem& rLoader = frameLoader.second; css::uno::Any& rTypesReg = rLoader[PROPNAME_TYPES]; OUStringList lTypesReg (comphelper::sequenceToContainer(rTypesReg.get >())); - for (OUStringList::const_iterator pTypesReg = lTypesReg.begin(); - pTypesReg != lTypesReg.end() ; - ++pTypesReg ) + for (auto const& typeReg : lTypesReg) { - OUStringList::iterator pTypeCheck = ::std::find(lTypes.begin(), lTypes.end(), *pTypesReg); + OUStringList::iterator pTypeCheck = ::std::find(lTypes.begin(), lTypes.end(), typeReg); if (pTypeCheck != lTypes.end()) lTypes.erase(pTypeCheck); } @@ -1500,16 +1483,12 @@ void FilterCache::impl_readPatchUINames(const css::uno::Reference< css::containe ::std::vector< OUString >::const_iterator pLocale ; ::comphelper::SequenceAsHashMap lUINames; - for ( pLocale = lLocales.begin(); - pLocale != lLocales.end() ; - ++pLocale ) + for (auto const& locale : lLocales) { - const OUString& sLocale = *pLocale; - OUString sValue; - xUIName->getByName(sLocale) >>= sValue; + xUIName->getByName(locale) >>= sValue; - lUINames[sLocale] <<= sValue; + lUINames[locale] <<= sValue; } aVal <<= lUINames.getAsConstPropertyValueList(); @@ -2143,19 +2122,16 @@ CacheItem FilterCache::impl_readOldItem(const css::uno::Reference< css::containe } sal_Int32 nProp = 0; - for (OUStringList::const_iterator pProp = lData.begin(); - pProp != lData.end() ; - ++pProp ) + for (auto const& prop : lData) { - const OUString& sProp = *pProp; switch(eType) { case E_TYPE : - impl_interpretDataVal4Type(sProp, nProp, aItem); + impl_interpretDataVal4Type(prop, nProp, aItem); break; case E_FILTER : - impl_interpretDataVal4Filter(sProp, nProp, aItem); + impl_interpretDataVal4Filter(prop, nProp, aItem); break; default: break; } @@ -2185,13 +2161,10 @@ OUStringList FilterCache::impl_tokenizeString(const OUString& sData , OUString FilterCache::impl_searchFrameLoaderForType(const OUString& sType) const { - CacheItemList::const_iterator pIt; - for ( pIt = m_lFrameLoaders.begin(); - pIt != m_lFrameLoaders.end() ; - ++pIt ) + for (auto const& frameLoader : m_lFrameLoaders) { - const OUString& sItem = pIt->first; - ::comphelper::SequenceAsHashMap lProps(pIt->second); + const OUString& sItem = frameLoader.first; + ::comphelper::SequenceAsHashMap lProps(frameLoader.second); OUStringList lTypes( comphelper::sequenceToContainer(lProps[PROPNAME_TYPES].get >())); @@ -2205,13 +2178,10 @@ OUString FilterCache::impl_searchFrameLoaderForType(const OUString& sType) const OUString FilterCache::impl_searchContentHandlerForType(const OUString& sType) const { - CacheItemList::const_iterator pIt; - for ( pIt = m_lContentHandlers.begin(); - pIt != m_lContentHandlers.end() ; - ++pIt ) + for (auto const& contentHandler : m_lContentHandlers) { - const OUString& sItem = pIt->first; - ::comphelper::SequenceAsHashMap lProps(pIt->second); + const OUString& sItem = contentHandler.first; + ::comphelper::SequenceAsHashMap lProps(contentHandler.second); OUStringList lTypes( comphelper::sequenceToContainer( lProps[PROPNAME_TYPES].get >() )); if (::std::find(lTypes.begin(), lTypes.end(), sType) != lTypes.end()) diff --git a/filter/source/config/cache/filterfactory.cxx b/filter/source/config/cache/filterfactory.cxx index ef8faeec31b2..a9564752334b 100644 --- a/filter/source/config/cache/filterfactory.cxx +++ b/filter/source/config/cache/filterfactory.cxx @@ -293,15 +293,12 @@ OUStringList FilterFactory::impl_queryMatchByDocumentService(const QueryTokenize OUStringList lFilterNames = pCache->getItemNames(FilterCache::E_FILTER); OUStringList lResult ; - for (OUStringList::const_iterator pName = lFilterNames.begin(); - pName != lFilterNames.end() ; - ++pName ) + for (auto const& filterName : lFilterNames) { try { - const OUString& sName = *pName; - const CacheItem aFilter = pCache->getItem(FilterCache::E_FILTER, sName); - CacheItem::const_iterator pProp ; + const CacheItem aFilter = pCache->getItem(FilterCache::E_FILTER, filterName); + CacheItem::const_iterator pProp; // "matchByDocumentService=" => any filter will be addressed here // "matchByDocumentService=all" => any filter will be addressed here @@ -343,7 +340,7 @@ OUStringList FilterFactory::impl_queryMatchByDocumentService(const QueryTokenize // OK - this filter passed all checks. // It match the query ... - lResult.push_back(sName); + lResult.push_back(filterName); } catch(const css::uno::RuntimeException&) { throw; } @@ -427,20 +424,12 @@ OUStringList FilterFactory::impl_getSortedFilterList(const QueryTokenizer& lToke // more complex search for all filters // We check first, which office modules are installed ... OUStringList lModules = impl_getListOfInstalledModules(); - OUStringList::const_iterator pIt2; - for ( pIt2 = lModules.begin(); - pIt2 != lModules.end() ; - ++pIt2 ) + for (auto const& module : lModules) { - sModule = *pIt2; - OUStringList lFilters4Module = impl_getSortedFilterListForModule(sModule, nIFlags, nEFlags); - OUStringList::const_iterator pIt3; - for ( pIt3 = lFilters4Module.begin(); - pIt3 != lFilters4Module.end() ; - ++pIt3 ) + OUStringList lFilters4Module = impl_getSortedFilterListForModule(module, nIFlags, nEFlags); + for (auto const& filter4Module : lFilters4Module) { - const OUString& sFilter = *pIt3; - lFilterList.push_back(sFilter); + lFilterList.push_back(filter4Module); } } } @@ -485,15 +474,12 @@ OUStringList FilterFactory::impl_getSortedFilterListForModule(const OUString& sM ::std::sort(lOtherFilters.begin(), lOtherFilters.end()); // merge both lists together - OUStringList lMergedFilters = lSortedFilters; - const OUStringList::const_iterator itlOtherFiltersEnd = lOtherFilters.end(); + OUStringList lMergedFilters = lSortedFilters; const OUStringList::const_iterator itlSortedFiltersEnd = lSortedFilters.end(); - for (OUStringList::const_iterator pIt = lOtherFilters.begin(); - pIt != itlOtherFiltersEnd ; - ++pIt ) + for (auto const& otherFilter : lOtherFilters) { - if (::std::find(lSortedFilters.begin(), lSortedFilters.end(), *pIt) == itlSortedFiltersEnd) - lMergedFilters.push_back(*pIt); + if (::std::find(lSortedFilters.begin(), lSortedFilters.end(), otherFilter) == itlSortedFiltersEnd) + lMergedFilters.push_back(otherFilter); } OUStringList::iterator pItToErase; diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx index 03158f06e3ba..6b7753665d78 100644 --- a/filter/source/config/cache/typedetection.cxx +++ b/filter/source/config/cache/typedetection.cxx @@ -357,10 +357,8 @@ public: void printFlatDetectionList(const char* caption, const FlatDetection& types) { cout << "-- " << caption << " (size=" << types.size() << ")" << endl; - FlatDetection::const_iterator it = types.begin(), itEnd = types.end(); - for (; it != itEnd; ++it) + for (auto const& item : types) { - const FlatDetectionInfo& item = *it; cout << " type='" << item.sType << "'; match by extension (" << item.bMatchByExtension << "); match by pattern (" << item.bMatchByPattern << "); pre-selected by doc service (" << item.bPreselectedByDocumentService << ")" << endl; @@ -508,19 +506,18 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes aLock.clear(); // <- SAFE - for (OUStringList::const_iterator pIt = lFilters.begin(); - pIt != lFilters.end(); ++pIt) + for (auto const& filter : lFilters) { // SAFE -> aLock.reset(); try { - CacheItem aFilter = cache.getItem(FilterCache::E_FILTER, *pIt); + CacheItem aFilter = cache.getItem(FilterCache::E_FILTER, filter); sal_Int32 nFlags = 0; aFilter[PROPNAME_FLAGS] >>= nFlags; if (static_cast(nFlags) & SfxFilterFlags::IMPORT) - sFilter = *pIt; + sFilter = filter; if (static_cast(nFlags) & SfxFilterFlags::PREFERED) break; } @@ -589,12 +586,9 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes aLock.clear(); // <- SAFE - OUStringList::const_iterator pIt; - for ( pIt = lFilters.begin(); - pIt != lFilters.end() ; - ++pIt ) + for (auto const& filter : lFilters) { - sFilter = *pIt; + sFilter = filter; // SAFE -> aLock.reset(); @@ -683,11 +677,9 @@ bool TypeDetection::impl_getPreselectionForType( OUStringList lExtensions(comphelper::sequenceToContainer(aType[PROPNAME_EXTENSIONS].get >() )); OUStringList lURLPattern(comphelper::sequenceToContainer(aType[PROPNAME_URLPATTERN].get >() )); - for (OUStringList::const_iterator pIt = lExtensions.begin(); - pIt != lExtensions.end() ; - ++pIt ) + for (auto const& extension : lExtensions) { - OUString sCheckExtension(pIt->toAsciiLowerCase()); + OUString sCheckExtension(extension.toAsciiLowerCase()); if (sCheckExtension == sExtension) { bBreakDetection = true; @@ -698,14 +690,12 @@ bool TypeDetection::impl_getPreselectionForType( if (!bBreakDetection) { - for (OUStringList::const_iterator pIt = lURLPattern.begin(); - pIt != lURLPattern.end() ; - ++pIt ) + for (auto const& elem : lURLPattern) { - WildCard aCheck(*pIt); + WildCard aCheck(elem); if (aCheck.Matches(aParsedURL.Main)) { - bMatchByPattern = true; + bMatchByPattern = true; break; } } @@ -766,11 +756,9 @@ bool TypeDetection::impl_getPreselectionForDocumentService( // But use temp. list of "preselected types" instead of incoming rFlatTypes list! // The reason behind: we must filter the obtained results. And copying stl entries // is an easier job than removing them .-) - for (OUStringList::const_iterator pFilter = lFilters.begin(); - pFilter != lFilters.end(); - ++pFilter) + for (auto const& filter : lFilters) { - OUString aType = impl_getTypeFromFilter(*pFilter); + OUString aType = impl_getTypeFromFilter(filter); if (aType.isEmpty()) continue; @@ -818,9 +806,9 @@ void TypeDetection::impl_getAllFormatTypes( } // Retrieve the default type for each of these filters, and store them. - for (OUStringList::const_iterator it = aFilterNames.begin(); it != aFilterNames.end(); ++it) + for (auto const& filterName : aFilterNames) { - OUString aType = impl_getTypeFromFilter(*it); + OUString aType = impl_getTypeFromFilter(filterName); if (aType.isEmpty()) continue; @@ -834,18 +822,17 @@ void TypeDetection::impl_getAllFormatTypes( // Get all types that match the URL alone. FlatDetection aFlatByURL; TheFilterCache::get().detectFlatForURL(aParsedURL, aFlatByURL); - FlatDetection::const_iterator it = aFlatByURL.begin(), itEnd = aFlatByURL.end(); - for (; it != itEnd; ++it) + for (auto const& elem : aFlatByURL) { - FlatDetection::iterator itPos = std::find_if(rFlatTypes.begin(), rFlatTypes.end(), FindByType(it->sType)); + FlatDetection::iterator itPos = std::find_if(rFlatTypes.begin(), rFlatTypes.end(), FindByType(elem.sType)); if (itPos == rFlatTypes.end()) // Not in the list yet. - rFlatTypes.push_back(*it); + rFlatTypes.push_back(elem); else { // Already in the list. Update the flags. FlatDetectionInfo& rInfo = *itPos; - const FlatDetectionInfo& rThisInfo = *it; + const FlatDetectionInfo& rThisInfo = elem; if (rThisInfo.bMatchByExtension) rInfo.bMatchByExtension = true; if (rThisInfo.bMatchByPattern) @@ -899,12 +886,11 @@ OUString TypeDetection::impl_detectTypeFlatAndDeep( utl::MediaDescriptor& r // or any needed information could not be // obtained from the cache => ignore it, and continue with search - for (FlatDetection::const_iterator pFlatIt = lFlatTypes.begin(); - pFlatIt != lFlatTypes.end() && !m_bCancel; - ++pFlatIt ) + for (auto const& flatTypeInfo : lFlatTypes) { - const FlatDetectionInfo& aFlatTypeInfo = *pFlatIt; - OUString sFlatType = aFlatTypeInfo.sType; + if (m_bCancel) + break; + OUString sFlatType = flatTypeInfo.sType; if (!impl_validateAndSetTypeOnDescriptor(rDescriptor, sFlatType)) continue; @@ -912,7 +898,7 @@ OUString TypeDetection::impl_detectTypeFlatAndDeep( utl::MediaDescriptor& r // b) if ( (!bAllowDeep ) || - (aFlatTypeInfo.bMatchByPattern) + (flatTypeInfo.bMatchByPattern) ) { return sFlatType; diff --git a/filter/source/flash/swfexporter.cxx b/filter/source/flash/swfexporter.cxx index 608de8b4fdd8..641f4d72ca8d 100644 --- a/filter/source/flash/swfexporter.cxx +++ b/filter/source/flash/swfexporter.cxx @@ -61,11 +61,9 @@ PageInfo::PageInfo() PageInfo::~PageInfo() { - std::vector::iterator aIter( maShapesVector.begin() ); - const std::vector::iterator aEnd( maShapesVector.end() ); - while( aIter != aEnd ) + for (auto const& shape : maShapesVector) { - delete *aIter++; + delete shape; } } diff --git a/filter/source/flash/swfwriter.cxx b/filter/source/flash/swfwriter.cxx index 2d9f44c577a5..4d3921158e68 100644 --- a/filter/source/flash/swfwriter.cxx +++ b/filter/source/flash/swfwriter.cxx @@ -128,11 +128,10 @@ void ImplCopySvStreamToXOutputStream( SvStream& rIn, Reference< XOutputStream > void Writer::storeTo( Reference< XOutputStream > const &xOutStream ) { - for(FontMap::iterator i = maFonts.begin(); i != maFonts.end(); ++i) + for (auto const& font : maFonts) { - FlashFont* pFont = (*i); - pFont->write( *mpFontsStream ); - delete pFont; + font->write( *mpFontsStream ); + delete font; } // Endtag @@ -275,24 +274,17 @@ sal_uInt16 Writer::defineShape( const GDIMetaFile& rMtf ) Impl_writeActions( rMtf ); sal_uInt16 nId = 0; - { - CharacterIdVector::iterator aIter( maShapeIds.begin() ); - const CharacterIdVector::iterator aEnd( maShapeIds.end() ); - - bool bHaveShapes = aIter != aEnd; + if (maShapeIds.empty()) + return nId; - if (bHaveShapes) + { + nId = startSprite(); + sal_uInt16 iDepth = 1; + for (auto const& shape : maShapeIds) { - nId = startSprite(); - - sal_uInt16 iDepth = 1; - for(; aIter != aEnd; ++aIter) - { - placeShape( *aIter, iDepth++, 0, 0 ); - } - - endSprite(); + placeShape( shape, iDepth++, 0, 0 ); } + endSprite(); } maShapeIds.clear(); diff --git a/filter/source/flash/swfwriter1.cxx b/filter/source/flash/swfwriter1.cxx index d807d4ac0dc2..09ed4f647efc 100644 --- a/filter/source/flash/swfwriter1.cxx +++ b/filter/source/flash/swfwriter1.cxx @@ -365,15 +365,12 @@ bool compare_fonts_for_me(const vcl::Font& rFont1, const vcl::Font& rFont2) FlashFont& Writer::Impl_getFont( const vcl::Font& rFont ) { - FontMap::iterator aIter( maFonts.begin() ); - const FontMap::iterator aEnd( maFonts.end() ); - - for(; aIter != aEnd; ++aIter) + for (auto const& font : maFonts) { - const vcl::Font tempFont = (*aIter)->getFont(); + const vcl::Font tempFont = font->getFont(); if( compare_fonts_for_me(tempFont, rFont) ) { - return **aIter; + return *font; } } diff --git a/filter/source/flash/swfwriter2.cxx b/filter/source/flash/swfwriter2.cxx index 4735a0f3388c..85df61b7bd43 100644 --- a/filter/source/flash/swfwriter2.cxx +++ b/filter/source/flash/swfwriter2.cxx @@ -108,11 +108,9 @@ void BitStream::writeTo( SvStream& out ) { pad(); - std::vector< sal_uInt8 >::iterator aIter( maData.begin() ); - const std::vector< sal_uInt8>::iterator aEnd( maData.end() ); - while(aIter != aEnd) + for (auto const& data : maData) { - out.WriteUChar( *aIter++ ); + out.WriteUChar(data); } } @@ -336,16 +334,16 @@ Sprite::Sprite( sal_uInt16 nId ) Sprite::~Sprite() { - for(std::vector< Tag* >::iterator i = maTags.begin(); i != maTags.end(); ++i) - delete *i; + for (auto const& tag : maTags) + delete tag; } void Sprite::write( SvStream& out ) { SvMemoryStream aTmp; - for(std::vector< Tag* >::iterator i = maTags.begin(); i != maTags.end(); ++i) - (*i)->write( aTmp ); + for (auto const& tag : maTags) + tag->write( aTmp ); if( !mnFrames ) mnFrames = 1; @@ -464,8 +462,8 @@ void FlashFont::write( SvStream& out ) sal_uInt16 nGlyphs = uInt16_( maGlyphOffsets.size() ); sal_uInt16 nOffset = nGlyphs * sizeof( sal_uInt16 ); - for(std::vector< sal_uInt16 >::iterator i = maGlyphOffsets.begin(); i != maGlyphOffsets.end(); ++i) - aTag.addUI16( nOffset + (*i) ); + for (auto const& glyphOffset : maGlyphOffsets) + aTag.addUI16( nOffset + glyphOffset ); aTag.addBits( maGlyphData ); @@ -625,10 +623,10 @@ void FillStyle::Impl_addGradient( Tag* pTag ) const pTag->addUI8( static_cast( aGradientRecords.size() ) ); - for(std::vector< GradRecord >::iterator i = aGradientRecords.begin(); i != aGradientRecords.end(); ++i) + for (auto const& gradientRecord : aGradientRecords) { - pTag->addUI8( (*i).mnRatio ); - pTag->addRGBA( (*i).maColor ); + pTag->addUI8( gradientRecord.mnRatio ); + pTag->addRGBA( gradientRecord.maColor ); } } diff --git a/filter/source/graphicfilter/eps/eps.cxx b/filter/source/graphicfilter/eps/eps.cxx index 9a1a81b71269..c5f8aa240872 100644 --- a/filter/source/graphicfilter/eps/eps.cxx +++ b/filter/source/graphicfilter/eps/eps.cxx @@ -1612,12 +1612,12 @@ void PSWriter::ImplSetClipRegion( vcl::Region const & rClipRegion ) RectangleVector aRectangles; rClipRegion.GetRegionRectangles(aRectangles); - for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter) + for (auto const& rectangle : aRectangles) { - double nX1(aRectIter->Left()); - double nY1(aRectIter->Top()); - double nX2(aRectIter->Right()); - double nY2(aRectIter->Bottom()); + double nX1(rectangle.Left()); + double nY1(rectangle.Top()); + double nX2(rectangle.Right()); + double nY2(rectangle.Bottom()); ImplWriteDouble( nX1 ); ImplWriteDouble( nY1 ); @@ -1714,21 +1714,21 @@ void PSWriter::ImplBmp( Bitmap const * pBitmap, Bitmap const * pMaskBitmap, cons aRegion.GetRegionRectangles(aRectangles); const long nMoveVertical(nHeightLeft - nHeightOrg); - for(RectangleVector::iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter) + for (auto & rectangle : aRectangles) { - aRectIter->Move(0, nMoveVertical); + rectangle.Move(0, nMoveVertical); - ImplWriteLong( aRectIter->Left() ); - ImplWriteLong( aRectIter->Top() ); + ImplWriteLong( rectangle.Left() ); + ImplWriteLong( rectangle.Top() ); ImplWriteByte( 'm' ); - ImplWriteLong( aRectIter->Right() + 1 ); - ImplWriteLong( aRectIter->Top() ); + ImplWriteLong( rectangle.Right() + 1 ); + ImplWriteLong( rectangle.Top() ); ImplWriteByte( 'l' ); - ImplWriteLong( aRectIter->Right() + 1 ); - ImplWriteLong( aRectIter->Bottom() + 1 ); + ImplWriteLong( rectangle.Right() + 1 ); + ImplWriteLong( rectangle.Bottom() + 1 ); ImplWriteByte( 'l' ); - ImplWriteLong( aRectIter->Left() ); - ImplWriteLong( aRectIter->Bottom() + 1 ); + ImplWriteLong( rectangle.Left() ); + ImplWriteLong( rectangle.Bottom() + 1 ); ImplWriteByte( 'l' ); ImplWriteByte( 'p', PS_SPACE | PS_WRAP ); } @@ -2038,9 +2038,8 @@ void PSWriter::ImplText( const OUString& rUniString, const Point& rPos, const lo ImplWriteF( nRotation, 1 ); mpPS->WriteCharPtr( "r " ); } - std::vector::iterator aIter( aPolyPolyVec.begin() ); - while ( aIter != aPolyPolyVec.end() ) - ImplPolyPoly( *aIter++, true ); + for (auto const& elem : aPolyPolyVec) + ImplPolyPoly( elem, true ); ImplWriteLine( "pom" ); } bLineColor = bOldLineColor; diff --git a/filter/source/msfilter/escherex.cxx b/filter/source/msfilter/escherex.cxx index 3f9834e6c194..9c7c01c5f0e6 100644 --- a/filter/source/msfilter/escherex.cxx +++ b/filter/source/msfilter/escherex.cxx @@ -2448,23 +2448,21 @@ void ConvertEnhancedCustomShapeEquation( SdrObjCustomShape* pCustoShape, rEquationOrder.push_back( rEquations.size() - 1 ); } // now updating our old equation indices, they are marked with a bit in the hiword of nOperation - std::vector< EnhancedCustomShapeEquation >::iterator aIter( rEquations.begin() ); - std::vector< EnhancedCustomShapeEquation >::iterator aEnd ( rEquations.end() ); - while( aIter != aEnd ) + for (auto & equation : rEquations) { sal_uInt32 nMask = 0x20000000; for( i = 0; i < 3; i++ ) { - if ( aIter->nOperation & nMask ) + if ( equation.nOperation & nMask ) { - aIter->nOperation ^= nMask; - const size_t nIndex(aIter->nPara[ i ] & 0x3ff); + equation.nOperation ^= nMask; + const size_t nIndex(equation.nPara[ i ] & 0x3ff); // #i124661# check index access, there are cases where this is out of bound leading // to errors up to crashes when executed if(nIndex < rEquationOrder.size()) { - aIter->nPara[ i ] = rEquationOrder[ nIndex ] | 0x400; + equation.nPara[ i ] = rEquationOrder[ nIndex ] | 0x400; } else { @@ -2473,7 +2471,6 @@ void ConvertEnhancedCustomShapeEquation( SdrObjCustomShape* pCustoShape, } nMask <<= 1; } - ++aIter; } } } @@ -2938,15 +2935,12 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT .WriteUInt16( nElements ) .WriteUInt16( nElementSize ); - std::vector< EnhancedCustomShapeEquation >::const_iterator aIter( aEquations.begin() ); - std::vector< EnhancedCustomShapeEquation >::const_iterator aEnd ( aEquations.end() ); - while( aIter != aEnd ) + for (auto const& equation : aEquations) { - aOut.WriteUInt16( aIter->nOperation ) - .WriteInt16( aIter->nPara[ 0 ] ) - .WriteInt16( aIter->nPara[ 1 ] ) - .WriteInt16( aIter->nPara[ 2 ] ); - ++aIter; + aOut.WriteUInt16( equation.nOperation ) + .WriteInt16( equation.nPara[ 0 ] ) + .WriteInt16( equation.nPara[ 1 ] ) + .WriteInt16( equation.nPara[ 2 ] ); } sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ]; memcpy( pBuf, aOut.GetData(), nStreamSize ); @@ -4825,10 +4819,10 @@ void EscherExGlobal::WriteDggAtom( SvStream& rStrm ) const // calculate and write the fixed DGG data sal_uInt32 nShapeCount = 0; sal_uInt32 nLastShapeId = 0; - for( DrawingInfoVector::const_iterator aIt = maDrawingInfos.begin(), aEnd = maDrawingInfos.end(); aIt != aEnd; ++aIt ) + for (auto const& drawingInfo : maDrawingInfos) { - nShapeCount += aIt->mnShapeCount; - nLastShapeId = ::std::max( nLastShapeId, aIt->mnLastShapeId ); + nShapeCount += drawingInfo.mnShapeCount; + nLastShapeId = ::std::max( nLastShapeId, drawingInfo.mnLastShapeId ); } // the non-existing cluster with index #0 is counted too sal_uInt32 nClusterCount = static_cast< sal_uInt32 >( maClusterTable.size() + 1 ); @@ -4836,8 +4830,8 @@ void EscherExGlobal::WriteDggAtom( SvStream& rStrm ) const rStrm.WriteUInt32( nLastShapeId ).WriteUInt32( nClusterCount ).WriteUInt32( nShapeCount ).WriteUInt32( nDrawingCount ); // write the cluster table - for( ClusterTable::const_iterator aIt = maClusterTable.begin(), aEnd = maClusterTable.end(); aIt != aEnd; ++aIt ) - rStrm.WriteUInt32( aIt->mnDrawingId ).WriteUInt32( aIt->mnNextShapeId ); + for (auto const& elem : maClusterTable) + rStrm.WriteUInt32( elem.mnDrawingId ).WriteUInt32( elem.mnNextShapeId ); } SvStream* EscherExGlobal::QueryPictureStream() @@ -4967,10 +4961,10 @@ void EscherEx::InsertAtCurrentPos( sal_uInt32 nBytes ) else mpOutStrm->SeekRel( nSize ); } - for (std::vector< sal_uInt32 >::iterator aIter( mOffsets.begin() ), aEnd( mOffsets.end() ); aIter != aEnd ; ++aIter) + for (auto & offset : mOffsets) { - if ( *aIter > nCurPos ) - *aIter += nBytes; + if ( offset > nCurPos ) + offset += nBytes; } mpOutStrm->Seek( STREAM_SEEK_TO_END ); nSource = mpOutStrm->Tell(); -- cgit