diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-01-27 16:56:41 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-01-29 08:30:13 +0100 |
commit | 474fa67c37b6c0b5e4ff12981c76a3b0bc860e95 (patch) | |
tree | caaf97060358e562fa1a2b27f6d3c27bfb054a90 /sc | |
parent | 46195e2a579a373287a99d03cc06c38f557880c0 (diff) |
Simplify containers iterations in sc/source/filter/[d-e]*
Use range-based loop or replace with STL functions
Change-Id: I7be6568641e154e74ff7bde812da9a8e67790a7f
Reviewed-on: https://gerrit.libreoffice.org/66972
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
38 files changed, 496 insertions, 562 deletions
diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx index ed71c759b184..4040f4adb67e 100644 --- a/sc/source/filter/dif/difimp.cxx +++ b/sc/source/filter/dif/difimp.cxx @@ -650,14 +650,14 @@ void DifColumn::Apply( ScDocument& rDoc, const SCCOL nCol, const SCTAB nTab ) ScPatternAttr aAttr( rDoc.GetPool() ); SfxItemSet &rItemSet = aAttr.GetItemSet(); - for (std::vector<ENTRY>::const_iterator it = maEntries.begin(); it != maEntries.end(); ++it) + for (const auto& rEntry : maEntries) { - OSL_ENSURE( it->nNumFormat > 0, + OSL_ENSURE( rEntry.nNumFormat > 0, "+DifColumn::Apply(): Number format must not be 0!" ); - rItemSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, it->nNumFormat ) ); + rItemSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, rEntry.nNumFormat ) ); - rDoc.ApplyPatternAreaTab( nCol, it->nStart, nCol, it->nEnd, nTab, aAttr ); + rDoc.ApplyPatternAreaTab( nCol, rEntry.nStart, nCol, rEntry.nEnd, nTab, aAttr ); rItemSet.ClearItem(); } diff --git a/sc/source/filter/excel/colrowst.cxx b/sc/source/filter/excel/colrowst.cxx index 32a67bc4f0be..5640335f08b8 100644 --- a/sc/source/filter/excel/colrowst.cxx +++ b/sc/source/filter/excel/colrowst.cxx @@ -217,13 +217,10 @@ void XclImpColRowSettings::Convert( SCTAB nScTab ) if (!maRowHeights.is_tree_valid()) return; - ColRowFlagsType::const_iterator itrFlags = maRowFlags.begin(), itrFlagsEnd = maRowFlags.end(); SCROW nPrevRow = -1; ExcColRowFlags nPrevFlags = ExcColRowFlags::NONE; - for (; itrFlags != itrFlagsEnd; ++itrFlags) + for (const auto& [nRow, nFlags] : maRowFlags) { - SCROW nRow = itrFlags->first; - ExcColRowFlags nFlags = itrFlags->second; if (nPrevRow >= 0) { sal_uInt16 nHeight = 0; @@ -308,11 +305,8 @@ void XclImpColRowSettings::ConvertHiddenFlags( SCTAB nScTab ) SCROW nPrevRow = -1; bool bPrevHidden = false; - RowHiddenType::const_iterator itr = maHiddenRows.begin(), itrEnd = maHiddenRows.end(); - for (; itr != itrEnd; ++itr) + for (const auto& [nRow, bHidden] : maHiddenRows) { - SCROW nRow = itr->first; - bool bHidden = itr->second; if (nPrevRow >= 0) { if (bPrevHidden) diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx index 5c0f4971eaab..c036b860413d 100644 --- a/sc/source/filter/excel/excdoc.cxx +++ b/sc/source/filter/excel/excdoc.cxx @@ -422,12 +422,12 @@ void ExcTable::FillAsTableBinary( SCTAB nCodeNameIdx ) //export cell notes std::vector<sc::NoteEntry> aNotes; rDoc.GetAllNoteEntries(aNotes); - for (std::vector<sc::NoteEntry>::const_iterator it = aNotes.begin(), itEnd = aNotes.end(); it != itEnd; ++it) + for (const auto& rNote : aNotes) { - if (it->maPos.Tab() != mnScTab) + if (rNote.maPos.Tab() != mnScTab) continue; - mxNoteList->AppendNewRecord(new XclExpNote(GetRoot(), it->maPos, it->mpNote, OUString())); + mxNoteList->AppendNewRecord(new XclExpNote(GetRoot(), rNote.maPos, rNote.mpNote, OUString())); } // WSBOOL needs data from page settings, create it here, add it later @@ -510,10 +510,9 @@ void ExcTable::FillAsTableBinary( SCTAB nCodeNameIdx ) if (pTabProtect) { const ::std::vector<ScEnhancedProtection>& rProts( pTabProtect->getEnhancedProtection()); - for (::std::vector<ScEnhancedProtection>::const_iterator it( rProts.begin()), itEnd( rProts.end()); - it != itEnd; ++it) + for (const auto& rProt : rProts) { - Add( new XclExpSheetEnhancedProtection( GetRoot(), *it)); + Add( new XclExpSheetEnhancedProtection( GetRoot(), rProt)); } } @@ -564,12 +563,12 @@ void ExcTable::FillAsTableXml() //export cell notes std::vector<sc::NoteEntry> aNotes; rDoc.GetAllNoteEntries(aNotes); - for (std::vector<sc::NoteEntry>::const_iterator it = aNotes.begin(), itEnd = aNotes.end(); it != itEnd; ++it) + for (const auto& rNote : aNotes) { - if (it->maPos.Tab() != mnScTab) + if (rNote.maPos.Tab() != mnScTab) continue; - mxNoteList->AppendNewRecord(new XclExpNote(GetRoot(), it->maPos, it->mpNote, OUString())); + mxNoteList->AppendNewRecord(new XclExpNote(GetRoot(), rNote.maPos, rNote.mpNote, OUString())); } // WSBOOL needs data from page settings, create it here, add it later diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx index 1ddf17d08f85..0bfe9cf4a427 100644 --- a/sc/source/filter/excel/excrecds.cxx +++ b/sc/source/filter/excel/excrecds.cxx @@ -476,24 +476,23 @@ void XclExpSheetProtection::SaveXml( XclExpXmlStream& rStrm ) if (!rProts.empty()) { rWorksheet->startElement( XML_protectedRanges, FSEND); - for (::std::vector<ScEnhancedProtection>::const_iterator it( rProts.begin()), end( rProts.end()); - it != end; ++it) + for (const auto& rProt : rProts) { - SAL_WARN_IF( (*it).maSecurityDescriptorXML.isEmpty() && !(*it).maSecurityDescriptor.empty(), + SAL_WARN_IF( rProt.maSecurityDescriptorXML.isEmpty() && !rProt.maSecurityDescriptor.empty(), "sc.filter", "XclExpSheetProtection::SaveXml: losing BIFF security descriptor"); rWorksheet->singleElement( XML_protectedRange, - XML_name, (*it).maTitle.isEmpty() ? nullptr : XclXmlUtils::ToOString( (*it).maTitle).getStr(), - XML_securityDescriptor, (*it).maSecurityDescriptorXML.isEmpty() ? nullptr : XclXmlUtils::ToOString( (*it).maSecurityDescriptorXML).getStr(), + XML_name, rProt.maTitle.isEmpty() ? nullptr : XclXmlUtils::ToOString( rProt.maTitle).getStr(), + XML_securityDescriptor, rProt.maSecurityDescriptorXML.isEmpty() ? nullptr : XclXmlUtils::ToOString( rProt.maSecurityDescriptorXML).getStr(), /* XXX 'password' is not part of OOXML, but Excel2013 * writes it if loaded from BIFF, in which case * 'algorithmName', 'hashValue', 'saltValue' and * 'spinCount' are absent; so do we if it was present. */ - XML_password, (*it).mnPasswordVerifier ? OString::number( (*it).mnPasswordVerifier, 16).getStr() : nullptr, - XML_algorithmName, (*it).maPasswordHash.maAlgorithmName.isEmpty() ? nullptr : XclXmlUtils::ToOString( (*it).maPasswordHash.maAlgorithmName).getStr(), - XML_hashValue, (*it).maPasswordHash.maHashValue.isEmpty() ? nullptr : XclXmlUtils::ToOString( (*it).maPasswordHash.maHashValue).getStr(), - XML_saltValue, (*it).maPasswordHash.maSaltValue.isEmpty() ? nullptr : XclXmlUtils::ToOString( (*it).maPasswordHash.maSaltValue).getStr(), - XML_spinCount, (*it).maPasswordHash.mnSpinCount ? OString::number( (*it).maPasswordHash.mnSpinCount).getStr() : nullptr, - XML_sqref, (*it).maRangeList.is() ? XclXmlUtils::ToOString( *(*it).maRangeList).getStr() : nullptr, + XML_password, rProt.mnPasswordVerifier ? OString::number( rProt.mnPasswordVerifier, 16).getStr() : nullptr, + XML_algorithmName, rProt.maPasswordHash.maAlgorithmName.isEmpty() ? nullptr : XclXmlUtils::ToOString( rProt.maPasswordHash.maAlgorithmName).getStr(), + XML_hashValue, rProt.maPasswordHash.maHashValue.isEmpty() ? nullptr : XclXmlUtils::ToOString( rProt.maPasswordHash.maHashValue).getStr(), + XML_saltValue, rProt.maPasswordHash.maSaltValue.isEmpty() ? nullptr : XclXmlUtils::ToOString( rProt.maPasswordHash.maSaltValue).getStr(), + XML_spinCount, rProt.maPasswordHash.mnSpinCount ? OString::number( rProt.maPasswordHash.mnSpinCount).getStr() : nullptr, + XML_sqref, rProt.maRangeList.is() ? XclXmlUtils::ToOString( *rProt.maRangeList).getStr() : nullptr, FSEND); } rWorksheet->endElement( XML_protectedRanges); @@ -779,9 +778,8 @@ void XclExpAutofilter::AddMultiValueEntry( const ScQueryEntry& rEntry ) { meType = MultiValue; const ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems(); - ScQueryEntry::QueryItemsType::const_iterator itr = rItems.begin(), itrEnd = rItems.end(); - for (; itr != itrEnd; ++itr) - maMultiValues.push_back(itr->maString.getString()); + for (const auto& rItem : rItems) + maMultiValues.push_back(rItem.maString.getString()); } void XclExpAutofilter::WriteBody( XclExpStream& rStrm ) @@ -833,10 +831,9 @@ void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm ) case MultiValue: { rWorksheet->startElement(XML_filters, FSEND); - std::vector<OUString>::const_iterator itr = maMultiValues.begin(), itrEnd = maMultiValues.end(); - for (; itr != itrEnd; ++itr) + for (const auto& rMultiValue : maMultiValues) { - OString aStr = OUStringToOString(*itr, RTL_TEXTENCODING_UTF8); + OString aStr = OUStringToOString(rMultiValue, RTL_TEXTENCODING_UTF8); const char* pz = aStr.getStr(); rWorksheet->singleElement(XML_filter, XML_val, pz, FSEND); } diff --git a/sc/source/filter/excel/exctools.cxx b/sc/source/filter/excel/exctools.cxx index 445a1ff7578c..8456c0be5ff4 100644 --- a/sc/source/filter/excel/exctools.cxx +++ b/sc/source/filter/excel/exctools.cxx @@ -93,17 +93,14 @@ void XclImpOutlineBuffer::MakeScOutline() ::std::vector<SCSIZE> aOutlineStack; aOutlineStack.reserve(mnMaxLevel); - OutlineLevels::const_iterator itr = maLevels.begin(), itrEnd = maLevels.end(); - for (; itr != itrEnd; ++itr) + for (const auto& [nPos, nLevel] : maLevels) { - SCSIZE nPos = itr->first; if (nPos >= mnEndPos) { // Don't go beyond the max allowed position. OSL_ENSURE(aOutlineStack.empty(), "XclImpOutlineBuffer::MakeScOutline: outline stack not empty but expected to be."); break; } - sal_uInt8 nLevel = itr->second; sal_uInt8 nCurLevel = static_cast<sal_uInt8>(aOutlineStack.size()); if (nLevel > nCurLevel) { @@ -196,9 +193,8 @@ ExcScenario::ExcScenario( XclImpStream& rIn, const RootData& rR ) n--; } - std::vector<ExcScenarioCell>::iterator iter; - for (iter = aEntries.begin(); iter != aEntries.end(); ++iter) - iter->SetValue(rIn.ReadUniString()); + for (auto& rEntry : aEntries) + rEntry.SetValue(rIn.ReadUniString()); } void ExcScenario::Apply( const XclImpRoot& rRoot, const bool bLast ) @@ -217,12 +213,11 @@ void ExcScenario::Apply( const XclImpRoot& rRoot, const bool bLast ) /* | ScScenarioFlags::ShowFrame*/ r.SetScenarioData( nNewTab, aComment, COL_LIGHTGRAY, nFlags); - std::vector<ExcScenarioCell>::const_iterator iter; - for (iter = aEntries.begin(); iter != aEntries.end(); ++iter) + for (const auto& rEntry : aEntries) { - sal_uInt16 nCol = iter->nCol; - sal_uInt16 nRow = iter->nRow; - OUString aVal = iter->GetValue(); + sal_uInt16 nCol = rEntry.nCol; + sal_uInt16 nRow = rEntry.nRow; + OUString aVal = rEntry.GetValue(); r.ApplyFlagsTab( nCol, nRow, nCol, nRow, nNewTab, ScMF::Scenario ); diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx index 4ebb82486889..1bebd26143bf 100644 --- a/sc/source/filter/excel/impop.cxx +++ b/sc/source/filter/excel/impop.cxx @@ -1244,8 +1244,8 @@ void ImportExcel::PostDocLoad() pStyleSheet->GetItemSet().Put( SfxUInt16Item( ATTR_PAGE_FIRSTPAGENO, 0 ) ); // outlines for all sheets, sets hidden rows and columns (#i11776# after filtered ranges) - for (XclImpOutlineListBuffer::iterator itBuffer = pOutlineListBuffer->begin(); itBuffer != pOutlineListBuffer->end(); ++itBuffer) - (*itBuffer)->Convert(); + for (auto& rxBuffer : *pOutlineListBuffer) + rxBuffer->Convert(); // document view settings (before visible OLE area) GetDocViewSettings().Finalize(); diff --git a/sc/source/filter/excel/read.cxx b/sc/source/filter/excel/read.cxx index c718b211af7a..1cbaa761cac8 100644 --- a/sc/source/filter/excel/read.cxx +++ b/sc/source/filter/excel/read.cxx @@ -1250,8 +1250,7 @@ ErrCode ImportExcel8::Read() { // In some strange circumstances a the codename might be missing // # Create any missing Sheet CodeNames - std::vector < SCTAB >::iterator it_end = nTabsWithNoCodeName.end(); - for ( std::vector < SCTAB >::iterator it = nTabsWithNoCodeName.begin(); it != it_end; ++it ) + for ( const auto& rTab : nTabsWithNoCodeName ) { SCTAB nTab = 1; while ( true ) @@ -1260,19 +1259,11 @@ ErrCode ImportExcel8::Read() aBuf.append("Sheet"); aBuf.append(static_cast<sal_Int32>(nTab++)); OUString sTmpName = aBuf.makeStringAndClear(); - std::vector<OUString>::iterator codeName_It = aCodeNames.begin(); - std::vector<OUString>::iterator codeName_It_end = aCodeNames.end(); - // search for codename - for ( ; codeName_It != codeName_It_end; ++codeName_It ) - { - if ( *codeName_It == sTmpName ) - break; - } - if ( codeName_It == codeName_It_end ) // generated codename not found + if ( std::find(aCodeNames.begin(), aCodeNames.end(), sTmpName) == aCodeNames.end() ) // generated codename not found { // Set new codename - GetDoc().SetCodeName( *it, sTmpName ); + GetDoc().SetCodeName( rTab, sTmpName ); // Record newly used codename aCodeNames.push_back(sTmpName); break; diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx index 83c1d2ef2244..017cde1e6093 100644 --- a/sc/source/filter/excel/xechart.cxx +++ b/sc/source/filter/excel/xechart.cxx @@ -264,10 +264,10 @@ void XclExpChRootData::InitializeFutureRecBlock( XclExpStream& rStrm ) rStrm.EndRecord(); } // write all unwritten CHFRBLOCKBEGIN records - for( XclChFrBlockVector::const_iterator aIt = maUnwrittenFrBlocks.begin(), aEnd = maUnwrittenFrBlocks.end(); aIt != aEnd; ++aIt ) + for( const auto& rUnwrittenFrBlock : maUnwrittenFrBlocks ) { - OSL_ENSURE( aIt->mnType != EXC_CHFRBLOCK_TYPE_UNKNOWN, "XclExpChRootData::InitializeFutureRecBlock - unknown future record block type" ); - lclWriteChFrBlockRecord( rStrm, *aIt, true ); + OSL_ENSURE( rUnwrittenFrBlock.mnType != EXC_CHFRBLOCK_TYPE_UNKNOWN, "XclExpChRootData::InitializeFutureRecBlock - unknown future record block type" ); + lclWriteChFrBlockRecord( rStrm, rUnwrittenFrBlock, true ); } // move all record infos to vector of written blocks maWrittenFrBlocks.insert( maWrittenFrBlocks.end(), maUnwrittenFrBlocks.begin(), maUnwrittenFrBlocks.end() ); @@ -2481,13 +2481,13 @@ void XclExpChTypeGroup::ConvertSeries( ::set_flag( maData.mnFlags, EXC_CHTYPEGROUP_VARIEDCOLORS, aSeriesProp.GetBoolProperty( EXC_CHPROP_VARYCOLORSBY ) ); // process all series - for( XDataSeriesVec::const_iterator aIt = aSeriesVec.begin(), aEnd = aSeriesVec.end(); aIt != aEnd; ++aIt ) + for( const auto& rxSeries : aSeriesVec ) { // create Excel series object, stock charts need special processing if( maTypeInfo.meTypeId == EXC_CHTYPEID_STOCK ) - CreateAllStockSeries( xChartType, *aIt ); + CreateAllStockSeries( xChartType, rxSeries ); else - CreateDataSeries( xDiagram, *aIt ); + CreateDataSeries( xDiagram, rxSeries ); } } } diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx index b58231634526..84663591f51b 100644 --- a/sc/source/filter/excel/xecontent.cxx +++ b/sc/source/filter/excel/xecontent.cxx @@ -1421,14 +1421,13 @@ XclExpColorScale::XclExpColorScale( const XclExpRoot& rRoot, const ScColorScaleF { const ScRange & rRange = rFormat.GetRange().front(); ScAddress aAddr = rRange.aStart; - for(ScColorScaleEntries::const_iterator itr = rFormat.begin(); - itr != rFormat.end(); ++itr) + for(const auto& rxColorScaleEntry : rFormat) { // exact position is not important, we allow only absolute refs - XclExpCfvoList::RecordRefType xCfvo( new XclExpCfvo( GetRoot(), *itr[0], aAddr ) ); + XclExpCfvoList::RecordRefType xCfvo( new XclExpCfvo( GetRoot(), *rxColorScaleEntry, aAddr ) ); maCfvoList.AppendRecord( xCfvo ); - XclExpColScaleColList::RecordRefType xClo( new XclExpColScaleCol( GetRoot(), itr[0]->GetColor() ) ); + XclExpColScaleColList::RecordRefType xClo( new XclExpColScaleCol( GetRoot(), rxColorScaleEntry->GetColor() ) ); maColList.AppendRecord( xClo ); } } @@ -1553,10 +1552,9 @@ XclExpCondFormatBuffer::XclExpCondFormatBuffer( const XclExpRoot& rRoot, const X if( const ScConditionalFormatList* pCondFmtList = GetDoc().GetCondFormList(GetCurrScTab()) ) { sal_Int32 nIndex = 0; - for( ScConditionalFormatList::const_iterator itr = pCondFmtList->begin(); - itr != pCondFmtList->end(); ++itr) + for( const auto& rxCondFmt : *pCondFmtList) { - XclExpCondfmtList::RecordRefType xCondfmtRec( new XclExpCondfmt( GetRoot(), **itr, xExtLst, nIndex )); + XclExpCondfmtList::RecordRefType xCondfmtRec( new XclExpCondfmt( GetRoot(), *rxCondFmt, xExtLst, nIndex )); if( xCondfmtRec->IsValidForXml() ) maCondfmtList.AppendRecord( xCondfmtRec ); } diff --git a/sc/source/filter/excel/xedbdata.cxx b/sc/source/filter/excel/xedbdata.cxx index 576476e89e80..909e2ed586f8 100644 --- a/sc/source/filter/excel/xedbdata.cxx +++ b/sc/source/filter/excel/xedbdata.cxx @@ -113,9 +113,9 @@ void XclExpTablesManager::Initialize() return; sal_Int32 nTableId = 0; - for (ScDBCollection::NamedDBs::iterator itDB(rDBs.begin()); itDB != rDBs.end(); ++itDB) + for (const auto& rxDB : rDBs) { - ScDBData* pDBData = itDB->get(); + ScDBData* pDBData = rxDB.get(); pDBData->RefreshTableColumnNames( &rDoc); // currently not in sync, so refresh ScRange aRange( ScAddress::UNINITIALIZED); pDBData->GetArea( aRange); diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx index 01dcdbbfd347..5c53e0588693 100644 --- a/sc/source/filter/excel/xeescher.cxx +++ b/sc/source/filter/excel/xeescher.cxx @@ -982,9 +982,9 @@ void XclExpTbxControlObj::WriteSubRecs( XclExpStream& rStrm ) if( nEntryCount ) { ScfUInt8Vec aSelEx( nEntryCount, 0 ); - for( ScfInt16Vec::const_iterator aIt = maMultiSel.begin(), aEnd = maMultiSel.end(); aIt != aEnd; ++aIt ) - if( *aIt < nEntryCount ) - aSelEx[ *aIt ] = 1; + for( const auto& rItem : maMultiSel ) + if( rItem < nEntryCount ) + aSelEx[ rItem ] = 1; rStrm.Write( &aSelEx[ 0 ], aSelEx.size() ); } } @@ -1445,10 +1445,10 @@ void XclExpComments::SaveXml( XclExpXmlStream& rStrm ) aAuthors.insert( XclXmlUtils::ToOUString( mrNotes.GetRecord( i )->GetAuthor() ) ); } - for( Authors::const_iterator b = aAuthors.begin(), e = aAuthors.end(); b != e; ++b ) + for( const auto& rAuthor : aAuthors ) { rComments->startElement( XML_author, FSEND ); - rComments->writeEscaped( *b ); + rComments->writeEscaped( rAuthor ); rComments->endElement( XML_author ); } diff --git a/sc/source/filter/excel/xeextlst.cxx b/sc/source/filter/excel/xeextlst.cxx index 840aa99d5a85..42aecd99b1f0 100644 --- a/sc/source/filter/excel/xeextlst.cxx +++ b/sc/source/filter/excel/xeextlst.cxx @@ -209,9 +209,9 @@ XclExpExtIconSet::XclExpExtIconSet(const XclExpRoot& rRoot, const ScIconSetForma if (mbCustom) { - for (auto itr = rData.maCustomVector.begin(); itr != rData.maCustomVector.end(); ++itr) + for (const auto& rItem : rData.maCustomVector) { - maCustom.AppendNewRecord(new XclExpExtIcon(*this, *itr)); + maCustom.AppendNewRecord(new XclExpExtIcon(*this, rItem)); } } } @@ -288,9 +288,9 @@ XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot maRange(rRange) { ScAddress aAddr = maRange.front().aStart; - for (auto itr = rData.begin(), itrEnd = rData.end(); itr != itrEnd; ++itr) + for (const auto& rItem : rData) { - const ScFormatEntry* pEntry = itr->pEntry; + const ScFormatEntry* pEntry = rItem.pEntry; switch (pEntry->GetType()) { case ScFormatEntry::Type::Iconset: @@ -315,12 +315,12 @@ XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot if (bNeedsExt) { - maCfRules.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry, aAddr, itr->aGUID, itr->nPriority)); + maCfRules.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry, aAddr, rItem.aGUID, rItem.nPriority)); } } break; case ScFormatEntry::Type::Databar: - maCfRules.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry, aAddr, itr->aGUID, itr->nPriority)); + maCfRules.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry, aAddr, rItem.aGUID, rItem.nPriority)); break; default: break; diff --git a/sc/source/filter/excel/xeformula.cxx b/sc/source/filter/excel/xeformula.cxx index 5c337fd3ddae..f695a2d7295a 100644 --- a/sc/source/filter/excel/xeformula.cxx +++ b/sc/source/filter/excel/xeformula.cxx @@ -738,8 +738,8 @@ void XclExpFmlaCompImpl::RecalcTokenClass( const XclExpTokenConvInfo& rConvInfo, // do conversion for nested operands, if token is an operator or function if( rConvInfo.mnTokPos < mxData->maOpListVec.size() ) if( const XclExpOperandList* pOperands = mxData->maOpListVec[ rConvInfo.mnTokPos ].get() ) - for( XclExpOperandList::const_iterator aIt = pOperands->begin(), aEnd = pOperands->end(); aIt != aEnd; ++aIt ) - RecalcTokenClass( *aIt, eConv, eClassConv, nTokClass == EXC_TOKCLASS_REF ); + for( const auto& rOperand : *pOperands ) + RecalcTokenClass( rOperand, eConv, eClassConv, nTokClass == EXC_TOKCLASS_REF ); } void XclExpFmlaCompImpl::FinalizeFormula() @@ -2480,18 +2480,18 @@ void XclExpFmlaCompImpl::InsertZeros( sal_uInt16 nInsertPos, sal_uInt16 nInsertS mxData->maTokVec.insert( mxData->maTokVec.begin() + nInsertPos, nInsertSize, 0 ); // update positions of operands waiting for an operator - for( ScfUInt16Vec::iterator aIt = mxData->maOpPosStack.begin(), aEnd = mxData->maOpPosStack.end(); aIt != aEnd; ++aIt ) - if( nInsertPos <= *aIt ) - *aIt = *aIt + nInsertSize; + for( auto& rOpPos : mxData->maOpPosStack ) + if( nInsertPos <= rOpPos ) + rOpPos += nInsertSize; // update operand lists of all operator tokens if( nInsertPos < mxData->maOpListVec.size() ) mxData->maOpListVec.insert( mxData->maOpListVec.begin() + nInsertPos, nInsertSize, XclExpOperandListRef() ); - for( XclExpOperandListVector::iterator aIt = mxData->maOpListVec.begin(), aEnd = mxData->maOpListVec.end(); aIt != aEnd; ++aIt ) - if( aIt->get() ) - for( XclExpOperandList::iterator aIt2 = (*aIt)->begin(), aEnd2 = (*aIt)->end(); aIt2 != aEnd2; ++aIt2 ) - if( nInsertPos <= aIt2->mnTokPos ) - aIt2->mnTokPos = aIt2->mnTokPos + nInsertSize; + for( auto& rxOpList : mxData->maOpListVec ) + if( rxOpList.get() ) + for( auto& rOp : *rxOpList ) + if( nInsertPos <= rOp.mnTokPos ) + rOp.mnTokPos += nInsertSize; } void XclExpFmlaCompImpl::Overwrite( sal_uInt16 nWriteToPos, sal_uInt16 nOffset ) diff --git a/sc/source/filter/excel/xehelper.cxx b/sc/source/filter/excel/xehelper.cxx index de1292feb7e6..7f4850194341 100644 --- a/sc/source/filter/excel/xehelper.cxx +++ b/sc/source/filter/excel/xehelper.cxx @@ -447,9 +447,9 @@ XclExpStringRef lclCreateFormattedString( rEE.GetPortions( nPara, aPosList ); // process all portions in the paragraph - for( std::vector<sal_Int32>::const_iterator it(aPosList.begin()); it != aPosList.end(); ++it ) + for( const auto& rPos : aPosList ) { - aSel.nEndPos = *it; + aSel.nEndPos = rPos; OUString aXclPortionText = aParaText.copy( aSel.nStartPos, aSel.nEndPos - aSel.nStartPos ); aItemSet.ClearItem(); @@ -716,9 +716,9 @@ void XclExpHFConverter::AppendPortion( const EditTextObject* pTextObj, sal_Unico std::vector<sal_Int32> aPosList; mrEE.GetPortions( nPara, aPosList ); - for( std::vector<sal_Int32>::const_iterator it( aPosList.begin() ); it != aPosList.end(); ++it ) + for( const auto& rPos : aPosList ) { - aSel.nEndPos = *it; + aSel.nEndPos = rPos; if( aSel.nStartPos < aSel.nEndPos ) { diff --git a/sc/source/filter/excel/xelink.cxx b/sc/source/filter/excel/xelink.cxx index 5084288d7980..63e70d5a6bfa 100644 --- a/sc/source/filter/excel/xelink.cxx +++ b/sc/source/filter/excel/xelink.cxx @@ -1162,14 +1162,14 @@ void XclExpCrn::WriteBody( XclExpStream& rStrm ) rStrm << static_cast< sal_uInt8 >( mnScCol + maValues.size() - 1 ) << static_cast< sal_uInt8 >( mnScCol ) << static_cast< sal_uInt16 >( mnScRow ); - for( CachedValues::iterator aIt = maValues.begin(), aEnd = maValues.end(); aIt != aEnd; ++aIt ) - { - if( aIt->has< bool >() ) - WriteBool( rStrm, aIt->get< bool >() ); - else if( aIt->has< double >() ) - WriteDouble( rStrm, aIt->get< double >() ); - else if( aIt->has< OUString >() ) - WriteString( rStrm, aIt->get< OUString >() ); + for( const auto& rValue : maValues ) + { + if( rValue.has< bool >() ) + WriteBool( rStrm, rValue.get< bool >() ); + else if( rValue.has< double >() ) + WriteDouble( rStrm, rValue.get< double >() ); + else if( rValue.has< OUString >() ) + WriteString( rStrm, rValue.get< OUString >() ); else WriteEmpty( rStrm ); } @@ -1220,11 +1220,11 @@ void XclExpCrn::SaveXml( XclExpXmlStream& rStrm ) FSEND); ScAddress aAdr( mnScCol, mnScRow, 0); // Tab number doesn't matter - for( CachedValues::iterator aIt = maValues.begin(), aEnd = maValues.end(); aIt != aEnd; ++aIt, aAdr.IncCol() ) + for( const auto& rValue : maValues ) { - if( aIt->has< double >() ) + if( rValue.has< double >() ) { - double fVal = aIt->get< double >(); + double fVal = rValue.get< double >(); if (rtl::math::isFinite( fVal)) { // t='n' is omitted @@ -1244,23 +1244,23 @@ void XclExpCrn::SaveXml( XclExpXmlStream& rStrm ) pFS->write( "#VALUE!" ); // OOXTODO: support other error values } } - else if( aIt->has< OUString >() ) + else if( rValue.has< OUString >() ) { pFS->startElement( XML_cell, XML_r, XclXmlUtils::ToOString( aAdr), XML_t, "str", FSEND); pFS->startElement( XML_v, FSEND ); - pFS->write( aIt->get< OUString >() ); + pFS->write( rValue.get< OUString >() ); } - else if( aIt->has< bool >() ) + else if( rValue.has< bool >() ) { pFS->startElement( XML_cell, XML_r, XclXmlUtils::ToOString( aAdr), XML_t, "b", FSEND); pFS->startElement( XML_v, FSEND ); - pFS->write( aIt->get< bool >() ? "1" : "0" ); + pFS->write( rValue.get< bool >() ? "1" : "0" ); } // OOXTODO: error type cell t='e' else @@ -1269,6 +1269,7 @@ void XclExpCrn::SaveXml( XclExpXmlStream& rStrm ) } pFS->endElement( XML_v ); pFS->endElement( XML_cell); + aAdr.IncCol(); } pFS->endElement( XML_row); @@ -1541,8 +1542,12 @@ XclExpSupbook::XclExpSupbook( const XclExpRoot& rRoot, const OUString& rUrl ) : mnFileId = nFileId + 1; ScfStringVec aTabNames; pRefMgr->getAllCachedTableNames( nFileId, aTabNames ); - for( ScfStringVec::const_iterator aBeg = aTabNames.begin(), aIt = aBeg, aEnd = aTabNames.end(); aIt != aEnd; ++aIt ) - InsertTabName( *aIt, pRefMgr->getCacheTable( nFileId, aIt - aBeg ) ); + size_t nTabIndex = 0; + for( const auto& rTabName : aTabNames ) + { + InsertTabName( rTabName, pRefMgr->getCacheTable( nFileId, nTabIndex ) ); + ++nTabIndex; + } } XclExpSupbook::XclExpSupbook( const XclExpRoot& rRoot, const OUString& rApplic, const OUString& rTopic ) : @@ -2481,8 +2486,8 @@ void XclExpLinkManagerImpl8::Save( XclExpStream& rStrm ) rStrm.StartRecord( EXC_ID_EXTERNSHEET, 2 + 6 * nCount ); rStrm << nCount; rStrm.SetSliceSize( 6 ); - for( XclExpXtiVec::const_iterator aIt = maXtiVec.begin(), aEnd = maXtiVec.end(); aIt != aEnd; ++aIt ) - aIt->Save( rStrm ); + for( const auto& rXti : maXtiVec ) + rXti.Save( rStrm ); rStrm.EndRecord(); } } @@ -2504,17 +2509,17 @@ void XclExpLinkManagerImpl8::SaveXml( XclExpXmlStream& rStrm ) #if 0 if( !maXtiVec.empty() ) { - for( XclExpXtiVec::const_iterator aIt = maXtiVec.begin(), aEnd = maXtiVec.end(); aIt != aEnd; ++aIt ) - aIt->SaveXml( rStrm ); + for( const auto& rXti : maXtiVec ) + rXti.SaveXml( rStrm ); } #endif } sal_uInt16 XclExpLinkManagerImpl8::InsertXti( const XclExpXti& rXti ) { - for( XclExpXtiVec::const_iterator aIt = maXtiVec.begin(), aEnd = maXtiVec.end(); aIt != aEnd; ++aIt ) - if( *aIt == rXti ) - return ulimit_cast< sal_uInt16 >( aIt - maXtiVec.begin() ); + auto aIt = std::find(maXtiVec.begin(), maXtiVec.end(), rXti); + if (aIt != maXtiVec.end()) + return ulimit_cast< sal_uInt16 >( std::distance(maXtiVec.begin(), aIt) ); maXtiVec.push_back( rXti ); return ulimit_cast< sal_uInt16 >( maXtiVec.size() - 1 ); } diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx index 167ffd227856..0ee0da0d05b4 100644 --- a/sc/source/filter/excel/xename.cxx +++ b/sc/source/filter/excel/xename.cxx @@ -711,36 +711,32 @@ void XclExpNameManagerImpl::CreateUserNames() { std::vector<ScRangeData*> vEmulateAsLocalRange; const ScRangeName& rNamedRanges = GetNamedRanges(); - ScRangeName::const_iterator itr = rNamedRanges.begin(), itrEnd = rNamedRanges.end(); - for (; itr != itrEnd; ++itr) + for (const auto& rEntry : rNamedRanges) { // skip definitions of shared formulas - if (!FindNamedExp(SCTAB_GLOBAL, itr->second->GetName())) + if (!FindNamedExp(SCTAB_GLOBAL, rEntry.second->GetName())) { - const ScTokenArray* pCode = itr->second->GetCode(); + const ScTokenArray* pCode = rEntry.second->GetCode(); if ( pCode - && (itr->second->HasType( ScRangeData::Type::AbsPos ) || itr->second->HasType( ScRangeData::Type::AbsArea )) + && (rEntry.second->HasType( ScRangeData::Type::AbsPos ) || rEntry.second->HasType( ScRangeData::Type::AbsArea )) && lcl_EnsureAbs3DToken( SCTAB_GLOBAL, pCode->FirstToken(), /*bFix=*/false ) ) { - vEmulateAsLocalRange.emplace_back(itr->second.get()); + vEmulateAsLocalRange.emplace_back(rEntry.second.get()); } else - CreateName(SCTAB_GLOBAL, *itr->second); + CreateName(SCTAB_GLOBAL, *rEntry.second); } } //look at sheets containing local range names ScRangeName::TabNameCopyMap rLocalNames; GetDoc().GetAllTabRangeNames(rLocalNames); - ScRangeName::TabNameCopyMap::iterator tabIt = rLocalNames.begin(), tabItEnd = rLocalNames.end(); - for (; tabIt != tabItEnd; ++tabIt) + for (const auto& [rTab, pRangeName] : rLocalNames) { - itr = tabIt->second->begin(); - itrEnd = tabIt->second->end(); - for (; itr != itrEnd; ++itr) + for (const auto& rEntry : *pRangeName) { // skip definitions of shared formulas - if (!FindNamedExp(tabIt->first, itr->second->GetName())) - CreateName(tabIt->first, *itr->second); + if (!FindNamedExp(rTab, rEntry.second->GetName())) + CreateName(rTab, *rEntry.second); } } diff --git a/sc/source/filter/excel/xepage.cxx b/sc/source/filter/excel/xepage.cxx index 7b2d0ded5d86..9ad3b873321f 100644 --- a/sc/source/filter/excel/xepage.cxx +++ b/sc/source/filter/excel/xepage.cxx @@ -175,9 +175,9 @@ void XclExpPageBreaks::WriteBody( XclExpStream& rStrm ) bool bWriteRange = (rStrm.GetRoot().GetBiff() == EXC_BIFF8); rStrm << static_cast< sal_uInt16 >( mrPageBreaks.size() ); - for( ScfUInt16Vec::const_iterator aIt = mrPageBreaks.begin(), aEnd = mrPageBreaks.end(); aIt != aEnd; ++aIt ) + for( const auto& rPageBreak : mrPageBreaks ) { - rStrm << *aIt; + rStrm << rPageBreak; if( bWriteRange ) rStrm << sal_uInt16( 0 ) << mnMaxPos; } @@ -195,10 +195,10 @@ void XclExpPageBreaks::SaveXml( XclExpXmlStream& rStrm ) XML_count, sNumPageBreaks.getStr(), XML_manualBreakCount, sNumPageBreaks.getStr(), FSEND ); - for( ScfUInt16Vec::const_iterator aIt = mrPageBreaks.begin(), aEnd = mrPageBreaks.end(); aIt != aEnd; ++aIt ) + for( const auto& rPageBreak : mrPageBreaks ) { pWorksheet->singleElement( XML_brk, - XML_id, OString::number( *aIt ).getStr(), + XML_id, OString::number( rPageBreak ).getStr(), XML_man, "true", XML_max, OString::number( mnMaxPos ).getStr(), XML_min, "0", @@ -314,9 +314,8 @@ XclExpPageSettings::XclExpPageSettings( const XclExpRoot& rRoot ) : rDoc.GetAllRowBreaks(aRowBreaks, nScTab, false, true); SCROW const nMaxRow = numeric_limits<sal_uInt16>::max(); - for (set<SCROW>::const_iterator itr = aRowBreaks.begin(), itrEnd = aRowBreaks.end(); itr != itrEnd; ++itr) + for (const SCROW nRow : aRowBreaks) { - SCROW nRow = *itr; if (nRow > nMaxRow) break; @@ -333,8 +332,8 @@ XclExpPageSettings::XclExpPageSettings( const XclExpRoot& rRoot ) : set<SCCOL> aColBreaks; rDoc.GetAllColBreaks(aColBreaks, nScTab, false, true); - for (set<SCCOL>::const_iterator itr = aColBreaks.begin(), itrEnd = aColBreaks.end(); itr != itrEnd; ++itr) - maData.maVerPageBreaks.push_back(*itr); + for (const auto& rColBreak : aColBreaks) + maData.maVerPageBreaks.push_back(rColBreak); } class XclExpXmlStartHeaderFooterElementRecord : public XclExpXmlElementRecord diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx index 7fd6d2034b2d..888759ce702f 100644 --- a/sc/source/filter/excel/xepivot.cxx +++ b/sc/source/filter/excel/xepivot.cxx @@ -601,8 +601,8 @@ void XclExpPCField::WriteSxgroupinfo( XclExpStream& rStrm ) if( IsStdGroupField() && !maGroupOrder.empty() ) { rStrm.StartRecord( EXC_ID_SXGROUPINFO, 2 * maGroupOrder.size() ); - for( ScfUInt16Vec::const_iterator aIt = maGroupOrder.begin(), aEnd = maGroupOrder.end(); aIt != aEnd; ++aIt ) - rStrm << *aIt; + for( const auto& rItem : maGroupOrder ) + rStrm << rItem; rStrm.EndRecord(); } } @@ -1057,9 +1057,9 @@ void XclExpPTField::SetPropertiesFromDim( const ScDPSaveDimension& rSaveDim ) // item properties const ScDPSaveDimension::MemberList &rMembers = rSaveDim.GetMembers(); - for (ScDPSaveDimension::MemberList::const_iterator i=rMembers.begin(); i != rMembers.end() ; ++i) - if( XclExpPTItem* pItem = GetItemAcc( (*i)->GetName() ) ) - pItem->SetPropertiesFromMember( **i ); + for (const auto& pMember : rMembers) + if( XclExpPTItem* pItem = GetItemAcc( pMember->GetName() ) ) + pItem->SetPropertiesFromMember( *pMember ); } void XclExpPTField::SetDataPropertiesFromDim( const ScDPSaveDimension& rSaveDim ) @@ -1244,10 +1244,13 @@ const XclExpPTField* XclExpPivotTable::GetField( const OUString& rName ) const sal_uInt16 XclExpPivotTable::GetDataFieldIndex( const OUString& rName, sal_uInt16 nDefaultIdx ) const { - for( XclPTDataFieldPosVec::const_iterator aIt = maDataFields.begin(), aEnd = maDataFields.end(); aIt != aEnd; ++aIt ) - if( const XclExpPTField* pField = GetField( aIt->first ) ) - if( pField->GetFieldName() == rName ) - return static_cast< sal_uInt16 >( aIt - maDataFields.begin() ); + auto aIt = std::find_if(maDataFields.begin(), maDataFields.end(), + [this, &rName](const XclPTDataFieldPos& rDataField) { + const XclExpPTField* pField = GetField( rDataField.first ); + return pField && pField->GetFieldName() == rName; + }); + if (aIt != maDataFields.end()) + return static_cast< sal_uInt16 >( std::distance(maDataFields.begin(), aIt) ); return nDefaultIdx; } @@ -1391,7 +1394,7 @@ void XclExpPivotTable::Finalize() { ScfUInt16Vec::const_iterator aIt = ::std::find( pFieldVec->begin(), pFieldVec->end(), EXC_SXIVD_DATA ); if( aIt != pFieldVec->end() ) - maPTInfo.mnDataPos = static_cast< sal_uInt16 >( aIt - pFieldVec->begin() ); + maPTInfo.mnDataPos = static_cast< sal_uInt16 >( std::distance(pFieldVec->begin(), aIt) ); } // single data field is always row oriented @@ -1450,8 +1453,8 @@ void XclExpPivotTable::WriteSxivd( XclExpStream& rStrm, const ScfUInt16Vec& rFie if( !rFields.empty() ) { rStrm.StartRecord( EXC_ID_SXIVD, rFields.size() * 2 ); - for( ScfUInt16Vec::const_iterator aIt = rFields.begin(), aEnd = rFields.end(); aIt != aEnd; ++aIt ) - rStrm << *aIt; + for( const auto& rField : rFields ) + rStrm << rField; rStrm.EndRecord(); } } @@ -1462,9 +1465,9 @@ void XclExpPivotTable::WriteSxpi( XclExpStream& rStrm ) const { rStrm.StartRecord( EXC_ID_SXPI, maPageFields.size() * 6 ); rStrm.SetSliceSize( 6 ); - for( ScfUInt16Vec::const_iterator aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt ) + for( const auto& rPageField : maPageFields ) { - XclExpPTFieldRef xField = maFieldList.GetRecord( *aIt ); + XclExpPTFieldRef xField = maFieldList.GetRecord( rPageField ); if( xField ) xField->WriteSxpiEntry( rStrm ); } @@ -1474,11 +1477,11 @@ void XclExpPivotTable::WriteSxpi( XclExpStream& rStrm ) const void XclExpPivotTable::WriteSxdiList( XclExpStream& rStrm ) const { - for( XclPTDataFieldPosVec::const_iterator aIt = maDataFields.begin(), aEnd = maDataFields.end(); aIt != aEnd; ++aIt ) + for( const auto& [rFieldIdx, rDataInfoIdx] : maDataFields ) { - XclExpPTFieldRef xField = maFieldList.GetRecord( aIt->first ); + XclExpPTFieldRef xField = maFieldList.GetRecord( rFieldIdx ); if( xField ) - xField->WriteSxdi( rStrm, aIt->second ); + xField->WriteSxdi( rStrm, rDataInfoIdx ); } } diff --git a/sc/source/filter/excel/xepivotxml.cxx b/sc/source/filter/excel/xepivotxml.cxx index bd8a081a82ae..b7fbd6bc1556 100644 --- a/sc/source/filter/excel/xepivotxml.cxx +++ b/sc/source/filter/excel/xepivotxml.cxx @@ -254,19 +254,17 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( XclExpXmlStream& rStrm, const Entr const ScDPCache::ScDPItemDataVec& rFieldItems = rCache.GetDimMemberValues(i); - ScDPCache::ScDPItemDataVec::const_iterator it = rFieldItems.begin(), itEnd = rFieldItems.end(); - std::set<ScDPItemData::Type> aDPTypes; double fMin = std::numeric_limits<double>::infinity(), fMax = -std::numeric_limits<double>::infinity(); bool isValueInteger = true; bool isContainsDate = rCache.IsDateDimension(i); - for (; it != itEnd; ++it) + for (const auto& rFieldItem : rFieldItems) { - ScDPItemData::Type eType = it->GetType(); + ScDPItemData::Type eType = rFieldItem.GetType(); aDPTypes.insert(eType); if (eType == ScDPItemData::Value) { - double fVal = it->GetValue(); + double fVal = rFieldItem.GetValue(); fMin = std::min(fMin, fVal); fMax = std::max(fMax, fVal); @@ -359,10 +357,8 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( XclExpXmlStream& rStrm, const Entr //if (bListItems) // see TODO above { - it = rFieldItems.begin(); - for (; it != itEnd; ++it) + for (const ScDPItemData& rItem : rFieldItems) { - const ScDPItemData& rItem = *it; switch (rItem.GetType()) { case ScDPItemData::String: @@ -445,9 +441,8 @@ void XclExpXmlPivotTableManager::Initialize() // Get all pivot objects that reference this cache, and set up an // object to cache ID mapping. const ScDPCache::ScDPObjectSet& rRefs = pCache->GetAllReferences(); - ScDPCache::ScDPObjectSet::const_iterator it = rRefs.begin(), itEnd = rRefs.end(); - for (; it != itEnd; ++it) - maCacheIdMap.emplace(*it, aCaches.size()+1); + for (const auto& rRef : rRefs) + maCacheIdMap.emplace(rRef, aCaches.size()+1); XclExpXmlPivotCaches::Entry aEntry; aEntry.mpCache = pCache; @@ -507,13 +502,11 @@ void XclExpXmlPivotTables::SaveXml( XclExpXmlStream& rStrm ) { sax_fastparser::FSHelperPtr& pWSStrm = rStrm.GetCurrentStream(); // worksheet stream - sal_Int32 nCounter = 1; // 1-based - TablesType::iterator it = maTables.begin(), itEnd = maTables.end(); - for (; it != itEnd; ++it, ++nCounter) + for (const auto& rTable : maTables) { - const ScDPObject& rObj = *it->mpTable; - sal_Int32 nCacheId = it->mnCacheId; - sal_Int32 nPivotId = it->mnPivotId; + const ScDPObject& rObj = *rTable.mpTable; + sal_Int32 nCacheId = rTable.mnCacheId; + sal_Int32 nPivotId = rTable.mnPivotId; sax_fastparser::FSHelperPtr pPivotStrm = rStrm.CreateOutputStream( XclXmlUtils::GetStreamName("xl/pivotTables/", "pivotTable", nPivotId), @@ -792,31 +785,26 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP } const ScDPCache::ScDPItemDataVec& rCacheFieldItems = rCache.GetDimMemberValues(i); - const auto iCacheFieldItems_begin = rCacheFieldItems.begin(), iCacheFieldItems_end = rCacheFieldItems.end(); // The pair contains the member index in cache and if it is hidden std::vector< std::pair<size_t, bool> > aMemberSequence; std::set<size_t> aUsedCachePositions; for (const auto & rMember : aMembers) { - for (auto it = iCacheFieldItems_begin; it != iCacheFieldItems_end; ++it) + auto it = std::find_if(rCacheFieldItems.begin(), rCacheFieldItems.end(), + [&rDPObj, &pDim, &rMember](const ScDPItemData& rItem) { + OUString sFormattedName; + if (rItem.HasStringData() || rItem.IsEmpty()) + sFormattedName = rItem.GetString(); + else + sFormattedName = const_cast<ScDPObject&>(rDPObj).GetFormattedString(pDim->GetName(), rItem.GetValue()); + return sFormattedName == rMember.maName; + }); + if (it != rCacheFieldItems.end()) { - OUString sFormattedName; - if (it->HasStringData() || it->IsEmpty()) - { - sFormattedName = it->GetString(); - } - else - { - sFormattedName = const_cast<ScDPObject&>(rDPObj).GetFormattedString(pDim->GetName(), it->GetValue()); - } - if (sFormattedName == rMember.maName) - { - size_t nCachePos = it - iCacheFieldItems_begin; - auto aInserted = aUsedCachePositions.insert(nCachePos); - if (aInserted.second) - aMemberSequence.emplace_back(std::make_pair(nCachePos, !rMember.mbVisible)); - break; - } + size_t nCachePos = static_cast<size_t>(std::distance(rCacheFieldItems.begin(), it)); + auto aInserted = aUsedCachePositions.insert(nCachePos); + if (aInserted.second) + aMemberSequence.emplace_back(std::make_pair(nCachePos, !rMember.mbVisible)); } } // Now add all remaining cache items as hidden @@ -888,11 +876,10 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP XML_count, OString::number(static_cast<long>(aRowFields.size())), FSEND); - std::vector<long>::iterator it = aRowFields.begin(), itEnd = aRowFields.end(); - for (; it != itEnd; ++it) + for (const auto& rRowField : aRowFields) { pPivotStrm->singleElement(XML_field, - XML_x, OString::number(*it), + XML_x, OString::number(rRowField), FSEND); } @@ -909,11 +896,10 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP XML_count, OString::number(static_cast<long>(aColFields.size())), FSEND); - std::vector<long>::iterator it = aColFields.begin(), itEnd = aColFields.end(); - for (; it != itEnd; ++it) + for (const auto& rColField : aColFields) { pPivotStrm->singleElement(XML_field, - XML_x, OString::number(*it), + XML_x, OString::number(rColField), FSEND); } @@ -930,11 +916,10 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP XML_count, OString::number(static_cast<long>(aPageFields.size())), FSEND); - std::vector<long>::iterator it = aPageFields.begin(), itEnd = aPageFields.end(); - for (; it != itEnd; ++it) + for (const auto& rPageField : aPageFields) { pPivotStrm->singleElement(XML_pageField, - XML_fld, OString::number(*it), + XML_fld, OString::number(rPageField), XML_hier, OString::number(-1), // TODO : handle this correctly. FSEND); } @@ -950,12 +935,11 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP XML_count, OString::number(static_cast<long>(aDataFields.size())), FSEND); - std::vector<DataField>::iterator it = aDataFields.begin(), itEnd = aDataFields.end(); - for (; it != itEnd; ++it) + for (const auto& rDataField : aDataFields) { - long nDimIdx = it->mnPos; + long nDimIdx = rDataField.mnPos; assert(aCachedDims[nDimIdx]); // the loop above should have screened for NULL's. - const ScDPSaveDimension& rDim = *it->mpDim; + const ScDPSaveDimension& rDim = *rDataField.mpDim; const boost::optional<OUString> & pName = rDim.GetLayoutName(); pPivotStrm->write("<")->writeId(XML_dataField); if (pName) diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx index 3455b741164c..b62de7eeafbf 100644 --- a/sc/source/filter/excel/xestream.cxx +++ b/sc/source/filter/excel/xestream.cxx @@ -304,8 +304,7 @@ void XclExpStream::WriteUnicodeBuffer( const ScfUInt16Vec& rBuffer, sal_uInt8 nF nFlags &= EXC_STRF_16BIT; // repeat only 16bit flag sal_uInt16 nCharLen = nFlags ? 2 : 1; - ScfUInt16Vec::const_iterator aEnd = rBuffer.end(); - for( ScfUInt16Vec::const_iterator aIter = rBuffer.begin(); aIter != aEnd; ++aIter ) + for( const auto& rItem : rBuffer ) { if( mbInRec && (mnCurrSize + nCharLen > mnCurrMaxSize) ) { @@ -313,9 +312,9 @@ void XclExpStream::WriteUnicodeBuffer( const ScfUInt16Vec& rBuffer, sal_uInt8 nF operator<<( nFlags ); } if( nCharLen == 2 ) - operator<<( *aIter ); + operator<<( rItem ); else - operator<<( static_cast< sal_uInt8 >( *aIter ) ); + operator<<( static_cast< sal_uInt8 >( rItem ) ); } } @@ -775,10 +774,9 @@ static ScRange lcl_ToRange( const XclRange& rRange ) OString XclXmlUtils::ToOString( const XclRangeList& rRanges ) { ScRangeList aRanges; - for( XclRangeVector::const_iterator i = rRanges.begin(), end = rRanges.end(); - i != end; ++i ) + for( const auto& rRange : rRanges ) { - aRanges.push_back( lcl_ToRange( *i ) ); + aRanges.push_back( lcl_ToRange( rRange ) ); } return ToOString( aRanges ); } diff --git a/sc/source/filter/excel/xestring.cxx b/sc/source/filter/excel/xestring.cxx index b43b700afcca..597c9174132f 100644 --- a/sc/source/filter/excel/xestring.cxx +++ b/sc/source/filter/excel/xestring.cxx @@ -43,13 +43,11 @@ int lclCompareVectors( const ::std::vector< Type >& rLeft, const ::std::vector< int nResult = 0; // 1st: compare all elements of the vectors - typedef typename ::std::vector< Type >::const_iterator CIT; - CIT aEndL = rLeft.end(), aEndR = rRight.end(); - for( CIT aItL = rLeft.begin(), aItR = rRight.begin(); !nResult && (aItL != aEndL) && (aItR != aEndR); ++aItL, ++aItR ) + auto [aItL, aItR] = std::mismatch(rLeft.begin(), rLeft.end(), rRight.begin(), rRight.end()); + if ((aItL != rLeft.end()) && (aItR != rRight.end())) nResult = static_cast< int >( *aItL ) - static_cast< int >( *aItR ); - - // 2nd: no differences found so far -> compare the vector sizes. Shorter vector is less - if( !nResult ) + else + // 2nd: compare the vector sizes. Shorter vector is less nResult = static_cast< int >( rLeft.size() ) - static_cast< int >( rRight.size() ); return nResult; @@ -81,9 +79,8 @@ template< typename Type, typename ValueHasher > sal_uInt16 lclHashVector( const ::std::vector< Type >& rVec, const ValueHasher& rHasher ) { sal_uInt32 nHash = rVec.size(); - typedef typename ::std::vector< Type >::const_iterator CIT; - for( CIT aIt = rVec.begin(), aEnd = rVec.end(); aIt != aEnd; ++aIt ) - nHash = (nHash * 31) + rHasher( *aIt ); + for( const auto& rItem : rVec ) + nHash = (nHash * 31) + rHasher( rItem ); return static_cast< sal_uInt16 >( nHash ^ (nHash >> 16) ); } @@ -315,22 +312,21 @@ void XclExpString::WriteFormats( XclExpStream& rStrm, bool bWriteSize ) const { if( IsRich() ) { - XclFormatRunVec::const_iterator aIt = maFormats.begin(), aEnd = maFormats.end(); if( mbIsBiff8 ) { if( bWriteSize ) rStrm << GetFormatsCount(); rStrm.SetSliceSize( 4 ); - for( ; aIt != aEnd; ++aIt ) - rStrm << aIt->mnChar << aIt->mnFontIdx; + for( const auto& rFormat : maFormats ) + rStrm << rFormat.mnChar << rFormat.mnFontIdx; } else { if( bWriteSize ) rStrm << static_cast< sal_uInt8 >( GetFormatsCount() ); rStrm.SetSliceSize( 2 ); - for( ; aIt != aEnd; ++aIt ) - rStrm << static_cast< sal_uInt8 >( aIt->mnChar ) << static_cast< sal_uInt8 >( aIt->mnFontIdx ); + for( const auto& rFormat : maFormats ) + rStrm << static_cast< sal_uInt8 >( rFormat.mnChar ) << static_cast< sal_uInt8 >( rFormat.mnFontIdx ); } rStrm.SetSliceSize( 0 ); } @@ -373,9 +369,8 @@ void XclExpString::WriteBufferToMem( sal_uInt8* pnMem ) const { if( mbIsBiff8 ) { - for( ScfUInt16Vec::const_iterator aIt = maUniBuffer.begin(), aEnd = maUniBuffer.end(); aIt != aEnd; ++aIt ) + for( const sal_uInt16 nChar : maUniBuffer ) { - sal_uInt16 nChar = *aIt; *pnMem = static_cast< sal_uInt8 >( nChar ); ++pnMem; if( mbIsUnicode ) @@ -433,15 +428,14 @@ void XclExpString::WriteXml( XclExpXmlStream& rStrm ) const else { XclExpFontBuffer& rFonts = rStrm.GetRoot().GetFontBuffer(); - XclFormatRunVec::const_iterator aIt = maFormats.begin(), aEnd = maFormats.end(); sal_uInt16 nStart = 0; const XclExpFont* pFont = nullptr; - for ( ; aIt != aEnd; ++aIt ) + for ( const auto& rFormat : maFormats ) { nStart = lcl_WriteRun( rStrm, GetUnicodeBuffer(), - nStart, aIt->mnChar-nStart, pFont ); - pFont = rFonts.GetFont( aIt->mnFontIdx ); + nStart, rFormat.mnChar-nStart, pFont ); + pFont = rFonts.GetFont( rFormat.mnFontIdx ); } lcl_WriteRun( rStrm, GetUnicodeBuffer(), nStart, GetUnicodeBuffer().size() - nStart, pFont ); diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index 805e5392ea05..9478698140d5 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -388,8 +388,8 @@ void XclExpPaletteImpl::Finalize() } // remap color ID data map (maColorIdDataVec) from list indexes to palette indexes - for( XclColorIdDataVec::iterator aIt = maColorIdDataVec.begin(), aEnd = maColorIdDataVec.end(); aIt != aEnd; ++aIt ) - aIt->mnIndex = aRemapVec[ aIt->mnIndex ].mnPalIndex; + for( auto& rColorIdData : maColorIdDataVec ) + rColorIdData.mnIndex = aRemapVec[ rColorIdData.mnIndex ].mnPalIndex; } sal_uInt16 XclExpPaletteImpl::GetColorIndex( sal_uInt32 nColorId ) const @@ -472,8 +472,8 @@ bool XclExpPaletteImpl::IsDefaultPalette() const void XclExpPaletteImpl::WriteBody( XclExpStream& rStrm ) { rStrm << static_cast< sal_uInt16 >( maPalette.size() ); - for( XclPaletteColorVec::const_iterator aIt = maPalette.begin(), aEnd = maPalette.end(); aIt != aEnd; ++aIt ) - rStrm << aIt->maColor; + for( const auto& rColor : maPalette ) + rStrm << rColor.maColor; } void XclExpPaletteImpl::SaveXml( XclExpXmlStream& rStrm ) @@ -484,9 +484,9 @@ void XclExpPaletteImpl::SaveXml( XclExpXmlStream& rStrm ) sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream(); rStyleSheet->startElement( XML_colors, FSEND ); rStyleSheet->startElement( XML_indexedColors, FSEND ); - for( XclPaletteColorVec::const_iterator aIt = maPalette.begin(), aEnd = maPalette.end(); aIt != aEnd; ++aIt ) + for( const auto& rColor : maPalette ) rStyleSheet->singleElement( XML_rgbColor, - XML_rgb, XclXmlUtils::ToOString( aIt->maColor ).getStr(), + XML_rgb, XclXmlUtils::ToOString( rColor.maColor ).getStr(), FSEND ); rStyleSheet->endElement( XML_indexedColors ); rStyleSheet->endElement( XML_colors ); @@ -613,8 +613,8 @@ void XclExpPaletteImpl::RawReducePalette( sal_uInt32 nPass ) } // update color ID data map (maps color IDs to color list indexes), replace old by new list indexes - for( XclColorIdDataVec::iterator aIt = maColorIdDataVec.begin(), aEnd = maColorIdDataVec.end(); aIt != aEnd; ++aIt ) - aIt->mnIndex = aListIndexMap[ aIt->mnIndex ]; + for( auto& rColorIdData : maColorIdDataVec ) + rColorIdData.mnIndex = aListIndexMap[ rColorIdData.mnIndex ]; } void XclExpPaletteImpl::ReduceLeastUsedColor() @@ -638,12 +638,12 @@ void XclExpPaletteImpl::ReduceLeastUsedColor() if( nKeep > nRemove ) --nKeep; // recalculate color ID data map (maps color IDs to color list indexes) - for( XclColorIdDataVec::iterator aIt = maColorIdDataVec.begin(), aEnd = maColorIdDataVec.end(); aIt != aEnd; ++aIt ) + for( auto& rColorIdData : maColorIdDataVec ) { - if( aIt->mnIndex > nRemove ) - --aIt->mnIndex; - else if( aIt->mnIndex == nRemove ) - aIt->mnIndex = nKeep; + if( rColorIdData.mnIndex > nRemove ) + --rColorIdData.mnIndex; + else if( rColorIdData.mnIndex == nRemove ) + rColorIdData.mnIndex = nKeep; } } } @@ -703,18 +703,19 @@ sal_Int32 XclExpPaletteImpl::GetNearestPaletteColor( rnIndex = 0; sal_Int32 nDist = SAL_MAX_INT32; - for( XclPaletteColorVec::const_iterator aIt = maPalette.begin(), aEnd = maPalette.end(); - aIt != aEnd; ++aIt ) + sal_uInt32 nPaletteIndex = 0; + for( const auto& rPaletteColor : maPalette ) { - if( !aIt->mbUsed ) + if( !rPaletteColor.mbUsed ) { - sal_Int32 nCurrDist = lclGetColorDistance( rColor, aIt->maColor ); + sal_Int32 nCurrDist = lclGetColorDistance( rColor, rPaletteColor.maColor ); if( nCurrDist < nDist ) { - rnIndex = aIt - maPalette.begin(); + rnIndex = nPaletteIndex; nDist = nCurrDist; } } + ++nPaletteIndex; } return nDist; } @@ -726,22 +727,23 @@ sal_Int32 XclExpPaletteImpl::GetNearPaletteColors( sal_Int32 nDist1 = SAL_MAX_INT32; sal_Int32 nDist2 = SAL_MAX_INT32; - for( XclPaletteColorVec::const_iterator aIt = maPalette.begin(), aEnd = maPalette.end(); - aIt != aEnd; ++aIt ) + sal_uInt32 nPaletteIndex = 0; + for( const auto& rPaletteColor : maPalette ) { - sal_Int32 nCurrDist = lclGetColorDistance( rColor, aIt->maColor ); + sal_Int32 nCurrDist = lclGetColorDistance( rColor, rPaletteColor.maColor ); if( nCurrDist < nDist1 ) { rnSecond = rnFirst; nDist2 = nDist1; - rnFirst = aIt - maPalette.begin(); + rnFirst = nPaletteIndex; nDist1 = nCurrDist; } else if( nCurrDist < nDist2 ) { - rnSecond = aIt - maPalette.begin(); + rnSecond = nPaletteIndex; nDist2 = nCurrDist; } + ++nPaletteIndex; } return nDist1; } @@ -1390,8 +1392,8 @@ sal_uInt16 XclExpNumFmtBuffer::Insert( sal_uInt32 nScNumFmt ) void XclExpNumFmtBuffer::Save( XclExpStream& rStrm ) { - for( XclExpNumFmtVec::const_iterator aIt = maFormatMap.begin(), aEnd = maFormatMap.end(); aIt != aEnd; ++aIt ) - WriteFormatRecord( rStrm, *aIt ); + for( const auto& rEntry : maFormatMap ) + WriteFormatRecord( rStrm, rEntry ); } void XclExpNumFmtBuffer::SaveXml( XclExpXmlStream& rStrm ) @@ -1403,9 +1405,9 @@ void XclExpNumFmtBuffer::SaveXml( XclExpXmlStream& rStrm ) rStyleSheet->startElement( XML_numFmts, XML_count, OString::number( maFormatMap.size() ).getStr(), FSEND ); - for( XclExpNumFmtVec::iterator aIt = maFormatMap.begin(), aEnd = maFormatMap.end(); aIt != aEnd; ++aIt ) + for( auto& rEntry : maFormatMap ) { - aIt->SaveXml( rStrm ); + rEntry.SaveXml( rStrm ); } rStyleSheet->endElement( XML_numFmts ); } @@ -2508,8 +2510,8 @@ void XclExpXFBuffer::Finalize() // *** map all built-in XF records (cell and style) *** ------------------- // do not change XF order -> std::map<> iterates elements in ascending order - for( XclExpBuiltInMap::const_iterator aIt = maBuiltInMap.begin(); aIt != aBuiltInEnd; ++aIt ) - AppendXFIndex( aIt->first ); + for( const auto& rEntry : maBuiltInMap ) + AppendXFIndex( rEntry.first ); // *** insert all user-defined style XF records, without reduce *** ------- @@ -2641,20 +2643,18 @@ void XclExpXFBuffer::SaveXml( XclExpXmlStream& rStrm ) rStyleSheet->startElement( XML_fills, XML_count, OString::number( maFills.size() ).getStr(), FSEND ); - for( XclExpFillList::iterator aIt = maFills.begin(), aEnd = maFills.end(); - aIt != aEnd; ++aIt ) + for( auto& rFill : maFills ) { - aIt->SaveXml( rStrm ); + rFill.SaveXml( rStrm ); } rStyleSheet->endElement( XML_fills ); rStyleSheet->startElement( XML_borders, XML_count, OString::number( maBorders.size() ).getStr(), FSEND ); - for( XclExpBorderList::iterator aIt = maBorders.begin(), aEnd = maBorders.end(); - aIt != aEnd; ++aIt ) + for( auto& rBorder : maBorders ) { - aIt->SaveXml( rStrm ); + rBorder.SaveXml( rStrm ); } rStyleSheet->endElement( XML_borders ); @@ -2740,9 +2740,12 @@ sal_uInt32 XclExpXFBuffer::FindXF( const SfxStyleSheetBase& rStyleSheet ) const sal_uInt32 XclExpXFBuffer::FindBuiltInXF( sal_uInt8 nStyleId, sal_uInt8 nLevel ) const { - for( XclExpBuiltInMap::const_iterator aIt = maBuiltInMap.begin(), aEnd = maBuiltInMap.end(); aIt != aEnd; ++aIt ) - if( (aIt->second.mnStyleId == nStyleId) && (aIt->second.mnLevel == nLevel) ) - return aIt->first; + auto aIt = std::find_if(maBuiltInMap.begin(), maBuiltInMap.end(), + [&nStyleId, nLevel](const XclExpBuiltInMap::value_type& rEntry) { + return (rEntry.second.mnStyleId == nStyleId) && (rEntry.second.mnLevel == nLevel); + }); + if (aIt != maBuiltInMap.end()) + return aIt->first; return EXC_XFID_NOTFOUND; } @@ -2997,13 +3000,12 @@ XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot ) ScConditionalFormatList* pList = rRoot.GetDoc().GetCondFormList(nTab); if (pList) { - for (ScConditionalFormatList::const_iterator itr = pList->begin(); - itr != pList->end(); ++itr) + for (const auto& rxItem : *pList) { - size_t nEntryCount = (*itr)->size(); + size_t nEntryCount = rxItem->size(); for (size_t nFormatEntry = 0; nFormatEntry < nEntryCount; ++nFormatEntry) { - const ScFormatEntry* pFormatEntry = (*itr)->GetEntry(nFormatEntry); + const ScFormatEntry* pFormatEntry = rxItem->GetEntry(nFormatEntry); if (!pFormatEntry || (pFormatEntry->GetType() != ScFormatEntry::Type::Condition && pFormatEntry->GetType() != ScFormatEntry::Type::Date)) continue; @@ -3094,9 +3096,9 @@ void XclExpDxfs::SaveXml( XclExpXmlStream& rStrm ) XML_count, OString::number(maDxf.size()).getStr(), FSEND ); - for ( DxfContainer::iterator itr = maDxf.begin(); itr != maDxf.end(); ++itr ) + for ( auto& rxDxf : maDxf ) { - (*itr)->SaveXml( rStrm ); + rxDxf->SaveXml( rStrm ); } rStyleSheet->endElement( XML_dxfs ); diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx index 033544d6ff10..1292138d9b0b 100644 --- a/sc/source/filter/excel/xetable.cxx +++ b/sc/source/filter/excel/xetable.cxx @@ -20,6 +20,7 @@ #include <xetable.hxx> #include <map> +#include <numeric> #include <com/sun/star/i18n/ScriptType.hpp> #include <scitems.hxx> #include <svl/intitem.hxx> @@ -1114,8 +1115,8 @@ bool XclExpMultiCellBase::IsEmpty() const void XclExpMultiCellBase::ConvertXFIndexes( const XclExpRoot& rRoot ) { - for( XclExpMultiXFIdDeq::iterator aIt = maXFIds.begin(), aEnd = maXFIds.end(); aIt != aEnd; ++aIt ) - aIt->ConvertXFIndex( rRoot ); + for( auto& rXFId : maXFIds ) + rXFId.ConvertXFIndex( rRoot ); } void XclExpMultiCellBase::Save( XclExpStream& rStrm ) @@ -1226,10 +1227,8 @@ void XclExpMultiCellBase::SaveXml( XclExpXmlStream& rStrm ) sal_uInt16 XclExpMultiCellBase::GetCellCount() const { - sal_uInt16 nCount = 0; - for( XclExpMultiXFIdDeq::const_iterator aIt = maXFIds.begin(), aEnd = maXFIds.end(); aIt != aEnd; ++aIt ) - nCount = nCount + aIt->mnCount; - return nCount; + return std::accumulate(maXFIds.begin(), maXFIds.end(), sal_uInt16(0), + [](const sal_uInt16& rSum, const XclExpMultiXFId& rXFId) { return rSum + rXFId.mnCount; }); } void XclExpMultiCellBase::AppendXFId( const XclExpMultiXFId& rXFId ) @@ -1262,10 +1261,10 @@ void XclExpMultiCellBase::GetXFIndexes( ScfUInt16Vec& rXFIndexes ) const { OSL_ENSURE( GetLastXclCol() < rXFIndexes.size(), "XclExpMultiCellBase::GetXFIndexes - vector too small" ); ScfUInt16Vec::iterator aDestIt = rXFIndexes.begin() + GetXclCol(); - for( XclExpMultiXFIdDeq::const_iterator aIt = maXFIds.begin(), aEnd = maXFIds.end(); aIt != aEnd; ++aIt ) + for( const auto& rXFId : maXFIds ) { - ::std::fill( aDestIt, aDestIt + aIt->mnCount, aIt->mnXFIndex ); - aDestIt += aIt->mnCount; + ::std::fill( aDestIt, aDestIt + rXFId.mnCount, rXFId.mnXFIndex ); + aDestIt += rXFId.mnCount; } } @@ -1277,13 +1276,13 @@ void XclExpMultiCellBase::RemoveUnusedXFIndexes( const ScfUInt16Vec& rXFIndexes // build new XF index vector, containing passed XF indexes maXFIds.clear(); - XclExpMultiXFId aXFId( 0 ); - for( ScfUInt16Vec::const_iterator aIt = rXFIndexes.begin() + GetXclCol(), aEnd = rXFIndexes.begin() + nLastXclCol + 1; aIt != aEnd; ++aIt ) - { - // AppendXFId() tests XclExpXFIndex::mnXFId, set it too - aXFId.mnXFId = aXFId.mnXFIndex = *aIt; - AppendXFId( aXFId ); - } + std::for_each(rXFIndexes.begin() + GetXclCol(), rXFIndexes.begin() + nLastXclCol + 1, + [this](const sal_uInt16& rXFIndex) { + XclExpMultiXFId aXFId( 0 ); + // AppendXFId() tests XclExpXFIndex::mnXFId, set it too + aXFId.mnXFId = aXFId.mnXFIndex = rXFIndex; + AppendXFId( aXFId ); + }); // remove leading and trailing unused XF indexes if( !maXFIds.empty() && (maXFIds.front().mnXFIndex == EXC_XF_NOTFOUND) ) @@ -1926,24 +1925,21 @@ void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, bool bProgress ) // *** Find default row format *** ---------------------------------------- - ScfUInt16Vec::iterator aCellBeg = aXFIndexes.begin(), aCellEnd = aXFIndexes.end(), aCellIt; - ScfUInt16Vec::const_iterator aColBeg = rColXFIndexes.begin(), aColIt; - // find most used XF index in the row typedef ::std::map< sal_uInt16, size_t > XclExpXFIndexMap; XclExpXFIndexMap aIndexMap; sal_uInt16 nRowXFIndex = EXC_XF_DEFAULTCELL; size_t nMaxXFCount = 0; const size_t nHalfIndexes = aXFIndexes.size() / 2; - for( aCellIt = aCellBeg; aCellIt != aCellEnd; ++aCellIt ) + for( const auto& rXFIndex : aXFIndexes ) { - if( *aCellIt != EXC_XF_NOTFOUND ) + if( rXFIndex != EXC_XF_NOTFOUND ) { - size_t& rnCount = aIndexMap[ *aCellIt ]; + size_t& rnCount = aIndexMap[ rXFIndex ]; ++rnCount; if( rnCount > nMaxXFCount ) { - nRowXFIndex = *aCellIt; + nRowXFIndex = rXFIndex; nMaxXFCount = rnCount; if (nMaxXFCount > nHalfIndexes) { @@ -1964,9 +1960,10 @@ void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, bool bProgress ) // count needed XF indexes for blank cells with and without row default XF index size_t nXFCountWithRowDefXF = 0; size_t nXFCountWithoutRowDefXF = 0; - for( aCellIt = aCellBeg, aColIt = aColBeg; aCellIt != aCellEnd; ++aCellIt, ++aColIt ) + ScfUInt16Vec::const_iterator aColIt = rColXFIndexes.begin(); + for( const auto& rXFIndex : aXFIndexes ) { - sal_uInt16 nXFIndex = *aCellIt; + sal_uInt16 nXFIndex = rXFIndex; if( nXFIndex != EXC_XF_NOTFOUND ) { if( nXFIndex != nRowXFIndex ) @@ -1974,6 +1971,7 @@ void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, bool bProgress ) if( nXFIndex != *aColIt ) ++nXFCountWithoutRowDefXF; // without row default XF index } + ++aColIt; } // use column XF indexes if this would cause less or equal number of BLANK records @@ -1986,9 +1984,13 @@ void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, bool bProgress ) { // use column default XF indexes // #i194#: remove cell XF indexes equal to column default XF indexes - for( aCellIt = aCellBeg, aColIt = aColBeg; aCellIt != aCellEnd; ++aCellIt, ++aColIt ) - if( *aCellIt == *aColIt ) - *aCellIt = EXC_XF_NOTFOUND; + ScfUInt16Vec::const_iterator aColIt = rColXFIndexes.begin(); + for( auto& rXFIndex : aXFIndexes ) + { + if( rXFIndex == *aColIt ) + rXFIndex = EXC_XF_NOTFOUND; + ++aColIt; + } } else { @@ -1996,9 +1998,9 @@ void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, bool bProgress ) mnXFIndex = nRowXFIndex; ::set_flag( mnFlags, EXC_ROW_USEDEFXF ); // #98133#, #i194#, #i27407#: remove cell XF indexes equal to row default XF index - for( aCellIt = aCellBeg; aCellIt != aCellEnd; ++aCellIt ) - if( *aCellIt == nRowXFIndex ) - *aCellIt = EXC_XF_NOTFOUND; + for( auto& rXFIndex : aXFIndexes ) + if( rXFIndex == nRowXFIndex ) + rXFIndex = EXC_XF_NOTFOUND; } // remove unused parts of BLANK/MULBLANK cell records @@ -2179,9 +2181,8 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt #endif if (nThreads == 1) { - RowMap::iterator itr, itrBeg = maRowMap.begin(), itrEnd = maRowMap.end(); - for (itr = itrBeg; itr != itrEnd; ++itr) - itr->second->Finalize( rColXFIndexes, true ); + for (auto& rEntry : maRowMap) + rEntry.second->Finalize( rColXFIndexes, true ); } else { @@ -2191,10 +2192,12 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt for ( size_t i = 0; i < nThreads; i++ ) aTasks[ i ].reset( new RowFinalizeTask( pTag, rColXFIndexes, i == 0 ) ); - RowMap::iterator itr, itrBeg = maRowMap.begin(), itrEnd = maRowMap.end(); size_t nIdx = 0; - for ( itr = itrBeg; itr != itrEnd; ++itr, ++nIdx ) - aTasks[ nIdx % nThreads ]->push_back( itr->second.get() ); + for ( const auto& rEntry : maRowMap ) + { + aTasks[ nIdx % nThreads ]->push_back( rEntry.second.get() ); + ++nIdx; + } for ( size_t i = 1; i < nThreads; i++ ) rPool.pushTask( std::move(aTasks[ i ]) ); @@ -2217,10 +2220,9 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt XclExpRow* pPrev = nullptr; typedef std::vector< XclExpRow* > XclRepeatedRows; XclRepeatedRows aRepeated; - RowMap::iterator itr, itrBeg = maRowMap.begin(), itrEnd = maRowMap.end(); - for (itr = itrBeg; itr != itrEnd; ++itr) + for (const auto& rEntry : maRowMap) { - const RowRef& rRow = itr->second; + const RowRef& rRow = rEntry.second; if ( rRow->IsDefaultable() ) { XclExpDefaultRowData aDefData( *rRow ); @@ -2259,13 +2261,13 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt rDefRowData = aMaxDefData; // now disable repeating extra (empty) rows that are equal to the default row - for ( XclRepeatedRows::iterator it = aRepeated.begin(), it_end = aRepeated.end(); it != it_end; ++it) + for (auto& rpRow : aRepeated) { - if ( (*it)->GetXclRowRpt() > 1 - && (*it)->GetHeight() == rDefRowData.mnHeight - && (*it)->IsHidden() == rDefRowData.IsHidden() ) + if ( rpRow->GetXclRowRpt() > 1 + && rpRow->GetHeight() == rDefRowData.mnHeight + && rpRow->IsHidden() == rDefRowData.IsHidden() ) { - (*it)->SetXclRowRpt( 1 ); + rpRow->SetXclRowRpt( 1 ); } } @@ -2276,9 +2278,9 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt sal_uInt32 nFirstUsedXclRow = SAL_MAX_UINT32; sal_uInt32 nFirstFreeXclRow = 0; - for (itr = itrBeg; itr != itrEnd; ++itr) + for (const auto& rEntry : maRowMap) { - const RowRef& rRow = itr->second; + const RowRef& rRow = rEntry.second; // disable unused rows rRow->DisableIfDefault( aMaxDefData ); @@ -2314,24 +2316,21 @@ void XclExpRowBuffer::Save( XclExpStream& rStrm ) // save in blocks of 32 rows, each block contains first all ROWs, then all cells size_t nSize = maRowMap.size(); - RowMap::iterator itr, itrBeg = maRowMap.begin(), itrEnd = maRowMap.end(); + RowMap::iterator itr = maRowMap.begin(), itrEnd = maRowMap.end(); RowMap::iterator itrBlkStart = maRowMap.begin(), itrBlkEnd = maRowMap.begin(); - sal_uInt16 nStartXclRow = (nSize == 0) ? 0 : itrBeg->second->GetXclRow(); + sal_uInt16 nStartXclRow = (nSize == 0) ? 0 : itr->second->GetXclRow(); - for (itr = itrBeg; itr != itrEnd; ++itr) + for (; itr != itrEnd; ++itr) { // find end of row block - while( (itrBlkEnd != itrEnd) && (itrBlkEnd->second->GetXclRow() - nStartXclRow < EXC_ROW_ROWBLOCKSIZE) ) - ++itrBlkEnd; + itrBlkEnd = std::find_if_not(itrBlkEnd, itrEnd, + [&nStartXclRow](const RowMap::value_type& rRow) { return rRow.second->GetXclRow() - nStartXclRow < EXC_ROW_ROWBLOCKSIZE; }); // write the ROW records - RowMap::iterator itRow; - for( itRow = itrBlkStart; itRow != itrBlkEnd; ++itRow ) - itRow->second->Save( rStrm ); + std::for_each(itrBlkStart, itrBlkEnd, [&rStrm](const RowMap::value_type& rRow) { rRow.second->Save( rStrm ); }); // write the cell records - for( itRow = itrBlkStart; itRow != itrBlkEnd; ++itRow ) - itRow->second->WriteCellList( rStrm ); + std::for_each(itrBlkStart, itrBlkEnd, [&rStrm](const RowMap::value_type& rRow) { rRow.second->WriteCellList( rStrm ); }); itrBlkStart = (itrBlkEnd == itrEnd) ? itrBlkEnd : itrBlkEnd++; nStartXclRow += EXC_ROW_ROWBLOCKSIZE; @@ -2340,13 +2339,7 @@ void XclExpRowBuffer::Save( XclExpStream& rStrm ) void XclExpRowBuffer::SaveXml( XclExpXmlStream& rStrm ) { - sal_Int32 nNonEmpty = 0; - RowMap::iterator itr = maRowMap.begin(), itrEnd = maRowMap.end(); - for (; itr != itrEnd; ++itr) - if (itr->second->IsEnabled()) - ++nNonEmpty; - - if (nNonEmpty == 0) + if (std::none_of(maRowMap.begin(), maRowMap.end(), [](const RowMap::value_type& rRow) { return rRow.second->IsEnabled(); })) { rStrm.GetCurrentStream()->singleElement( XML_sheetData, FSEND ); return; @@ -2354,8 +2347,8 @@ void XclExpRowBuffer::SaveXml( XclExpXmlStream& rStrm ) sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); rWorksheet->startElement( XML_sheetData, FSEND ); - for (itr = maRowMap.begin(); itr != itrEnd; ++itr) - itr->second->SaveXml(rStrm); + for (const auto& rEntry : maRowMap) + rEntry.second->SaveXml(rStrm); rWorksheet->endElement( XML_sheetData ); } diff --git a/sc/source/filter/excel/xeview.cxx b/sc/source/filter/excel/xeview.cxx index a8504671a1c0..766601c66206 100644 --- a/sc/source/filter/excel/xeview.cxx +++ b/sc/source/filter/excel/xeview.cxx @@ -211,18 +211,17 @@ XclExpSelection::XclExpSelection( const XclTabViewData& rData, sal_uInt8 nPane ) // find the cursor position in the selection list (or add it) XclRangeList& rXclSel = maSelData.maXclSelection; - bool bFound = false; - for( XclRangeVector::const_iterator aIt = rXclSel.begin(), aEnd = rXclSel.end(); !bFound && (aIt != aEnd); ++aIt ) + auto aIt = std::find_if(rXclSel.begin(), rXclSel.end(), + [this](const XclRange& rRange) { return rRange.Contains(maSelData.maXclCursor); }); + if (aIt != rXclSel.end()) { - bFound = aIt->Contains( maSelData.maXclCursor ); - if( bFound ) - maSelData.mnCursorIdx = static_cast< sal_uInt16 >( aIt - rXclSel.begin() ); + maSelData.mnCursorIdx = static_cast< sal_uInt16 >( std::distance(rXclSel.begin(), aIt) ); } - /* Cursor cell not found in list? (e.g. inactive pane, or removed in - ConvertRangeList(), because Calc cursor on invalid pos) - -> insert the valid Excel cursor. */ - if( !bFound ) + else { + /* Cursor cell not found in list? (e.g. inactive pane, or removed in + ConvertRangeList(), because Calc cursor on invalid pos) + -> insert the valid Excel cursor. */ maSelData.mnCursorIdx = static_cast< sal_uInt16 >( rXclSel.size() ); rXclSel.push_back( XclRange( maSelData.maXclCursor ) ); } diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx index 1c5334f04da1..3954dccff2dd 100644 --- a/sc/source/filter/excel/xichart.cxx +++ b/sc/source/filter/excel/xichart.cxx @@ -2910,8 +2910,7 @@ void XclImpChTypeGroup::CreateStockSeries( Reference< XChartType > const & xChar ::std::vector< Reference< XLabeledDataSequence > > aLabeledSeqVec; OSL_ENSURE( maSeries.size() >= 3, "XclImpChTypeGroup::CreateChartType - missing stock series" ); int nRoleIdx = (maSeries.size() == 3) ? 1 : 0; - for( XclImpChSeriesVec::const_iterator aIt = maSeries.begin(), aEnd = maSeries.end(); - (nRoleIdx < 4) && (aIt != aEnd); ++nRoleIdx, ++aIt ) + for( const auto& rxSeries : maSeries ) { // create a data sequence with a specific role OUString aRole; @@ -2922,9 +2921,12 @@ void XclImpChTypeGroup::CreateStockSeries( Reference< XChartType > const & xChar case 2: aRole = EXC_CHPROP_ROLE_LOWVALUES; break; case 3: aRole = EXC_CHPROP_ROLE_CLOSEVALUES; break; } - Reference< XLabeledDataSequence > xDataSeq = (*aIt)->CreateValueSequence( aRole ); + Reference< XLabeledDataSequence > xDataSeq = rxSeries->CreateValueSequence( aRole ); if( xDataSeq.is() ) aLabeledSeqVec.push_back( xDataSeq ); + ++nRoleIdx; + if (nRoleIdx >= 4) + break; } // attach labeled data sequences to series and insert series into chart type @@ -3610,8 +3612,12 @@ XclImpChTypeGroupRef XclImpChAxesSet::GetFirstTypeGroup() const XclImpChLegendRef XclImpChAxesSet::GetLegend() const { XclImpChLegendRef xLegend; - for( XclImpChTypeGroupMap::const_iterator aIt = maTypeGroups.begin(), aEnd = maTypeGroups.end(); !xLegend && (aIt != aEnd); ++aIt ) - xLegend = aIt->second->GetLegend(); + for( const auto& rEntry : maTypeGroups ) + { + xLegend = rEntry.second->GetLegend(); + if (xLegend) + break; + } return xLegend; } @@ -3747,11 +3753,11 @@ Reference< XCoordinateSystem > XclImpChAxesSet::CreateCoordSystem( Reference< XD if( xChartTypeCont.is() ) { sal_Int32 nApiAxesSetIdx = GetApiAxesSetIndex(); - for( XclImpChTypeGroupMap::const_iterator aIt = maTypeGroups.begin(), aEnd = maTypeGroups.end(); aIt != aEnd; ++aIt ) + for( const auto& rEntry : maTypeGroups ) { try { - Reference< XChartType > xChartType = aIt->second->CreateChartType( xDiagram, nApiAxesSetIdx ); + Reference< XChartType > xChartType = rEntry.second->CreateChartType( xDiagram, nApiAxesSetIdx ); if( xChartType.is() ) xChartTypeCont->addChartType( xChartType ); } @@ -4039,8 +4045,8 @@ void XclImpChChart::Convert( const Reference<XChartDocument>& xChartDoc, if( ScChartListenerCollection* pChartCollection = rDoc.GetChartListenerCollection() ) { ::std::unique_ptr< ::std::vector< ScTokenRef > > xRefTokens( new ::std::vector< ScTokenRef > ); - for( XclImpChSeriesVec::const_iterator aIt = maSeries.begin(), aEnd = maSeries.end(); aIt != aEnd; ++aIt ) - (*aIt)->FillAllSourceLinks( *xRefTokens ); + for( const auto& rxSeries : maSeries ) + rxSeries->FillAllSourceLinks( *xRefTokens ); if( !xRefTokens->empty() ) { ::std::unique_ptr< ScChartListener > xListener( new ScChartListener( rObjName, &rDoc, std::move(xRefTokens) ) ); @@ -4119,9 +4125,8 @@ void XclImpChChart::Finalize() void XclImpChChart::FinalizeSeries() { - for( XclImpChSeriesVec::iterator aSIt = maSeries.begin(), aSEnd = maSeries.end(); aSIt != aSEnd; ++aSIt ) + for( const XclImpChSeriesRef& xSeries : maSeries ) { - XclImpChSeriesRef xSeries = *aSIt; if( xSeries->HasParentSeries() ) { /* Process child series (trend lines and error bars). Data of @@ -4148,18 +4153,18 @@ void XclImpChChart::FinalizeDataFormats() itself has collected all CHDATAFORMAT groups to be able to store data format groups for series that have not been imported at that time. This loop finally assigns these groups to the related series. */ - for( XclImpChDataFormatMap::const_iterator aMIt = maDataFmts.begin(), aMEnd = maDataFmts.end(); aMIt != aMEnd; ++aMIt ) + for( const auto& [rPos, rDataFmt] : maDataFmts ) { - sal_uInt16 nSeriesIdx = aMIt->first.mnSeriesIdx; + sal_uInt16 nSeriesIdx = rPos.mnSeriesIdx; if( nSeriesIdx < maSeries.size() ) - maSeries[ nSeriesIdx ]->SetDataFormat( aMIt->second ); + maSeries[ nSeriesIdx ]->SetDataFormat( rDataFmt ); } /* #i51639# (part 2): Finalize data formats of all series. This adds for example missing CHDATAFORMAT groups for entire series that are needed for automatic colors of lines and areas. */ - for( XclImpChSeriesVec::iterator aVIt = maSeries.begin(), aVEnd = maSeries.end(); aVIt != aVEnd; ++aVIt ) - (*aVIt)->FinalizeDataFormats(); + for( auto& rxSeries : maSeries ) + rxSeries->FinalizeDataFormats(); } void XclImpChChart::FinalizeTitle() diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx index 54150dc9a7bc..b34c6b5071aa 100644 --- a/sc/source/filter/excel/xicontent.cxx +++ b/sc/source/filter/excel/xicontent.cxx @@ -725,8 +725,8 @@ void XclImpCondFormatManager::ReadCF( XclImpStream& rStrm ) void XclImpCondFormatManager::Apply() { - for( XclImpCondFmtList::iterator itFmt = maCondFmtList.begin(); itFmt != maCondFmtList.end(); ++itFmt ) - (*itFmt)->Apply(); + for( auto& rxFmt : maCondFmtList ) + rxFmt->Apply(); maCondFmtList.clear(); } @@ -927,10 +927,9 @@ void XclImpValidationManager::ReadDV( XclImpStream& rStrm ) void XclImpValidationManager::Apply() { ScDocument& rDoc = GetRoot().GetDoc(); - DVItemList::iterator itr = maDVItems.begin(), itrEnd = maDVItems.end(); - for (; itr != itrEnd; ++itr) + for (const auto& rxDVItem : maDVItems) { - DVItem& rItem = **itr; + DVItem& rItem = *rxDVItem; // set the handle ID sal_uLong nHandle = rDoc.AddValidationEntry( rItem.maValidData ); ScPatternAttr aPattern( rDoc.GetPool() ); @@ -1088,8 +1087,8 @@ void XclImpWebQueryBuffer::ReadWqtables( XclImpStream& rStrm ) void XclImpWebQueryBuffer::Apply() { ScDocument& rDoc = GetDoc(); - for( XclImpWebQueryList::iterator itQuery = maWQList.begin(); itQuery != maWQList.end(); ++itQuery ) - itQuery->Apply( rDoc, EXC_WEBQRY_FILTER ); + for( auto& rQuery : maWQList ) + rQuery.Apply( rDoc, EXC_WEBQRY_FILTER ); } // Decryption ================================================================= @@ -1383,10 +1382,9 @@ void XclImpSheetProtectBuffer::ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab void XclImpSheetProtectBuffer::Apply() const { - for (ProtectedSheetMap::const_iterator itr = maProtectedSheets.begin(), itrEnd = maProtectedSheets.end(); - itr != itrEnd; ++itr) + for (const auto& [rTab, rSheet] : maProtectedSheets) { - if (!itr->second.mbProtected) + if (!rSheet.mbProtected) // This sheet is (for whatever reason) not protected. continue; @@ -1394,7 +1392,7 @@ void XclImpSheetProtectBuffer::Apply() const pProtect->setProtected(true); // 16-bit hash password - const sal_uInt16 nHash = itr->second.mnPasswordHash; + const sal_uInt16 nHash = rSheet.mnPasswordHash; if (nHash) { Sequence<sal_Int8> aPass(2); @@ -1404,7 +1402,7 @@ void XclImpSheetProtectBuffer::Apply() const } // sheet protection options - const sal_uInt16 nOptions = itr->second.mnOptions; + const sal_uInt16 nOptions = rSheet.mnOptions; pProtect->setOption( ScTableProtection::OBJECTS, (nOptions & 0x0001) ); pProtect->setOption( ScTableProtection::SCENARIOS, (nOptions & 0x0002) ); pProtect->setOption( ScTableProtection::FORMAT_CELLS, (nOptions & 0x0004) ); @@ -1422,10 +1420,10 @@ void XclImpSheetProtectBuffer::Apply() const pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, (nOptions & 0x4000) ); // Enhanced protection containing editable ranges and permissions. - pProtect->setEnhancedProtection( itr->second.maEnhancedProtections); + pProtect->setEnhancedProtection( rSheet.maEnhancedProtections); // all done. now commit. - GetDoc().SetTabProtection(itr->first, pProtect.get()); + GetDoc().SetTabProtection(rTab, pProtect.get()); } } diff --git a/sc/source/filter/excel/xiescher.cxx b/sc/source/filter/excel/xiescher.cxx index 247f074b3c0f..db4ec7e1bfa3 100644 --- a/sc/source/filter/excel/xiescher.cxx +++ b/sc/source/filter/excel/xiescher.cxx @@ -110,6 +110,7 @@ #include <namebuff.hxx> #include <sfx2/docfile.hxx> #include <memory> +#include <numeric> #include <utility> using namespace com::sun::star; @@ -954,10 +955,8 @@ void XclImpDrawObjVector::InsertGrouped( XclImpDrawObjRef const & xDrawObj ) std::size_t XclImpDrawObjVector::GetProgressSize() const { - std::size_t nProgressSize = 0; - for( ::std::vector< XclImpDrawObjRef >::const_iterator aIt = mObjs.begin(), aEnd = mObjs.end(); aIt != aEnd; ++aIt ) - nProgressSize += (*aIt)->GetProgressSize(); - return nProgressSize; + return std::accumulate(mObjs.begin(), mObjs.end(), std::size_t(0), + [](const std::size_t& rSum, const XclImpDrawObjRef& rxObj) { return rSum + rxObj->GetProgressSize(); }); } XclImpPhObj::XclImpPhObj( const XclImpRoot& rRoot ) : @@ -1018,8 +1017,8 @@ SdrObjectUniquePtr XclImpGroupObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, *GetDoc().GetDrawLayer())); // child objects in BIFF2-BIFF5 have absolute size, not needed to pass own anchor rectangle SdrObjList& rObjList = *xSdrObj->GetSubList(); // SdrObjGroup always returns existing sublist - for( ::std::vector< XclImpDrawObjRef >::const_iterator aIt = maChildren.begin(), aEnd = maChildren.end(); aIt != aEnd; ++aIt ) - rDffConv.ProcessObject( rObjList, **aIt ); + for( const auto& rxChild : maChildren ) + rDffConv.ProcessObject( rObjList, *rxChild ); rDffConv.Progress(); return xSdrObj; } @@ -1371,8 +1370,8 @@ SdrObjectUniquePtr XclImpPolygonObj::DoCreateSdrObj( XclImpDffConverter& rDffCon { // create the polygon ::basegfx::B2DPolygon aB2DPolygon; - for( PointVector::const_iterator aIt = maCoords.begin(), aEnd = maCoords.end(); aIt != aEnd; ++aIt ) - aB2DPolygon.append( lclGetPolyPoint( rAnchorRect, *aIt ) ); + for( const auto& rCoord : maCoords ) + aB2DPolygon.append( lclGetPolyPoint( rAnchorRect, rCoord ) ); // close polygon if specified if( ::get_flag( mnPolyFlags, EXC_OBJ_POLY_CLOSED ) && (maCoords.front() != maCoords.back()) ) aB2DPolygon.append( lclGetPolyPoint( rAnchorRect, maCoords.front() ) ); @@ -2737,9 +2736,13 @@ void XclImpListBoxObj::DoProcessControl( ScfPropertySet& rPropSet ) const // multi selection: API expects sequence of list entry indexes if( bMultiSel ) { - for( ScfUInt8Vec::const_iterator aBeg = maSelection.begin(), aIt = aBeg, aEnd = maSelection.end(); aIt != aEnd; ++aIt ) - if( *aIt != 0 ) - aSelVec.push_back( static_cast< sal_Int16 >( aIt - aBeg ) ); + sal_Int16 nIndex = 0; + for( const auto& rItem : maSelection ) + { + if( rItem != 0 ) + aSelVec.push_back( nIndex ); + ++nIndex; + } } // single selection: mnSelEntry is one-based, API expects zero-based else if( mnSelEntry > 0 ) @@ -3352,8 +3355,8 @@ void XclImpDffConverter::ProcessObject( SdrObjList& rObjList, const XclImpDrawOb void XclImpDffConverter::ProcessDrawing( const XclImpDrawObjVector& rDrawObjs ) { SdrPage& rSdrPage = GetConvData().mrSdrPage; - for( ::std::vector< XclImpDrawObjRef >::const_iterator aIt = rDrawObjs.begin(), aEnd = rDrawObjs.end(); aIt != aEnd; ++aIt ) - ProcessObject( rSdrPage, **aIt ); + for( const auto& rxDrawObj : rDrawObjs ) + ProcessObject( rSdrPage, *rxDrawObj ); } void XclImpDffConverter::ProcessDrawing( SvStream& rDffStrm ) @@ -4000,10 +4003,8 @@ void XclImpDrawing::SetSkipObj( sal_uInt16 nObjId ) std::size_t XclImpDrawing::GetProgressSize() const { - std::size_t nProgressSize = maRawObjs.GetProgressSize(); - for( XclImpObjMap::const_iterator aIt = maObjMap.begin(), aEnd = maObjMap.end(); aIt != aEnd; ++aIt ) - nProgressSize += aIt->second->GetProgressSize(); - return nProgressSize; + return std::accumulate(maObjMap.begin(), maObjMap.end(), maRawObjs.GetProgressSize(), + [](const std::size_t& rSum, const XclImpObjMap::value_type& rEntry) { return rSum + rEntry.second->GetProgressSize(); }); } void XclImpDrawing::ImplConvertObjects( XclImpDffConverter& rDffConv, SdrModel& rSdrModel, SdrPage& rSdrPage ) @@ -4015,8 +4016,8 @@ void XclImpDrawing::ImplConvertObjects( XclImpDffConverter& rDffConv, SdrModel& // register this drawing manager at the passed (global) DFF manager rDffConv.InitializeDrawing( *this, rSdrModel, rSdrPage ); // process list of objects to be skipped - for( ScfUInt16Vec::const_iterator aIt = maSkipObjs.begin(), aEnd = maSkipObjs.end(); aIt != aEnd; ++aIt ) - if( XclImpDrawObjBase* pDrawObj = FindDrawObj( *aIt ).get() ) + for( const auto& rSkipObj : maSkipObjs ) + if( XclImpDrawObjBase* pDrawObj = FindDrawObj( rSkipObj ).get() ) pDrawObj->SetProcessSdrObj( false ); // process drawing objects without DFF data rDffConv.ProcessDrawing( maRawObjs ); @@ -4298,17 +4299,16 @@ void XclImpObjectManager::ConvertObjects() return; // get total progress bar size for all sheet drawing managers - std::size_t nProgressSize = 0; - for( XclImpSheetDrawingMap::iterator aIt = maSheetDrawings.begin(), aEnd = maSheetDrawings.end(); aIt != aEnd; ++aIt ) - nProgressSize += aIt->second->GetProgressSize(); + std::size_t nProgressSize = std::accumulate(maSheetDrawings.begin(), maSheetDrawings.end(), std::size_t(0), + [](const std::size_t& rSum, const XclImpSheetDrawingMap::value_type& rEntry) { return rSum + rEntry.second->GetProgressSize(); }); // nothing to do if progress bar is zero (no objects present) if( nProgressSize == 0 ) return; XclImpDffConverter aDffConv( GetRoot(), maDggStrm ); aDffConv.StartProgressBar( nProgressSize ); - for( XclImpSheetDrawingMap::iterator aIt = maSheetDrawings.begin(), aEnd = maSheetDrawings.end(); aIt != aEnd; ++aIt ) - aIt->second->ConvertObjects( aDffConv ); + for( auto& rEntry : maSheetDrawings ) + rEntry.second->ConvertObjects( aDffConv ); // #i112436# don't call ScChartListenerCollection::SetDirty here, // instead use InterpretDirtyCells in ScDocument::CalcAfterLoad. diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx index 694b1c2b3120..90d0d10ea807 100644 --- a/sc/source/filter/excel/xihelper.cxx +++ b/sc/source/filter/excel/xihelper.cxx @@ -126,10 +126,10 @@ void XclImpAddressConverter::ConvertRangeList( ScRangeList& rScRanges, const XclRangeList& rXclRanges, SCTAB nScTab, bool bWarn ) { rScRanges.RemoveAll(); - for( XclRangeVector::const_iterator aIt = rXclRanges.begin(), aEnd = rXclRanges.end(); aIt != aEnd; ++aIt ) + for( const auto& rXclRange : rXclRanges ) { ScRange aScRange( ScAddress::UNINITIALIZED ); - if( ConvertRange( aScRange, *aIt, nScTab, nScTab, bWarn ) ) + if( ConvertRange( aScRange, rXclRange, nScTab, nScTab, bWarn ) ) rScRanges.push_back( aScRange ); } } diff --git a/sc/source/filter/excel/xilink.cxx b/sc/source/filter/excel/xilink.cxx index 5c2337310ab5..653def1be9b9 100644 --- a/sc/source/filter/excel/xilink.cxx +++ b/sc/source/filter/excel/xilink.cxx @@ -223,9 +223,9 @@ void XclImpTabInfo::AppendXclTabName( const OUString& rXclTabName, SCTAB nScTab void XclImpTabInfo::InsertScTab( SCTAB nScTab ) { - for( XclTabNameMap::iterator aIt = maTabNames.begin(), aEnd = maTabNames.end(); aIt != aEnd; ++aIt ) - if( aIt->second >= nScTab ) - ++aIt->second; + for( auto& rEntry : maTabNames ) + if( rEntry.second >= nScTab ) + ++rEntry.second; } SCTAB XclImpTabInfo::GetScTabFromXclName( const OUString& rXclTabName ) const @@ -255,9 +255,8 @@ void XclImpTabInfo::ReadTabid( XclImpStream& rStrm ) sal_uInt16 XclImpTabInfo::GetCurrentIndex( sal_uInt16 nCreatedId, sal_uInt16 nMaxTabId ) const { sal_uInt16 nReturn = 0; - for( ScfUInt16Vec::const_iterator aIt = maTabIdVec.begin(), aEnd = maTabIdVec.end(); aIt != aEnd; ++aIt ) + for( sal_uInt16 nValue : maTabIdVec ) { - sal_uInt16 nValue = *aIt; if( nValue == nCreatedId ) return nReturn; if( nValue <= nMaxTabId ) @@ -569,9 +568,9 @@ void XclImpSupbookTab::LoadCachedValues( const ScExternalRefCache::TableTypeRef& if (maCrnList.empty()) return; - for (XclImpCrnList::iterator itCrnRef = maCrnList.begin(); itCrnRef != maCrnList.end(); ++itCrnRef) + for (const auto& rxCrn : maCrnList) { - const XclImpCrn* const pCrn = itCrnRef->get(); + const XclImpCrn* const pCrn = rxCrn.get(); const XclAddress& rAddr = pCrn->GetAddress(); switch (pCrn->GetType()) { @@ -739,11 +738,11 @@ void XclImpSupbook::LoadCachedValues() ScExternalRefManager* pRefMgr = GetRoot().GetDoc().GetExternalRefManager(); sal_uInt16 nFileId = pRefMgr->getExternalFileId(aAbsUrl); - for (XclImpSupbookTabList::iterator itTab = maSupbTabList.begin(); itTab != maSupbTabList.end(); ++itTab) + for (auto& rxTab : maSupbTabList) { - const OUString& rTabName = (*itTab)->GetTabName(); + const OUString& rTabName = rxTab->GetTabName(); ScExternalRefCache::TableTypeRef pCacheTable = pRefMgr->getCacheTable(nFileId, rTabName, true); - (*itTab)->LoadCachedValues( pCacheTable, GetSharedStringPool()); + rxTab->LoadCachedValues( pCacheTable, GetSharedStringPool()); pCacheTable->setWholeTableCached(); } } @@ -772,8 +771,12 @@ void XclImpLinkManagerImpl::ReadExternsheet( XclImpStream& rStrm ) insert the entries of the second record before the entries of the first record. */ XclImpXtiVector aNewEntries( nXtiCount ); - for( XclImpXtiVector::iterator aIt = aNewEntries.begin(), aEnd = aNewEntries.end(); rStrm.IsValid() && (aIt != aEnd); ++aIt ) - rStrm >> *aIt; + for( auto& rNewEntry : aNewEntries ) + { + if (!rStrm.IsValid()) + break; + rStrm >> rNewEntry; + } maXtiList.insert( maXtiList.begin(), aNewEntries.begin(), aNewEntries.end() ); LoadCachedValues(); @@ -874,8 +877,8 @@ void XclImpLinkManagerImpl::LoadCachedValues() { // Read all CRN records which can be accessed via XclImpSupbook, and store // the cached values to the external reference manager. - for (XclImpSupbookList::iterator itSupbook = maSupbookList.begin(); itSupbook != maSupbookList.end(); ++itSupbook) - (*itSupbook)->LoadCachedValues(); + for (auto& rxSupbook : maSupbookList) + rxSupbook->LoadCachedValues(); } XclImpLinkManager::XclImpLinkManager( const XclImpRoot& rRoot ) : diff --git a/sc/source/filter/excel/xiname.cxx b/sc/source/filter/excel/xiname.cxx index 6e20ab6dc425..4f168cf8fd95 100644 --- a/sc/source/filter/excel/xiname.cxx +++ b/sc/source/filter/excel/xiname.cxx @@ -291,15 +291,18 @@ const XclImpName* XclImpNameManager::FindName( const OUString& rXclName, SCTAB n { const XclImpName* pGlobalName = nullptr; // a found global name const XclImpName* pLocalName = nullptr; // a found local name - for( XclImpNameList::const_iterator itName = maNameList.begin(); itName != maNameList.end() && !pLocalName; ++itName ) + for( const auto& rxName : maNameList ) { - if( (*itName)->GetXclName() == rXclName ) + if( rxName->GetXclName() == rXclName ) { - if( (*itName)->GetScTab() == nScTab ) - pLocalName = itName->get(); - else if( (*itName)->IsGlobal() ) - pGlobalName = itName->get(); + if( rxName->GetScTab() == nScTab ) + pLocalName = rxName.get(); + else if( rxName->IsGlobal() ) + pGlobalName = rxName.get(); } + + if (pLocalName) + break; } return pLocalName ? pLocalName : pGlobalName; } @@ -312,9 +315,8 @@ const XclImpName* XclImpNameManager::GetName( sal_uInt16 nXclNameIdx ) const void XclImpNameManager::ConvertAllTokens() { - XclImpNameList::iterator it = maNameList.begin(), itEnd = maNameList.end(); - for (; it != itEnd; ++it) - (*it)->ConvertTokens(); + for (auto& rxName : maNameList) + rxName->ConvertTokens(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/excel/xipage.cxx b/sc/source/filter/excel/xipage.cxx index 526a8e355e9b..0864c167287e 100644 --- a/sc/source/filter/excel/xipage.cxx +++ b/sc/source/filter/excel/xipage.cxx @@ -368,18 +368,16 @@ void XclImpPageSettings::Finalize() // *** page breaks *** - ScfUInt16Vec::const_iterator aIt, aEnd; - - for( aIt = maData.maHorPageBreaks.begin(), aEnd = maData.maHorPageBreaks.end(); aIt != aEnd; ++aIt ) + for( const auto& rHorPageBreak : maData.maHorPageBreaks ) { - SCROW nScRow = static_cast< SCROW >( *aIt ); + SCROW nScRow = static_cast< SCROW >( rHorPageBreak ); if( nScRow <= MAXROW ) rDoc.SetRowBreak(nScRow, nScTab, false, true); } - for( aIt = maData.maVerPageBreaks.begin(), aEnd = maData.maVerPageBreaks.end(); aIt != aEnd; ++aIt ) + for( const auto& rVerPageBreak : maData.maVerPageBreaks ) { - SCCOL nScCol = static_cast< SCCOL >( *aIt ); + SCCOL nScCol = static_cast< SCCOL >( rVerPageBreak ); if( nScCol <= MAXCOL ) rDoc.SetColBreak(nScCol, nScTab, false, true); } diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx index b3448485b0a8..37ca835669b7 100644 --- a/sc/source/filter/excel/xipivot.cxx +++ b/sc/source/filter/excel/xipivot.cxx @@ -414,8 +414,8 @@ void XclImpPCField::ConvertStdGroupField( ScDPSaveData& rSaveData, const ScfStri ScDPSaveGroupItemVec aGroupItems; aGroupItems.reserve( maItems.size() ); // initialize with own item names - for( XclImpPCItemVec::const_iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt ) - aGroupItems.emplace_back( (*aIt)->ConvertToText() ); + for( const auto& rxItem : maItems ) + aGroupItems.emplace_back( rxItem->ConvertToText() ); // *** iterate over all base items, set their names at corresponding own items *** for( sal_uInt16 nItemIdx = 0, nItemCount = static_cast< sal_uInt16 >( maGroupOrder.size() ); nItemIdx < nItemCount; ++nItemIdx ) @@ -427,9 +427,9 @@ void XclImpPCField::ConvertStdGroupField( ScDPSaveData& rSaveData, const ScfStri // *** create the ScDPSaveGroupDimension object, fill with grouping info *** ScDPSaveGroupDimension aGroupDim( rBaseFieldName, GetFieldName( rVisNames ) ); - for( ScDPSaveGroupItemVec::const_iterator aIt = aGroupItems.begin(), aEnd = aGroupItems.end(); aIt != aEnd; ++aIt ) - if( !aIt->IsEmpty() ) - aGroupDim.AddGroupItem( *aIt ); + for( const auto& rGroupItem : aGroupItems ) + if( !rGroupItem.IsEmpty() ) + aGroupDim.AddGroupItem( rGroupItem ); rSaveData.GetDimensionData()->AddGroupDimension( aGroupDim ); } } @@ -768,10 +768,10 @@ void XclImpPivotCache::ReadPivotCacheStream( const XclImpStream& rStrm ) // read index list and insert all items into generated source data if( bGenerateSource && (nItemScRow <= MAXROW) && (++nItemScRow <= MAXROW) ) { - for( XclImpPCFieldVec::const_iterator aIt = aOrigFields.begin(), aEnd = aOrigFields.end(); aIt != aEnd; ++aIt ) + for( const auto& rxOrigField : aOrigFields ) { - sal_uInt16 nItemIdx = (*aIt)->Has16BitIndexes() ? aPCStrm.ReaduInt16() : aPCStrm.ReaduInt8(); - (*aIt)->WriteOrigItemToSource( nItemScRow, nScTab, nItemIdx ); + sal_uInt16 nItemIdx = rxOrigField->Has16BitIndexes() ? aPCStrm.ReaduInt16() : aPCStrm.ReaduInt8(); + rxOrigField->WriteOrigItemToSource( nItemScRow, nScTab, nItemIdx ); } } xCurrField.reset(); @@ -1183,8 +1183,8 @@ void XclImpPTField::ConvertFieldInfo( const ScDPSaveData& rSaveData, ScDPObject* return; pSaveDim->SetShowEmpty( ::get_flag( maFieldExtInfo.mnFlags, EXC_SXVDEX_SHOWALL ) ); - for( XclImpPTItemVec::const_iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt ) - (*aIt)->ConvertItem( *pSaveDim, pObj, rRoot ); + for( const auto& rxItem : maItems ) + rxItem->ConvertItem( *pSaveDim, pObj, rRoot ); if(bPageField && maPageInfo.mnSelItem != EXC_SXPI_ALLITEMS) { @@ -1422,21 +1422,19 @@ void XclImpPivotTable::Convert() // *** fields *** - ScfUInt16Vec::const_iterator aIt, aEnd; - // row fields - for( aIt = maRowFields.begin(), aEnd = maRowFields.end(); aIt != aEnd; ++aIt ) - if( const XclImpPTField* pField = GetField( *aIt ) ) + for( const auto& rRowField : maRowFields ) + if( const XclImpPTField* pField = GetField( rRowField ) ) pField->ConvertRowColField( aSaveData ); // column fields - for( aIt = maColFields.begin(), aEnd = maColFields.end(); aIt != aEnd; ++aIt ) - if( const XclImpPTField* pField = GetField( *aIt ) ) + for( const auto& rColField : maColFields ) + if( const XclImpPTField* pField = GetField( rColField ) ) pField->ConvertRowColField( aSaveData ); // page fields - for( aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt ) - if( const XclImpPTField* pField = GetField( *aIt ) ) + for( const auto& rPageField : maPageFields ) + if( const XclImpPTField* pField = GetField( rPageField ) ) pField->ConvertPageField( aSaveData ); // We need to import hidden fields because hidden fields may contain @@ -1450,8 +1448,8 @@ void XclImpPivotTable::Convert() pField->ConvertHiddenField( aSaveData ); // data fields - for( aIt = maFiltDataFields.begin(), aEnd = maFiltDataFields.end(); aIt != aEnd; ++aIt ) - if( const XclImpPTField* pField = GetField( *aIt ) ) + for( const auto& rFiltDataField : maFiltDataFields ) + if( const XclImpPTField* pField = GetField( rFiltDataField ) ) pField->ConvertDataField( aSaveData ); // *** insert into Calc document *** @@ -1529,27 +1527,24 @@ void XclImpPivotTable::ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveD vector<ScAddress> aFieldBtns; aGeometry.getPageFieldPositions(aFieldBtns); - vector<ScAddress>::const_iterator itr = aFieldBtns.begin(), itrEnd = aFieldBtns.end(); - for (; itr != itrEnd; ++itr) + for (const auto& rFieldBtn : aFieldBtns) { - rDoc.ApplyFlagsTab(itr->Col(), itr->Row(), itr->Col(), itr->Row(), itr->Tab(), ScMF::Button); + rDoc.ApplyFlagsTab(rFieldBtn.Col(), rFieldBtn.Row(), rFieldBtn.Col(), rFieldBtn.Row(), rFieldBtn.Tab(), ScMF::Button); ScMF nMFlag = ScMF::ButtonPopup; - OUString aName = rDoc.GetString(itr->Col(), itr->Row(), itr->Tab()); + OUString aName = rDoc.GetString(rFieldBtn.Col(), rFieldBtn.Row(), rFieldBtn.Tab()); if (rSaveData.HasInvisibleMember(aName)) nMFlag |= ScMF::HiddenMember; - rDoc.ApplyFlagsTab(itr->Col()+1, itr->Row(), itr->Col()+1, itr->Row(), itr->Tab(), nMFlag); + rDoc.ApplyFlagsTab(rFieldBtn.Col()+1, rFieldBtn.Row(), rFieldBtn.Col()+1, rFieldBtn.Row(), rFieldBtn.Tab(), nMFlag); } aGeometry.getColumnFieldPositions(aFieldBtns); rSaveData.GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aFieldDims); if (aFieldBtns.size() == aFieldDims.size()) { - itr = aFieldBtns.begin(); - itrEnd = aFieldBtns.end(); vector<const ScDPSaveDimension*>::const_iterator itDim = aFieldDims.begin(); - for (; itr != itrEnd; ++itr, ++itDim) + for (const auto& rFieldBtn : aFieldBtns) { ScMF nMFlag = ScMF::Button; const ScDPSaveDimension* pDim = *itDim; @@ -1557,7 +1552,8 @@ void XclImpPivotTable::ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveD nMFlag |= ScMF::HiddenMember; if (!pDim->IsDataLayout()) nMFlag |= ScMF::ButtonPopup; - rDoc.ApplyFlagsTab(itr->Col(), itr->Row(), itr->Col(), itr->Row(), itr->Tab(), nMFlag); + rDoc.ApplyFlagsTab(rFieldBtn.Col(), rFieldBtn.Row(), rFieldBtn.Col(), rFieldBtn.Row(), rFieldBtn.Tab(), nMFlag); + ++itDim; } } @@ -1565,10 +1561,8 @@ void XclImpPivotTable::ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveD rSaveData.GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aFieldDims); if ((aFieldBtns.size() == aFieldDims.size()) || (maPTAddlInfo.mbCompactMode && aFieldBtns.size() == 1)) { - itr = aFieldBtns.begin(); - itrEnd = aFieldBtns.end(); vector<const ScDPSaveDimension*>::const_iterator itDim = aFieldDims.begin(); - for (; itr != itrEnd; ++itr) + for (const auto& rFieldBtn : aFieldBtns) { ScMF nMFlag = ScMF::Button; const ScDPSaveDimension* pDim = itDim != aFieldDims.end() ? *itDim++ : nullptr; @@ -1576,7 +1570,7 @@ void XclImpPivotTable::ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveD nMFlag |= ScMF::HiddenMember; if (!pDim || !pDim->IsDataLayout()) nMFlag |= ScMF::ButtonPopup; - rDoc.ApplyFlagsTab(itr->Col(), itr->Row(), itr->Col(), itr->Row(), itr->Tab(), nMFlag); + rDoc.ApplyFlagsTab(rFieldBtn.Col(), rFieldBtn.Row(), rFieldBtn.Col(), rFieldBtn.Row(), rFieldBtn.Tab(), nMFlag); } } } @@ -1588,18 +1582,18 @@ void XclImpPivotTable::ApplyFieldInfo() ScDPSaveData& rSaveData = *mpDPObj->GetSaveData(); // row fields - for( auto aIt = maRowFields.begin(), aEnd = maRowFields.end(); aIt != aEnd; ++aIt ) - if( const XclImpPTField* pField = GetField( *aIt ) ) + for( const auto& rRowField : maRowFields ) + if( const XclImpPTField* pField = GetField( rRowField ) ) pField->ConvertFieldInfo( rSaveData, mpDPObj, *this ); // column fields - for( auto aIt = maColFields.begin(), aEnd = maColFields.end(); aIt != aEnd; ++aIt ) - if( const XclImpPTField* pField = GetField( *aIt ) ) + for( const auto& rColField : maColFields ) + if( const XclImpPTField* pField = GetField( rColField ) ) pField->ConvertFieldInfo( rSaveData, mpDPObj, *this ); // page fields - for( auto aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt ) - if( const XclImpPTField* pField = GetField( *aIt ) ) + for( const auto& rPageField : maPageFields ) + if( const XclImpPTField* pField = GetField( rPageField ) ) pField->ConvertFieldInfo( rSaveData, mpDPObj, *this, true ); // hidden fields @@ -1718,20 +1712,20 @@ void XclImpPivotTableManager::ReadSxAddl( XclImpStream& rStrm ) void XclImpPivotTableManager::ReadPivotCaches( const XclImpStream& rStrm ) { - for( XclImpPivotCacheVec::iterator aIt = maPCaches.begin(), aEnd = maPCaches.end(); aIt != aEnd; ++aIt ) - (*aIt)->ReadPivotCacheStream( rStrm ); + for( auto& rxPCache : maPCaches ) + rxPCache->ReadPivotCacheStream( rStrm ); } void XclImpPivotTableManager::ConvertPivotTables() { - for( XclImpPivotTableVec::iterator aIt = maPTables.begin(), aEnd = maPTables.end(); aIt != aEnd; ++aIt ) - (*aIt)->Convert(); + for( auto& rxPTable : maPTables ) + rxPTable->Convert(); } void XclImpPivotTableManager::MaybeRefreshPivotTables() { - for( XclImpPivotTableVec::iterator aIt = maPTables.begin(), aEnd = maPTables.end(); aIt != aEnd; ++aIt ) - (*aIt)->MaybeRefresh(); + for( auto& rxPTable : maPTables ) + rxPTable->MaybeRefresh(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/excel/xistream.cxx b/sc/source/filter/excel/xistream.cxx index e48d596bd5ef..f58e53282690 100644 --- a/sc/source/filter/excel/xistream.cxx +++ b/sc/source/filter/excel/xistream.cxx @@ -146,9 +146,12 @@ uno::Sequence< beans::NamedValue > XclImpBiff5Decrypter::OnVerifyPassword( const // since the export uses Std97 encryption always we have to request it here ::std::vector< sal_uInt16 > aPassVect( 16 ); - ::std::vector< sal_uInt16 >::iterator aIt = aPassVect.begin(); - for( sal_Int32 nInd = 0; nInd < nLen; ++nInd, ++aIt ) - *aIt = static_cast< sal_uInt16 >( rPassword[nInd] ); + sal_Int32 nInd = 0; + std::for_each(aPassVect.begin(), aPassVect.begin() + nLen, + [&rPassword, &nInd](sal_uInt16& rPass) { + rPass = static_cast< sal_uInt16 >( rPassword[nInd] ); + ++nInd; + }); uno::Sequence< sal_Int8 > aDocId = ::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 ); OSL_ENSURE( aDocId.getLength() == 16, "Unexpected length of the sequence!" ); @@ -251,10 +254,11 @@ uno::Sequence< beans::NamedValue > XclImpBiff8Decrypter::OnVerifyPassword( const // copy string to sal_uInt16 array ::std::vector< sal_uInt16 > aPassVect( 16 ); const sal_Unicode* pcChar = rPassword.getStr(); - const sal_Unicode* pcCharEnd = pcChar + nLen; - ::std::vector< sal_uInt16 >::iterator aIt = aPassVect.begin(); - for( ; pcChar < pcCharEnd; ++pcChar, ++aIt ) - *aIt = static_cast< sal_uInt16 >( *pcChar ); + std::for_each(aPassVect.begin(), aPassVect.begin() + nLen, + [&pcChar](sal_uInt16& rPass) { + rPass = static_cast< sal_uInt16 >( *pcChar ); + ++pcChar; + }); // init codec mpCodec->InitKey(aPassVect.data(), maSalt.data()); diff --git a/sc/source/filter/excel/xistyle.cxx b/sc/source/filter/excel/xistyle.cxx index 40eea2516b45..81df8e573b24 100644 --- a/sc/source/filter/excel/xistyle.cxx +++ b/sc/source/filter/excel/xistyle.cxx @@ -691,10 +691,8 @@ void XclImpNumFmtBuffer::CreateScFormats() OSL_ENSURE( maIndexMap.empty(), "XclImpNumFmtBuffer::CreateScFormats - already created" ); SvNumberFormatter& rFormatter = GetFormatter(); - for( XclNumFmtMap::const_iterator aIt = GetFormatMap().begin(), aEnd = GetFormatMap().end(); aIt != aEnd; ++aIt ) + for( const auto& [rXclNumFmt, rNumFmt] : GetFormatMap() ) { - const XclNumFmt& rNumFmt = aIt->second; - // insert/convert the Excel number format sal_Int32 nCheckPos; SvNumFormatType nType = SvNumFormatType::DEFINED; @@ -709,7 +707,7 @@ void XclImpNumFmtBuffer::CreateScFormats() nKey = rFormatter.GetFormatIndex( rNumFmt.meOffset, rNumFmt.meLanguage ); // insert the resulting format key into the Excel->Calc index map - maIndexMap[ aIt->first ] = nKey; + maIndexMap[ rXclNumFmt ] = nKey; } } @@ -1626,35 +1624,34 @@ void XclImpXFBuffer::CreateUserStyles() /* Calculate names of built-in styles. Store styles with reserved names in the aConflictNameStyles list. */ - for( XclImpStyleList::iterator itStyle = maBuiltinStyles.begin(); itStyle != maBuiltinStyles.end(); ++itStyle ) + for( const auto& rxStyle : maBuiltinStyles ) { - OUString aStyleName = XclTools::GetBuiltInStyleName( (*itStyle)->GetBuiltinId(), (*itStyle)->GetName(), (*itStyle)->GetLevel() ); + OUString aStyleName = XclTools::GetBuiltInStyleName( rxStyle->GetBuiltinId(), rxStyle->GetName(), rxStyle->GetLevel() ); OSL_ENSURE( bReserveAll || (aCellStyles.count( aStyleName ) == 0), "XclImpXFBuffer::CreateUserStyles - multiple styles with equal built-in identifier" ); if( aCellStyles.count( aStyleName ) > 0 ) - aConflictNameStyles.push_back( itStyle->get() ); + aConflictNameStyles.push_back( rxStyle.get() ); else - aCellStyles[ aStyleName ] = itStyle->get(); + aCellStyles[ aStyleName ] = rxStyle.get(); } /* Calculate names of user defined styles. Store styles with reserved names in the aConflictNameStyles list. */ - for( XclImpStyleList::iterator itStyle = maUserStyles.begin(); itStyle != maUserStyles.end(); ++itStyle ) + for( const auto& rxStyle : maUserStyles ) { // #i1624# #i1768# ignore unnamed user styles - if( !(*itStyle)->GetName().isEmpty() ) + if( !rxStyle->GetName().isEmpty() ) { - if( aCellStyles.count( (*itStyle)->GetName() ) > 0 ) - aConflictNameStyles.push_back( itStyle->get() ); + if( aCellStyles.count( rxStyle->GetName() ) > 0 ) + aConflictNameStyles.push_back( rxStyle.get() ); else - aCellStyles[ (*itStyle)->GetName() ] = itStyle->get(); + aCellStyles[ rxStyle->GetName() ] = rxStyle.get(); } } // find unused names for all styles with conflicting names - for( XclImpStyleVector::iterator aIt = aConflictNameStyles.begin(), aEnd = aConflictNameStyles.end(); aIt != aEnd; ++aIt ) + for( XclImpStyle* pStyle : aConflictNameStyles ) { - XclImpStyle* pStyle = *aIt; OUString aUnusedName; sal_Int32 nIndex = 0; do @@ -1666,9 +1663,9 @@ void XclImpXFBuffer::CreateUserStyles() } // set final names and create user-defined and modified built-in cell styles - for( CellStyleNameMap::iterator aIt = aCellStyles.begin(), aEnd = aCellStyles.end(); aIt != aEnd; ++aIt ) - if( aIt->second ) - aIt->second->CreateUserStyle( aIt->first ); + for( auto& [rStyleName, rpStyle] : aCellStyles ) + if( rpStyle ) + rpStyle->CreateUserStyle( rStyleName ); } ScStyleSheet* XclImpXFBuffer::CreateStyleSheet( sal_uInt16 nXFIndex ) @@ -1982,20 +1979,19 @@ void XclImpXFRangeBuffer::Finalize() // apply patterns XclImpXFBuffer& rXFBuffer = GetXFBuffer(); - for( XclImpXFRangeColumnVec::const_iterator aVBeg = maColumns.begin(), aVEnd = maColumns.end(), aVIt = aVBeg; aVIt != aVEnd; ++aVIt ) + SCCOL nScCol = 0; + for( const auto& rxColumn : maColumns ) { // apply all cell styles of an existing column - if( aVIt->get() ) + if( rxColumn.get() ) { - XclImpXFRangeColumn& rColumn = **aVIt; - SCCOL nScCol = static_cast< SCCOL >( aVIt - aVBeg ); + XclImpXFRangeColumn& rColumn = *rxColumn; std::vector<ScAttrEntry> aAttrs; aAttrs.reserve(rColumn.end() - rColumn.begin()); - for (XclImpXFRangeColumn::IndexList::iterator itr = rColumn.begin(), itrEnd = rColumn.end(); - itr != itrEnd; ++itr) + for (const auto& rxStyle : rColumn) { - XclImpXFRange& rStyle = **itr; + XclImpXFRange& rStyle = *rxStyle; const XclImpXFIndex& rXFIndex = rStyle.maXFIndex; XclImpXF* pXF = rXFBuffer.GetXF( rXFIndex.GetXFIndex() ); if (!pXF) @@ -2022,11 +2018,12 @@ void XclImpXFRangeBuffer::Finalize() aAttrParam.mbLatinNumFmtOnly = false; // when unsure, set it to false. rDoc.setAttrEntries(nScTab, nScCol, std::move(aAttrParam)); } + ++nScCol; } // insert hyperlink cells - for( XclImpHyperlinkVector::const_iterator aLIt = maHyperlinks.begin(), aLEnd = maHyperlinks.end(); aLIt != aLEnd; ++aLIt ) - XclImpHyperlink::InsertUrl( GetRoot(), aLIt->first, aLIt->second ); + for( const auto& [rXclRange, rUrl] : maHyperlinks ) + XclImpHyperlink::InsertUrl( GetRoot(), rXclRange, rUrl ); // apply cell merging for ( size_t i = 0, nRange = maMergeList.size(); i < nRange; ++i ) diff --git a/sc/source/filter/excel/xladdress.cxx b/sc/source/filter/excel/xladdress.cxx index 4aaae918b34d..a11b1959ca64 100644 --- a/sc/source/filter/excel/xladdress.cxx +++ b/sc/source/filter/excel/xladdress.cxx @@ -115,8 +115,8 @@ void XclRangeList::WriteSubList( XclExpStream& rStrm, size_t nBegin, size_t nCou rStrm << nXclCount; } rStrm.SetSliceSize( bCol16Bit ? 8 : 6 ); - for( XclRangeVector::const_iterator aIt = mRanges.begin() + nBegin, aEnd = mRanges.begin() + nEnd; aIt != aEnd; ++aIt ) - aIt->Write( rStrm, bCol16Bit ); + std::for_each(mRanges.begin() + nBegin, mRanges.begin() + nEnd, + [&rStrm, &bCol16Bit](const XclRange& rRange) { rRange.Write(rStrm, bCol16Bit); }); } XclAddressConverterBase::XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos ) : diff --git a/sc/source/filter/excel/xlpivot.cxx b/sc/source/filter/excel/xlpivot.cxx index ccc657537433..aa7938762c78 100644 --- a/sc/source/filter/excel/xlpivot.cxx +++ b/sc/source/filter/excel/xlpivot.cxx @@ -519,9 +519,9 @@ void XclPTFieldInfo::GetSubtotals( XclPTSubtotalVec& rSubtotals ) const void XclPTFieldInfo::SetSubtotals( const XclPTSubtotalVec& rSubtotals ) { mnSubtotals = EXC_SXVD_SUBT_NONE; - for( XclPTSubtotalVec::const_iterator aIt = rSubtotals.begin(), aEnd = rSubtotals.end(); aIt != aEnd; ++aIt ) + for( const auto& rSubtotal : rSubtotals ) { - switch( *aIt ) + switch( rSubtotal ) { case ScGeneralFunction::AUTO: mnSubtotals |= EXC_SXVD_SUBT_DEFAULT; break; case ScGeneralFunction::SUM: mnSubtotals |= EXC_SXVD_SUBT_SUM; break; diff --git a/sc/source/filter/excel/xlstyle.cxx b/sc/source/filter/excel/xlstyle.cxx index 45e6a555e97e..8d769042642a 100644 --- a/sc/source/filter/excel/xlstyle.cxx +++ b/sc/source/filter/excel/xlstyle.cxx @@ -1525,8 +1525,8 @@ void XclNumFmtBuffer::InsertBuiltinFormats() } // copy reused number formats - for( XclReuseMap::const_iterator aRIt = aReuseMap.begin(), aREnd = aReuseMap.end(); aRIt != aREnd; ++aRIt ) - maFmtMap[ aRIt->first ] = maFmtMap[ aRIt->second ]; + for( const auto& [rXclNumFmt, rXclReuseFmt] : aReuseMap ) + maFmtMap[ rXclNumFmt ] = maFmtMap[ rXclReuseFmt ]; } // Cell formatting data (XF) ================================================== diff --git a/sc/source/filter/excel/xltoolbar.cxx b/sc/source/filter/excel/xltoolbar.cxx index 335beb5ae3e0..d8c1dc900814 100644 --- a/sc/source/filter/excel/xltoolbar.cxx +++ b/sc/source/filter/excel/xltoolbar.cxx @@ -101,23 +101,20 @@ void ScCTB::Print( FILE* fp ) indent_printf( fp, " nViews 0x%x\n", nViews); tb.Print( fp ); - std::vector<TBVisualData>::iterator visData_end = rVisualData.end(); sal_Int32 counter = 0; - for ( std::vector<TBVisualData>::iterator it = rVisualData.begin(); it != visData_end; ++it ) + for ( auto& rItem : rVisualData ) { - indent_printf( fp, " TBVisualData [%d]\n", counter++ ); Indent b; - it->Print( fp ); + rItem.Print( fp ); } indent_printf( fp, " ectbid 0x%x\n", ectbid); - std::vector<ScTBC>::iterator it_end = rTBC.end(); counter = 0; - for ( std::vector<ScTBC>::iterator it = rTBC.begin(); it != it_end; ++it ) + for ( auto& rItem : rTBC ) { indent_printf( fp, " ScTBC [%d]\n", counter++); Indent c; - it->Print( fp ); + rItem.Print( fp ); } } #endif @@ -129,10 +126,9 @@ bool ScCTB::IsMenuToolbar() bool ScCTB::ImportMenuTB( ScCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& xMenuDesc, CustomToolBarImportHelper& helper ) { - sal_Int32 index = 0; - for ( std::vector< ScTBC >::iterator it = rTBC.begin(); it != rTBC.end(); ++it, ++index ) + for ( auto& rItem : rTBC ) { - if ( !it->ImportToolBarControl( rWrapper, xMenuDesc, helper, IsMenuToolbar() ) ) + if ( !rItem.ImportToolBarControl( rWrapper, xMenuDesc, helper, IsMenuToolbar() ) ) return false; } return true; @@ -156,9 +152,9 @@ bool ScCTB::ImportCustomToolBar( ScCTBWrapper& rWrapper, CustomToolBarImportHelp xProps->setPropertyValue("UIName", uno::makeAny( name.getString() ) ); OUString sToolBarName = "private:resource/toolbar/custom_" + name.getString(); - for ( std::vector< ScTBC >::iterator it = rTBC.begin(); it != rTBC.end(); ++it ) + for ( auto& rItem : rTBC ) { - if ( !it->ImportToolBarControl( rWrapper, xIndexContainer, helper, IsMenuToolbar() ) ) + if ( !rItem.ImportToolBarControl( rWrapper, xIndexContainer, helper, IsMenuToolbar() ) ) return false; } @@ -368,11 +364,10 @@ ScCTBWrapper::Print( FILE* fp ) Indent a; indent_printf( fp, "[ 0x%x ] ScCTBWrapper -- dump\n", nOffSet ); ctbSet.Print( fp ); - std::vector<ScCTB>::iterator it_end = rCTB.end(); - for ( std::vector<ScCTB>::iterator it = rCTB.begin(); it != it_end; ++it ) + for ( auto& rItem : rCTB ) { Indent b; - it->Print( fp ); + rItem.Print( fp ); } } #endif @@ -380,14 +375,9 @@ ScCTBWrapper::Print( FILE* fp ) ScCTB* ScCTBWrapper::GetCustomizationData( const OUString& sTBName ) { ScCTB* pCTB = nullptr; - for ( std::vector< ScCTB >::iterator it = rCTB.begin(); it != rCTB.end(); ++it ) - { - if ( it->GetName() == sTBName ) - { - pCTB = &(*it); - break; - } - } + auto it = std::find_if(rCTB.begin(), rCTB.end(), [&sTBName](ScCTB& rItem) { return rItem.GetName() == sTBName; }); + if (it != rCTB.end()) + pCTB = &(*it); return pCTB; } @@ -399,8 +389,7 @@ void ScCTBWrapper::ImportCustomToolBar( SfxObjectShell& rDocSh ) uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xAppCfgSupp( ui::theModuleUIConfigurationManagerSupplier::get(xContext) ); - std::vector<ScCTB>::iterator it_end = rCTB.end(); - for ( std::vector<ScCTB>::iterator it = rCTB.begin(); it != it_end; ++it ) + for ( auto& rItem : rCTB ) { // for each customtoolbar CustomToolBarImportHelper helper( rDocSh, xAppCfgSupp->getUIConfigurationManager( "com.sun.star.sheet.SpreadsheetDocument" ) ); @@ -410,11 +399,8 @@ void ScCTBWrapper::ImportCustomToolBar( SfxObjectShell& rDocSh ) // such menus will be dealt with when they are encountered // as part of importing the appropriate MenuSpecific toolbar control ) - if ( !(*it).IsMenuToolbar() ) - { - if ( !(*it).ImportCustomToolBar( *this, helper ) ) - return; - } + if ( !rItem.IsMenuToolbar() && !rItem.ImportCustomToolBar( *this, helper ) ) + return; } } |