diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-02-20 01:10:07 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-20 07:17:38 +0100 |
commit | 6a143985bdc5d12d1f9e8cf8592440282986c099 (patch) | |
tree | 346e09d6ba1146b52a6a484a2883f3e898184648 | |
parent | d707a5e64ba53ddb7669cca725915527aa788a6b (diff) |
Simplify containers iterations in desktop, dtrans, editeng, extensions
Use range-based loop or replace with STL functions
Change-Id: Ic5389d123d0a6a32a8bb46b081165e94a7c55292
Reviewed-on: https://gerrit.libreoffice.org/68036
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
25 files changed, 181 insertions, 295 deletions
diff --git a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx index 8a92a746ca2f..eb34d3730ada 100644 --- a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx +++ b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx @@ -885,15 +885,12 @@ bool ExtensionBox_Impl::FindEntryPos( const TEntry_Impl& rEntry, const long nSta void ExtensionBox_Impl::cleanVecListenerAdded() { - auto i = m_vListenerAdded.begin(); - while( i != m_vListenerAdded.end()) - { - const uno::Reference<deployment::XPackage> hardRef(*i); - if (!hardRef.is()) - i = m_vListenerAdded.erase(i); - else - ++i; - } + m_vListenerAdded.erase(std::remove_if(m_vListenerAdded.begin(), m_vListenerAdded.end(), + [](const uno::WeakReference<deployment::XPackage>& rxListener) { + const uno::Reference<deployment::XPackage> hardRef(rxListener); + return !hardRef.is(); + }), + m_vListenerAdded.end()); } void ExtensionBox_Impl::addEventListenerOnce( @@ -1003,39 +1000,37 @@ void ExtensionBox_Impl::removeEntry( const uno::Reference< deployment::XPackage { ::osl::ClearableMutexGuard aGuard( m_entriesMutex ); - for ( auto iIndex = m_vEntries.begin(); iIndex != m_vEntries.end(); ++iIndex ) + auto iIndex = std::find_if(m_vEntries.begin(), m_vEntries.end(), + [&xPackage](const TEntry_Impl& rxEntry) { return rxEntry->m_xPackage == xPackage; }); + if (iIndex != m_vEntries.end()) { - if ( (*iIndex)->m_xPackage == xPackage ) + long nPos = iIndex - m_vEntries.begin(); + + // Entries mustn't be removed here, because they contain a hyperlink control + // which can only be deleted when the thread has the solar mutex. Therefore + // the entry will be moved into the m_vRemovedEntries list which will be + // cleared on the next paint event + m_vRemovedEntries.push_back( *iIndex ); + (*iIndex)->m_xPackage->removeEventListener(m_xRemoveListener.get()); + m_vEntries.erase( iIndex ); + + m_bNeedsRecalc = true; + + if ( IsReallyVisible() ) + invalidate = true; + + if ( m_bHasActive ) { - long nPos = iIndex - m_vEntries.begin(); - - // Entries mustn't be removed here, because they contain a hyperlink control - // which can only be deleted when the thread has the solar mutex. Therefore - // the entry will be moved into the m_vRemovedEntries list which will be - // cleared on the next paint event - m_vRemovedEntries.push_back( *iIndex ); - (*iIndex)->m_xPackage->removeEventListener(m_xRemoveListener.get()); - m_vEntries.erase( iIndex ); - - m_bNeedsRecalc = true; - - if ( IsReallyVisible() ) - invalidate = true; - - if ( m_bHasActive ) - { - if ( nPos < m_nActive ) - m_nActive -= 1; - else if ( ( nPos == m_nActive ) && - ( nPos == static_cast<long>(m_vEntries.size()) ) ) - m_nActive -= 1; - - m_bHasActive = false; - //clear before calling out of this method - aGuard.clear(); - selectEntry( m_nActive ); - } - break; + if ( nPos < m_nActive ) + m_nActive -= 1; + else if ( ( nPos == m_nActive ) && + ( nPos == static_cast<long>(m_vEntries.size()) ) ) + m_nActive -= 1; + + m_bHasActive = false; + //clear before calling out of this method + aGuard.clear(); + selectEntry( m_nActive ); } } } diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx index bea253cb5c96..7a4476f69319 100644 --- a/desktop/source/migration/migration.cxx +++ b/desktop/source/migration/migration.cxx @@ -337,18 +337,11 @@ bool MigrationImpl::checkMigrationCompleted() static void insertSorted(migrations_available& rAvailableMigrations, supported_migration const & aSupportedMigration) { - bool bInserted( false ); - migrations_available::iterator pIter = rAvailableMigrations.begin(); - while (pIter != rAvailableMigrations.end()) - { - if ( pIter->nPriority < aSupportedMigration.nPriority ) { - rAvailableMigrations.insert(pIter, aSupportedMigration ); - bInserted = true; - break; // i111193: insert invalidates iterator! - } - ++pIter; - } - if ( !bInserted ) + migrations_available::iterator pIter = std::find_if(rAvailableMigrations.begin(), rAvailableMigrations.end(), + [&aSupportedMigration](const supported_migration& rMigration) { return rMigration.nPriority < aSupportedMigration.nPriority; }); + if (pIter != rAvailableMigrations.end()) + rAvailableMigrations.insert(pIter, aSupportedMigration ); + else rAvailableMigrations.push_back( aSupportedMigration ); } diff --git a/dtrans/source/cnttype/mcnttype.cxx b/dtrans/source/cnttype/mcnttype.cxx index 4ba1a295fd8a..8b35abb23193 100644 --- a/dtrans/source/cnttype/mcnttype.cxx +++ b/dtrans/source/cnttype/mcnttype.cxx @@ -20,6 +20,7 @@ #include <sal/config.h> #include <com/sun/star/container/NoSuchElementException.hpp> +#include <comphelper/sequence.hxx> #include <rtl/ustring.hxx> #include <tools/inetmime.hxx> @@ -51,18 +52,7 @@ OUString SAL_CALL CMimeContentType::getFullMediaType( ) Sequence< OUString > SAL_CALL CMimeContentType::getParameters( ) { - Sequence< OUString > seqParams; - - map< OUString, OUString >::iterator iter; - map< OUString, OUString >::iterator iter_end = m_ParameterMap.end( ); - - for ( iter = m_ParameterMap.begin( ); iter != iter_end; ++iter ) - { - seqParams.realloc( seqParams.getLength( ) + 1 ); - seqParams[seqParams.getLength( ) - 1] = iter->first; - } - - return seqParams; + return comphelper::mapKeysToSequence(m_ParameterMap); } sal_Bool SAL_CALL CMimeContentType::hasParameter( const OUString& aName ) diff --git a/dtrans/source/cnttype/wbench/testcnttype.cxx b/dtrans/source/cnttype/wbench/testcnttype.cxx index 86f2bf969a81..a148348ff6cb 100644 --- a/dtrans/source/cnttype/wbench/testcnttype.cxx +++ b/dtrans/source/cnttype/wbench/testcnttype.cxx @@ -93,14 +93,13 @@ sal_Bool processCntTypesAndWriteResultIntoFile( char* fname, vector< string >& v // set pointer to file start fseek( fstream, 0, SEEK_SET ); - vector< string >::iterator iter_end = vecData.end( ); - for ( vector< string >::iterator iter = vecData.begin( ); iter != iter_end; ++iter ) + for ( const auto& rData : vecData ) { try { - fprintf( fstream, "Read: %s\n", iter->c_str( ) ); + fprintf( fstream, "Read: %s\n", rData.c_str( ) ); - Reference< XMimeContentType > xMCntTyp = cnttypeFactory->createMimeContentType( OUString::createFromAscii( iter->c_str( ) ) ); + Reference< XMimeContentType > xMCntTyp = cnttypeFactory->createMimeContentType( OUString::createFromAscii( rData.c_str( ) ) ); fwprintf( fstream, OUString("Type: %s\n"), xMCntTyp->getMediaType( ).getStr( ) ); fwprintf( fstream, OUString("Subtype: %s\n"), xMCntTyp->getMediaSubtype( ).getStr( ) ); diff --git a/dtrans/source/win32/ftransl/ftransl.cxx b/dtrans/source/win32/ftransl/ftransl.cxx index 1ab6e1c87089..8293e22a8cd8 100644 --- a/dtrans/source/win32/ftransl/ftransl.cxx +++ b/dtrans/source/win32/ftransl/ftransl.cxx @@ -355,38 +355,27 @@ namespace { void findDataFlavorForStandardFormatId( sal_Int32 aStandardFormatId, DataFlavor& aDataFlavor ) { /* - we break the for loop if we find the first CF_INVALID + we stop search if we find the first CF_INVALID because in the translation table the entries with a standard clipboard format id appear before the other entries with CF_INVALID */ - vector< FormatEntry >::const_iterator citer_end = g_TranslTable.end( ); - for ( vector< FormatEntry >::const_iterator citer = g_TranslTable.begin( ); citer != citer_end; ++citer ) - { - sal_Int32 stdId = citer->aStandardFormatId; - if ( aStandardFormatId == stdId ) - { - aDataFlavor = citer->aDataFlavor; - break; - } - else if ( stdId == CF_INVALID ) - break; - } + vector< FormatEntry >::const_iterator citer = std::find_if(g_TranslTable.begin(), g_TranslTable.end(), + [&aStandardFormatId](const FormatEntry& rEntry) { + return rEntry.aStandardFormatId == aStandardFormatId + || rEntry.aStandardFormatId == CF_INVALID; + }); + if (citer != g_TranslTable.end() && citer->aStandardFormatId == aStandardFormatId) + aDataFlavor = citer->aDataFlavor; } void findDataFlavorForNativeFormatName( const OUString& aNativeFormatName, DataFlavor& aDataFlavor ) { - vector< FormatEntry >::const_iterator citer_end = g_TranslTable.end( ); - for ( vector< FormatEntry >::const_iterator citer = g_TranslTable.begin( ); - citer != citer_end; - ++citer ) - { - if ( aNativeFormatName.equalsIgnoreAsciiCase( citer->aNativeFormatName ) ) - { - aDataFlavor = citer->aDataFlavor; - break; - } - } + vector< FormatEntry >::const_iterator citer = std::find_if(g_TranslTable.begin(), g_TranslTable.end(), + [&aNativeFormatName](const FormatEntry& rEntry) { + return aNativeFormatName.equalsIgnoreAsciiCase(rEntry.aNativeFormatName); }); + if (citer != g_TranslTable.end()) + aDataFlavor = citer->aDataFlavor; } void findStandardFormatIdForCharset( const OUString& aCharset, Any& aAny ) @@ -403,16 +392,13 @@ void findStandardFormatIdForCharset( const OUString& aCharset, Any& aAny ) void setStandardFormatIdForNativeFormatName( const OUString& aNativeFormatName, Any& aAny ) { - vector< FormatEntry >::const_iterator citer_end = g_TranslTable.end( ); - for ( vector< FormatEntry >::const_iterator citer = g_TranslTable.begin( ); citer != citer_end; ++citer ) - { - if ( aNativeFormatName.equalsIgnoreAsciiCase( citer->aNativeFormatName ) && - (CF_INVALID != citer->aStandardFormatId) ) - { - aAny <<= citer->aStandardFormatId; - break; - } - } + vector< FormatEntry >::const_iterator citer = std::find_if(g_TranslTable.begin(), g_TranslTable.end(), + [&aNativeFormatName](const FormatEntry& rEntry) { + return aNativeFormatName.equalsIgnoreAsciiCase(rEntry.aNativeFormatName) + && (CF_INVALID != rEntry.aStandardFormatId); + }); + if (citer != g_TranslTable.end()) + aAny <<= citer->aStandardFormatId; } void findStdFormatIdOrNativeFormatNameForFullMediaType( @@ -420,23 +406,21 @@ void findStdFormatIdOrNativeFormatNameForFullMediaType( const OUString& aFullMediaType, Any& aAny ) { - vector< FormatEntry >::const_iterator citer_end = g_TranslTable.end( ); - for ( vector< FormatEntry >::const_iterator citer = g_TranslTable.begin( ); citer != citer_end; ++citer ) + vector< FormatEntry >::const_iterator citer = std::find_if(g_TranslTable.begin(), g_TranslTable.end(), + [&aRefXMimeFactory, &aFullMediaType](const FormatEntry& rEntry) { + Reference<XMimeContentType> refXMime( aRefXMimeFactory->createMimeContentType(rEntry.aDataFlavor.MimeType) ); + return aFullMediaType.equalsIgnoreAsciiCase(refXMime->getFullMediaType()); + }); + if (citer != g_TranslTable.end()) { - Reference< XMimeContentType > - refXMime( aRefXMimeFactory->createMimeContentType( citer->aDataFlavor.MimeType ) ); - if ( aFullMediaType.equalsIgnoreAsciiCase( refXMime->getFullMediaType( ) ) ) + sal_Int32 cf = citer->aStandardFormatId; + if ( CF_INVALID != cf ) + aAny <<= cf; + else { - sal_Int32 cf = citer->aStandardFormatId; - if ( CF_INVALID != cf ) - aAny <<= cf; - else - { - OSL_ENSURE( citer->aNativeFormatName.getLength( ), - "Invalid standard format id and empty native format name in translation table" ); - aAny <<= citer->aNativeFormatName; - } - break; + OSL_ENSURE( citer->aNativeFormatName.getLength( ), + "Invalid standard format id and empty native format name in translation table" ); + aAny <<= citer->aNativeFormatName; } } } diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index 1b8c079b58ba..020a5a32d7aa 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -884,36 +884,20 @@ void Test::testHyperlinkSearch() bool hasBold(const editeng::Section& rSecAttr) { - std::vector<const SfxPoolItem*>::const_iterator it = rSecAttr.maAttributes.begin(), itEnd = rSecAttr.maAttributes.end(); - for (; it != itEnd; ++it) - { - const SfxPoolItem* p = *it; - if (p->Which() != EE_CHAR_WEIGHT) - continue; - - if (static_cast<const SvxWeightItem*>(p)->GetWeight() != WEIGHT_BOLD) - continue; - - return true; - } - return false; + return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), + [](const SfxPoolItem* p) { + return p->Which() == EE_CHAR_WEIGHT + && static_cast<const SvxWeightItem*>(p)->GetWeight() == WEIGHT_BOLD; + }); } bool hasItalic(const editeng::Section& rSecAttr) { - std::vector<const SfxPoolItem*>::const_iterator it = rSecAttr.maAttributes.begin(), itEnd = rSecAttr.maAttributes.end(); - for (; it != itEnd; ++it) - { - const SfxPoolItem* p = *it; - if (p->Which() != EE_CHAR_ITALIC) - continue; - - if (static_cast<const SvxPostureItem*>(p)->GetPosture() != ITALIC_NORMAL) - continue; - - return true; - } - return false; + return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), + [](const SfxPoolItem* p) { + return p->Which() == EE_CHAR_ITALIC + && static_cast<const SvxPostureItem*>(p)->GetPosture() == ITALIC_NORMAL; + }); } void Test::testBoldItalicCopyPaste() @@ -1104,19 +1088,11 @@ void Test::testBoldItalicCopyPaste() // Auxiliary function to test Underline text Copy/Paste using Legacy Format bool hasUnderline(const editeng::Section& rSecAttr) { - std::vector<const SfxPoolItem*>::const_iterator it = rSecAttr.maAttributes.begin(), itEnd = rSecAttr.maAttributes.end(); - for (; it != itEnd; ++it) - { - const SfxPoolItem* p = *it; - if (p->Which() != EE_CHAR_UNDERLINE) - continue; - - if (static_cast<const SvxUnderlineItem*>(p)->GetLineStyle() != LINESTYLE_SINGLE) - continue; - - return true; - } - return false; + return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), + [](const SfxPoolItem* p) { + return p->Which() == EE_CHAR_UNDERLINE + && static_cast<const SvxUnderlineItem*>(p)->GetLineStyle() == LINESTYLE_SINGLE; + }); } void Test::testUnderlineCopyPaste() diff --git a/editeng/source/accessibility/AccessibleParaManager.cxx b/editeng/source/accessibility/AccessibleParaManager.cxx index c8db48792835..8a7ce274e5d0 100644 --- a/editeng/source/accessibility/AccessibleParaManager.cxx +++ b/editeng/source/accessibility/AccessibleParaManager.cxx @@ -235,8 +235,8 @@ namespace accessibility rChild.SetState( AccessibleStateType::FOCUSED ); // add states passed from outside - for( VectorOfStates::const_iterator aIt = maChildStates.begin(), aEnd = maChildStates.end(); aIt != aEnd; ++aIt ) - rChild.SetState( *aIt ); + for( const auto& rState : maChildStates ) + rChild.SetState( rState ); } void AccessibleParaManager::SetState( sal_Int32 nChild, const sal_Int16 nStateId ) diff --git a/editeng/source/accessibility/AccessibleStaticTextBase.cxx b/editeng/source/accessibility/AccessibleStaticTextBase.cxx index 73a93f210326..c28c94b7dc99 100644 --- a/editeng/source/accessibility/AccessibleStaticTextBase.cxx +++ b/editeng/source/accessibility/AccessibleStaticTextBase.cxx @@ -913,12 +913,11 @@ namespace accessibility uno::Sequence< beans::PropertyValue > aSeq = mpImpl->GetParagraph( nPara ).getDefaultAttributes( RequestedAttributes ); PropertyValueVector aIntersectionVec; - PropertyValueVector::const_iterator aEnd = aDefAttrVec.end(); - for ( PropertyValueVector::const_iterator aItr = aDefAttrVec.begin(); aItr != aEnd; ++aItr ) + for ( const auto& rDefAttr : aDefAttrVec ) { const beans::PropertyValue* pItr = aSeq.getConstArray(); const beans::PropertyValue* pEnd = pItr + aSeq.getLength(); - const beans::PropertyValue* pFind = std::find_if( pItr, pEnd, PropertyValueEqualFunctor(*aItr) ); + const beans::PropertyValue* pFind = std::find_if( pItr, pEnd, PropertyValueEqualFunctor(rDefAttr) ); if ( pFind != pEnd ) { aIntersectionVec.push_back( *pFind ); diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index d19542ddc056..d86d39fbf18a 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -2798,12 +2798,13 @@ const EditCharAttrib* CharAttribList::FindAttrib( sal_uInt16 nWhich, sal_Int32 n { // Backwards, if one ends where the next starts. // => The starting one is the valid one ... - AttribsType::const_reverse_iterator it = aAttribs.rbegin(), itEnd = aAttribs.rend(); - for (; it != itEnd; ++it) + AttribsType::const_reverse_iterator it = std::find_if(aAttribs.rbegin(), aAttribs.rend(), + [&nWhich, &nPos](const AttribsType::value_type& rxAttr) { + return rxAttr->Which() == nWhich && rxAttr->IsIn(nPos); }); + if (it != aAttribs.rend()) { const EditCharAttrib& rAttr = **it; - if (rAttr.Which() == nWhich && rAttr.IsIn(nPos)) - return &rAttr; + return &rAttr; } return nullptr; } @@ -2812,12 +2813,13 @@ EditCharAttrib* CharAttribList::FindAttrib( sal_uInt16 nWhich, sal_Int32 nPos ) { // Backwards, if one ends where the next starts. // => The starting one is the valid one ... - AttribsType::reverse_iterator it = aAttribs.rbegin(), itEnd = aAttribs.rend(); - for (; it != itEnd; ++it) + AttribsType::reverse_iterator it = std::find_if(aAttribs.rbegin(), aAttribs.rend(), + [&nWhich, &nPos](AttribsType::value_type& rxAttr) { + return rxAttr->Which() == nWhich && rxAttr->IsIn(nPos); }); + if (it != aAttribs.rend()) { EditCharAttrib& rAttr = **it; - if (rAttr.Which() == nWhich && rAttr.IsIn(nPos)) - return &rAttr; + return &rAttr; } return nullptr; } @@ -2836,14 +2838,9 @@ const EditCharAttrib* CharAttribList::FindNextAttrib( sal_uInt16 nWhich, sal_Int bool CharAttribList::HasAttrib( sal_Int32 nStartPos, sal_Int32 nEndPos ) const { - AttribsType::const_reverse_iterator it = aAttribs.rbegin(), itEnd = aAttribs.rend(); - for (; it != itEnd; ++it) - { - const EditCharAttrib& rAttr = **it; - if (rAttr.GetStart() < nEndPos && rAttr.GetEnd() > nStartPos) - return true; - } - return false; + return std::any_of(aAttribs.rbegin(), aAttribs.rend(), + [&nStartPos, &nEndPos](const AttribsType::value_type& rxAttr) { + return rxAttr->GetStart() < nEndPos && rxAttr->GetEnd() > nStartPos; }); } diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx index 81143ce33b5a..97d37b315586 100644 --- a/editeng/source/editeng/edtspell.cxx +++ b/editeng/source/editeng/edtspell.cxx @@ -401,27 +401,22 @@ void WrongList::ClearWrongs( size_t nStart, size_t nEnd, void WrongList::InsertWrong( size_t nStart, size_t nEnd ) { - WrongList::iterator nPos = maRanges.end(); - for (WrongList::iterator i = maRanges.begin(); i != maRanges.end(); ++i) + WrongList::iterator nPos = std::find_if(maRanges.begin(), maRanges.end(), + [&nStart](const editeng::MisspellRange& rRange) { return rRange.mnStart >= nStart; }); + + if (nPos != maRanges.end()) { - if (i->mnStart >= nStart) { - nPos = i; - { - // It can really only happen that the Wrong starts exactly here - // and runs along, but not that there are several ranges ... - // Exactly in the range is no one allowed to be, otherwise this - // Method can not be called! - SAL_WARN_IF((i->mnStart != nStart || i->mnEnd <= nEnd) && i->mnStart <= nEnd, "editeng", "InsertWrong: RangeMismatch!"); - if (i->mnStart == nStart && i->mnEnd > nEnd) - i->mnStart = nEnd + 1; - } - break; + // It can really only happen that the Wrong starts exactly here + // and runs along, but not that there are several ranges ... + // Exactly in the range is no one allowed to be, otherwise this + // Method can not be called! + SAL_WARN_IF((nPos->mnStart != nStart || nPos->mnEnd <= nEnd) && nPos->mnStart <= nEnd, "editeng", "InsertWrong: RangeMismatch!"); + if (nPos->mnStart == nStart && nPos->mnEnd > nEnd) + nPos->mnStart = nEnd + 1; } - } - - if (nPos != maRanges.end()) maRanges.insert(nPos, editeng::MisspellRange(nStart, nEnd)); + } else maRanges.emplace_back(nStart, nEnd); @@ -444,20 +439,12 @@ bool WrongList::operator==(const WrongList& rCompare) const { // check direct members if(GetInvalidStart() != rCompare.GetInvalidStart() - || GetInvalidEnd() != rCompare.GetInvalidEnd() - || maRanges.size() != rCompare.maRanges.size()) + || GetInvalidEnd() != rCompare.GetInvalidEnd()) return false; - WrongList::const_iterator rCB = rCompare.maRanges.begin(); - - for (auto const& rangeA : maRanges) - { - if(rangeA.mnStart != rCB->mnStart || rangeA.mnEnd != rCB->mnEnd) - return false; - ++rCB; - } - - return true; + return std::equal(maRanges.begin(), maRanges.end(), rCompare.maRanges.begin(), rCompare.maRanges.end(), + [](const editeng::MisspellRange& a, const editeng::MisspellRange& b) { + return a.mnStart == b.mnStart && a.mnEnd == b.mnEnd; }); } bool WrongList::empty() const @@ -506,10 +493,8 @@ bool WrongList::DbgIsBuggy() const bool bError = false; for (WrongList::const_iterator i = maRanges.begin(); !bError && (i != maRanges.end()); ++i) { - for (WrongList::const_iterator j = i + 1; !bError && (j != maRanges.end()); ++j) - { - bError = i->mnStart <= j->mnEnd && j->mnStart <= i->mnEnd; - } + bError = std::any_of(i + 1, maRanges.end(), [&i](const editeng::MisspellRange& rRange) { + return i->mnStart <= rRange.mnEnd && rRange.mnStart <= i->mnEnd; }); } return bError; } diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index bf235228a05d..2ac00ef7481c 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -652,9 +652,8 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel ) rOutput.WriteCharPtr( "}}" ); // 1xparentheses paragraphs, 1xparentheses RTF document rOutput.Flush(); - std::vector<SvxFontItem*>::iterator it; - for (it = aFontTable.begin(); it != aFontTable.end(); ++it) - delete *it; + for (auto& pItem : aFontTable) + delete pItem; return rOutput.GetError(); } @@ -2122,8 +2121,6 @@ void ImpEditEngine::ApplyChangedSentence(EditView const & rEditView, aSet.Put(SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId)); SetAttribs( *aCurrentOldPosition, aSet ); } - if(aCurrentNewPortion == rNewPortions.begin()) - break; } while(aCurrentNewPortion != rNewPortions.begin()); } @@ -2139,15 +2136,14 @@ void ImpEditEngine::ApplyChangedSentence(EditView const & rEditView, //delete the sentence completely ImpDeleteSelection( aAllSentence ); - svx::SpellPortions::const_iterator aCurrentNewPortion = rNewPortions.begin(); EditPaM aCurrentPaM = aAllSentence.Min(); - while(aCurrentNewPortion != rNewPortions.end()) + for(const auto& rCurrentNewPortion : rNewPortions) { //set the language attribute LanguageType eCurLanguage = GetLanguage( aCurrentPaM ); - if(eCurLanguage != aCurrentNewPortion->eLanguage) + if(eCurLanguage != rCurrentNewPortion.eLanguage) { - SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( aCurrentNewPortion->eLanguage ); + SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( rCurrentNewPortion.eLanguage ); sal_uInt16 nLangWhichId = EE_CHAR_LANGUAGE; switch(nScriptType) { @@ -2156,12 +2152,11 @@ void ImpEditEngine::ApplyChangedSentence(EditView const & rEditView, default: break; } SfxItemSet aSet( aEditDoc.GetItemPool(), {{nLangWhichId, nLangWhichId}}); - aSet.Put(SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId)); + aSet.Put(SvxLanguageItem(rCurrentNewPortion.eLanguage, nLangWhichId)); SetAttribs( aCurrentPaM, aSet ); } //insert the new string and set the cursor to the end of the inserted string - aCurrentPaM = ImpInsertText( aCurrentPaM , aCurrentNewPortion->sText ); - ++aCurrentNewPortion; + aCurrentPaM = ImpInsertText( aCurrentPaM , rCurrentNewPortion.sText ); } } UndoActionEnd(); diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index 19fb8fa0ec47..a7ec83d0837d 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -1292,16 +1292,12 @@ size_t Outliner::InsertView( OutlinerView* pView, size_t nIndex ) void Outliner::RemoveView( OutlinerView const * pView ) { - - for ( ViewList::iterator it = aViewList.begin(); it != aViewList.end(); ++it ) + ViewList::iterator it = std::find(aViewList.begin(), aViewList.end(), pView); + if (it != aViewList.end()) { - if ( *it == pView ) - { - pView->pEditView->HideCursor(); // HACK - pEditEngine->RemoveView( pView->pEditView.get() ); - aViewList.erase( it ); - break; - } + pView->pEditView->HideCursor(); // HACK + pEditEngine->RemoveView( pView->pEditView.get() ); + aViewList.erase( it ); } } diff --git a/extensions/source/dbpilots/gridwizard.cxx b/extensions/source/dbpilots/gridwizard.cxx index 617d2504f8d4..7a3ab8374979 100644 --- a/extensions/source/dbpilots/gridwizard.cxx +++ b/extensions/source/dbpilots/gridwizard.cxx @@ -178,20 +178,18 @@ namespace dbp { Reference< XNameAccess > xExistenceChecker(xColumnContainer.get()); - std::vector< OUString >::const_iterator pColumnServiceName = aColumnServiceNames.begin(); std::vector< OUString >::const_iterator pColumnLabelPostfix = aColumnLabelPostfixes.begin(); std::vector< OUString >::const_iterator pFormFieldName = aFormFieldNames.begin(); - std::vector< OUString >::const_iterator pColumnServiceNameEnd = aColumnServiceNames.end(); - for (;pColumnServiceName < pColumnServiceNameEnd; ++pColumnServiceName, ++pColumnLabelPostfix, ++pFormFieldName) + for (const auto& rColumnServiceName : aColumnServiceNames) { // create a (grid)column for the (resultset)column try { - Reference< XPropertySet > xColumn( xColumnFactory->createColumn(*pColumnServiceName), UNO_SET_THROW ); + Reference< XPropertySet > xColumn( xColumnFactory->createColumn(rColumnServiceName), UNO_SET_THROW ); Reference< XPropertySetInfo > xColumnPSI( xColumn->getPropertySetInfo(), UNO_SET_THROW ); - OUString sColumnName(*pColumnServiceName); + OUString sColumnName(rColumnServiceName); disambiguateName(xExistenceChecker, sColumnName); // the data field the column should be bound to @@ -213,6 +211,9 @@ namespace dbp "unexpected exception while creating the grid column for field " << *pFormFieldName ); } + + ++pColumnLabelPostfix; + ++pFormFieldName; } } } diff --git a/extensions/source/inc/componentmodule.cxx b/extensions/source/inc/componentmodule.cxx index 92f7bb45cc1c..18f589c77ccc 100644 --- a/extensions/source/inc/componentmodule.cxx +++ b/extensions/source/inc/componentmodule.cxx @@ -91,17 +91,14 @@ namespace compmodule && (s_pImplementationNames->size() == s_pFactoryFunctionPointers->size()), "OModule::revokeComponent : inconsistent state !"); - sal_Int32 nLen = s_pImplementationNames->size(); - for (sal_Int32 i=0; i<nLen; ++i) + auto it = std::find(s_pImplementationNames->begin(), s_pImplementationNames->end(), _rImplementationName); + if (it != s_pImplementationNames->end()) { - if ((*s_pImplementationNames)[i] == _rImplementationName) - { - s_pImplementationNames->erase(s_pImplementationNames->begin() + i); - s_pSupportedServices->erase(s_pSupportedServices->begin() + i); - s_pCreationFunctionPointers->erase(s_pCreationFunctionPointers->begin() + i); - s_pFactoryFunctionPointers->erase(s_pFactoryFunctionPointers->begin() + i); - break; - } + sal_Int32 i = static_cast<sal_Int32>(std::distance(s_pImplementationNames->begin(), it)); + s_pImplementationNames->erase(it); + s_pSupportedServices->erase(s_pSupportedServices->begin() + i); + s_pCreationFunctionPointers->erase(s_pCreationFunctionPointers->begin() + i); + s_pFactoryFunctionPointers->erase(s_pFactoryFunctionPointers->begin() + i); } if (s_pImplementationNames->empty()) diff --git a/extensions/source/propctrlr/browserlistbox.cxx b/extensions/source/propctrlr/browserlistbox.cxx index dcac53bdf98a..7a3b226b2434 100644 --- a/extensions/source/propctrlr/browserlistbox.cxx +++ b/extensions/source/propctrlr/browserlistbox.cxx @@ -621,9 +621,8 @@ namespace pcr void OBrowserListBox::SetPropertyValue(const OUString& _rEntryName, const Any& _rValue, bool _bUnknownValue ) { - ListBoxLines::iterator line = m_aLines.begin(); - for ( ; line != m_aLines.end() && ( line->aName != _rEntryName ); ++line ) - ; + ListBoxLines::iterator line = std::find_if(m_aLines.begin(), m_aLines.end(), + [&_rEntryName](const ListBoxLine& rLine) { return rLine.aName == _rEntryName; }); if ( line != m_aLines.end() ) { @@ -658,9 +657,8 @@ namespace pcr bool OBrowserListBox::impl_getBrowserLineForName( const OUString& _rEntryName, BrowserLinePointer& _out_rpLine ) const { - ListBoxLines::const_iterator line = m_aLines.begin(); - for ( ; line != m_aLines.end() && ( line->aName != _rEntryName ); ++line ) - ; + ListBoxLines::const_iterator line = std::find_if(m_aLines.begin(), m_aLines.end(), + [&_rEntryName](const ListBoxLine& rLine) { return rLine.aName == _rEntryName; }); if ( line != m_aLines.end() ) _out_rpLine = line->pLine; @@ -1023,14 +1021,13 @@ namespace pcr bool OBrowserListBox::RemoveEntry( const OUString& _rName ) { - ListBoxLines::size_type nPos = 0; - ListBoxLines::iterator it = m_aLines.begin(); - for ( ; it != m_aLines.end() && ( it->aName != _rName ); ++it, ++nPos ) - ; + ListBoxLines::iterator it = std::find_if(m_aLines.begin(), m_aLines.end(), + [&_rName](const ListBoxLine& rLine) { return rLine.aName == _rName; }); if ( it == m_aLines.end() ) return false; + ListBoxLines::size_type nPos = static_cast<ListBoxLines::size_type>(std::distance(m_aLines.begin(), it)); m_aLines.erase( it ); m_aOutOfDateLines.erase( m_aLines.size() ); diff --git a/extensions/source/propctrlr/buttonnavigationhandler.cxx b/extensions/source/propctrlr/buttonnavigationhandler.cxx index 8ffe59cc144d..5488d9b5428b 100644 --- a/extensions/source/propctrlr/buttonnavigationhandler.cxx +++ b/extensions/source/propctrlr/buttonnavigationhandler.cxx @@ -185,7 +185,7 @@ namespace pcr if ( aProperties.empty() ) return Sequence< Property >(); - return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); + return comphelper::containerToSequence(aProperties); } diff --git a/extensions/source/propctrlr/cellbindinghandler.cxx b/extensions/source/propctrlr/cellbindinghandler.cxx index ea8f9924e1bc..5df2611537b1 100644 --- a/extensions/source/propctrlr/cellbindinghandler.cxx +++ b/extensions/source/propctrlr/cellbindinghandler.cxx @@ -477,7 +477,7 @@ namespace pcr if ( aProperties.empty() ) return Sequence< Property >(); - return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); + return comphelper::containerToSequence(aProperties); } diff --git a/extensions/source/propctrlr/editpropertyhandler.cxx b/extensions/source/propctrlr/editpropertyhandler.cxx index 643e43870640..a1016e2075cd 100644 --- a/extensions/source/propctrlr/editpropertyhandler.cxx +++ b/extensions/source/propctrlr/editpropertyhandler.cxx @@ -222,7 +222,7 @@ namespace pcr if ( aProperties.empty() ) return Sequence< Property >(); - return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); + return comphelper::containerToSequence(aProperties); } @@ -242,7 +242,7 @@ namespace pcr } if ( aSuperseded.empty() ) return Sequence< OUString >(); - return Sequence< OUString >( &(*aSuperseded.begin()), aSuperseded.size() ); + return comphelper::containerToSequence(aSuperseded); } @@ -253,7 +253,7 @@ namespace pcr if ( implHaveTextTypeProperty() ) aInterestingActuatingProps.push_back( PROPERTY_TEXTTYPE ); aInterestingActuatingProps.push_back( PROPERTY_MULTILINE ); - return Sequence< OUString >( &(*aInterestingActuatingProps.begin()), aInterestingActuatingProps.size() ); + return comphelper::containerToSequence(aInterestingActuatingProps); } diff --git a/extensions/source/propctrlr/eformspropertyhandler.cxx b/extensions/source/propctrlr/eformspropertyhandler.cxx index 328c8bf025b7..d074a7e64fed 100644 --- a/extensions/source/propctrlr/eformspropertyhandler.cxx +++ b/extensions/source/propctrlr/eformspropertyhandler.cxx @@ -310,7 +310,7 @@ namespace pcr if ( aProperties.empty() ) return Sequence< Property >(); - return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); + return comphelper::containerToSequence(aProperties); } @@ -392,7 +392,7 @@ namespace pcr std::vector< OUString > aInterestedInActuations( 2 ); aInterestedInActuations[ 0 ] = PROPERTY_XML_DATA_MODEL; aInterestedInActuations[ 1 ] = PROPERTY_BINDING_NAME; - return Sequence< OUString >( &(*aInterestedInActuations.begin()), aInterestedInActuations.size() ); + return comphelper::containerToSequence(aInterestedInActuations); } diff --git a/extensions/source/propctrlr/formcomponenthandler.cxx b/extensions/source/propctrlr/formcomponenthandler.cxx index 7dfa51afabcf..78719cce93d6 100644 --- a/extensions/source/propctrlr/formcomponenthandler.cxx +++ b/extensions/source/propctrlr/formcomponenthandler.cxx @@ -858,7 +858,7 @@ namespace pcr if ( aProperties.empty() ) return Sequence< Property >(); - return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); + return comphelper::containerToSequence(aProperties); } Sequence< OUString > SAL_CALL FormComponentPropertyHandler::getSupersededProperties( ) @@ -892,7 +892,7 @@ namespace pcr aInterestingProperties.push_back( PROPERTY_FORMATKEY ); aInterestingProperties.push_back( PROPERTY_EMPTY_IS_NULL ); aInterestingProperties.push_back( PROPERTY_TOGGLE ); - return Sequence< OUString >( &(*aInterestingProperties.begin()), aInterestingProperties.size() ); + return comphelper::containerToSequence(aInterestingProperties); } LineDescriptor SAL_CALL FormComponentPropertyHandler::describePropertyLine( const OUString& _rPropertyName, diff --git a/extensions/source/propctrlr/formgeometryhandler.cxx b/extensions/source/propctrlr/formgeometryhandler.cxx index 1edeacbf230b..2c81fc76e4bb 100644 --- a/extensions/source/propctrlr/formgeometryhandler.cxx +++ b/extensions/source/propctrlr/formgeometryhandler.cxx @@ -555,7 +555,7 @@ namespace pcr if ( impl_haveSheetAnchorType_nothrow() ) addInt32PropertyDescription( aProperties, PROPERTY_SHEET_ANCHOR_TYPE ); - return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); + return comphelper::containerToSequence(aProperties); } diff --git a/extensions/source/propctrlr/propcontroller.cxx b/extensions/source/propctrlr/propcontroller.cxx index 062df51c042c..9f6fa9fcbaed 100644 --- a/extensions/source/propctrlr/propcontroller.cxx +++ b/extensions/source/propctrlr/propcontroller.cxx @@ -596,17 +596,10 @@ namespace pcr m_pView = nullptr; } - for ( InterfaceArray::iterator loop = m_aInspectedObjects.begin(); - loop != m_aInspectedObjects.end(); - ++loop - ) - { - if ( *loop == _rSource.Source ) - { - m_aInspectedObjects.erase( loop ); - break; - } - } + auto it = std::find_if(m_aInspectedObjects.begin(), m_aInspectedObjects.end(), + [&_rSource](const InterfaceArray::value_type& rxObj) { return rxObj == _rSource.Source; }); + if (it != m_aInspectedObjects.end()) + m_aInspectedObjects.erase(it); } @@ -1462,10 +1455,8 @@ namespace pcr bool OPropertyBrowserController::impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty ) { - OrderedPropertyMap::const_iterator search = m_aProperties.begin(); - for ( ; search != m_aProperties.end(); ++search ) - if ( search->second.Name == _rName ) - break; + OrderedPropertyMap::const_iterator search = std::find_if(m_aProperties.begin(), m_aProperties.end(), + [&_rName](const OrderedPropertyMap::value_type& rEntry) { return rEntry.second.Name == _rName; }); if ( _pProperty ) *_pProperty = search; return ( search != m_aProperties.end() ); diff --git a/extensions/source/propctrlr/propertyeditor.cxx b/extensions/source/propctrlr/propertyeditor.cxx index f960ee3232ad..40c88d82cc52 100644 --- a/extensions/source/propctrlr/propertyeditor.cxx +++ b/extensions/source/propctrlr/propertyeditor.cxx @@ -97,11 +97,8 @@ namespace pcr m_aPropertyPageIds.swap( aEmpty ); } - while ( !m_aHiddenPages.empty() ) - { - m_aHiddenPages.begin()->second.pPage.disposeAndClear(); - m_aHiddenPages.erase( m_aHiddenPages.begin() ); - } + for (auto& rEntry : m_aHiddenPages) + rEntry.second.pPage.disposeAndClear(); m_aHiddenPages.clear(); } diff --git a/extensions/source/propctrlr/submissionhandler.cxx b/extensions/source/propctrlr/submissionhandler.cxx index 191c17451dbd..d525ad5a821d 100644 --- a/extensions/source/propctrlr/submissionhandler.cxx +++ b/extensions/source/propctrlr/submissionhandler.cxx @@ -269,7 +269,7 @@ namespace pcr } if ( aProperties.empty() ) return Sequence< Property >(); - return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); + return comphelper::containerToSequence(aProperties); } diff --git a/extensions/source/update/check/updatecheck.cxx b/extensions/source/update/check/updatecheck.cxx index dd07258df128..47ef6e18093e 100644 --- a/extensions/source/update/check/updatecheck.cxx +++ b/extensions/source/update/check/updatecheck.cxx @@ -1225,14 +1225,8 @@ UpdateCheck::setUpdateInfo(const UpdateInfo& aInfo) OSL_ASSERT(DISABLED == m_eState || CHECK_SCHEDULED == m_eState); // Ignore leading non direct download if we get direct ones - std::vector< DownloadSource >::iterator iter = m_aUpdateInfo.Sources.begin(); - while( iter != m_aUpdateInfo.Sources.end() ) - { - if( iter->IsDirect ) - break; - - ++iter; - } + std::vector< DownloadSource >::iterator iter = std::find_if(m_aUpdateInfo.Sources.begin(), m_aUpdateInfo.Sources.end(), + [](const DownloadSource& rSource) { return rSource.IsDirect; }); if( (iter != m_aUpdateInfo.Sources.begin()) && (iter != m_aUpdateInfo.Sources.end()) && |