diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-11-03 15:10:04 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-11-03 16:00:36 +0100 |
commit | 4284f618557992fdf12574f8fd014be76ec9fffc (patch) | |
tree | fac74828b9a4139d1f74087443c3fcc0b8a1363f | |
parent | f575cf3320684efe7db9844da89a5ebdb3083498 (diff) |
Simplify containers iterations in sw/source/filter
Use range-based loop or replace with STL functions.
Change-Id: Ifffb7ba08b3a9950ee076558ec4048b0788a38c8
Reviewed-on: https://gerrit.libreoffice.org/62806
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
25 files changed, 219 insertions, 331 deletions
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index efbb9cce6837..4993f21176a7 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -295,9 +295,9 @@ void SwHTMLWriter::CollectFlyFrames() SwPosFlyFrames aFlyPos(m_pDoc->GetAllFlyFormats(m_bWriteAll ? nullptr : m_pCurrentPam, true)); - for(SwPosFlyFrames::const_iterator aIter(aFlyPos.begin()); aIter != aFlyPos.end(); ++aIter) + for(const auto& rpItem : aFlyPos) { - const SwFrameFormat& rFrameFormat = (*aIter)->GetFormat(); + const SwFrameFormat& rFrameFormat = rpItem->GetFormat(); const SdrObject *pSdrObj = nullptr; const SwPosition *pAPos; const SwContentNode *pACNd; @@ -347,7 +347,7 @@ void SwHTMLWriter::CollectFlyFrames() if( !m_pHTMLPosFlyFrames ) m_pHTMLPosFlyFrames.reset(new SwHTMLPosFlyFrames); - m_pHTMLPosFlyFrames->insert( o3tl::make_unique<SwHTMLPosFlyFrame>(**aIter, pSdrObj, nMode) ); + m_pHTMLPosFlyFrames->insert( o3tl::make_unique<SwHTMLPosFlyFrame>(*rpItem, pSdrObj, nMode) ); } } diff --git a/sw/source/filter/html/htmltabw.cxx b/sw/source/filter/html/htmltabw.cxx index a2e93d6bd9f8..600d27c5dc72 100644 --- a/sw/source/filter/html/htmltabw.cxx +++ b/sw/source/filter/html/htmltabw.cxx @@ -196,10 +196,9 @@ static bool lcl_TableBox_HasTabBorders( const SwTableBox* pBox, bool *pBorders ) if( !pBox->GetSttNd() ) { - for( SwTableLines::const_iterator it = pBox->GetTabLines().begin(); - it != pBox->GetTabLines().end(); ++it) + for( const auto& rpLine : pBox->GetTabLines() ) { - if ( lcl_TableLine_HasTabBorders( *it, pBorders ) ) + if ( lcl_TableLine_HasTabBorders( rpLine, pBorders ) ) break; } } @@ -220,10 +219,9 @@ static bool lcl_TableLine_HasTabBorders( const SwTableLine* pLine, bool *pBorder if( *pBorders ) return false; - for( SwTableBoxes::const_iterator it = pLine->GetTabBoxes().begin(); - it != pLine->GetTabBoxes().end(); ++it) + for( const auto& rpBox : pLine->GetTabBoxes() ) { - if ( lcl_TableBox_HasTabBorders( *it, pBorders ) ) + if ( lcl_TableBox_HasTabBorders( rpBox, pBorders ) ) break; } return !*pBorders; diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index 879a95e0db9b..042ab0d1563d 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -472,9 +472,8 @@ SwHTMLParser::~SwHTMLParser() if( !m_aSetAttrTab.empty() ) { OSL_ENSURE( m_aSetAttrTab.empty(),"There are still attributes on the stack" ); - for ( HTMLAttrs::const_iterator it = m_aSetAttrTab.begin(); - it != m_aSetAttrTab.end(); ++it ) - delete *it; + for ( auto& rpAttr : m_aSetAttrTab ) + delete rpAttr; m_aSetAttrTab.clear(); } diff --git a/sw/source/filter/writer/writer.cxx b/sw/source/filter/writer/writer.cxx index e0a92c344d8b..05d72841b81e 100644 --- a/sw/source/filter/writer/writer.cxx +++ b/sw/source/filter/writer/writer.cxx @@ -84,10 +84,9 @@ Writer_Impl::Writer_Impl() void Writer_Impl::RemoveFontList( SwDoc& rDoc ) { - for( std::vector<const SvxFontItem*>::const_iterator it = aFontRemoveLst.begin(); - it != aFontRemoveLst.end(); ++it ) + for( const auto& rpFontItem : aFontRemoveLst ) { - rDoc.GetAttrPool().Remove( **it ); + rDoc.GetAttrPool().Remove( *rpFontItem ); } } diff --git a/sw/source/filter/ww8/WW8FFData.cxx b/sw/source/filter/ww8/WW8FFData.cxx index 8a2392d643ab..7b5c4efb7467 100644 --- a/sw/source/filter/ww8/WW8FFData.cxx +++ b/sw/source/filter/ww8/WW8FFData.cxx @@ -146,15 +146,8 @@ void WW8FFData::Write(SvStream * pDataStrm) sal_uInt32 nListboxEntries = msListEntries.size(); pDataStrm->WriteUInt32( nListboxEntries ); - std::vector< OUString >::const_iterator aIt = msListEntries.begin(); - - while (aIt != msListEntries.end()) - { - const OUString & rEntry = *aIt; + for (const OUString & rEntry : msListEntries) WriteOUString(pDataStrm, rEntry, false); - - ++aIt; - } } SwWW8Writer::WriteLong( *pDataStrm, nDataStt, diff --git a/sw/source/filter/ww8/WW8TableInfo.cxx b/sw/source/filter/ww8/WW8TableInfo.cxx index ae6596f43b52..0ecda9170a19 100644 --- a/sw/source/filter/ww8/WW8TableInfo.cxx +++ b/sw/source/filter/ww8/WW8TableInfo.cxx @@ -208,12 +208,9 @@ GridColsPtr WW8TableNodeInfoInner::getGridColsOfRow(AttributeOutputBase & rBase, rBase.GetTablePageSize( this, nPageSize, bRelBoxSize ); SwTwips nSz = 0; - Widths::const_iterator aWidthsEnd = pWidths->end(); - for ( Widths::const_iterator aIt = pWidths->begin(); - aIt != aWidthsEnd; - ++aIt) + for (const auto& rWidth : *pWidths) { - nSz += *aIt; + nSz += rWidth; SwTwips nCalc = nSz; if ( bRelBoxSize ) nCalc = ( nCalc * nPageSize ) / nTableSz; @@ -267,10 +264,8 @@ WidthsPtr WW8TableNodeInfoInner::getColumnWidthsBasedOnAllRows() // column separators pWidths = std::make_shared<Widths>(); sal_uInt32 nPreviousWidth = 0; - Widths::const_iterator aItEnd2 = pSeparators->end(); - for (Widths::const_iterator aIt2 = pSeparators->begin(); aIt2 != aItEnd2; ++aIt2) + for (const sal_uInt32 nCurrentWidth : *pSeparators) { - sal_uInt32 nCurrentWidth = *aIt2; pWidths->push_back(nCurrentWidth - nPreviousWidth); nPreviousWidth = nCurrentWidth; } @@ -393,15 +388,10 @@ std::string WW8TableNodeInfo::toString() const std::string sResult(buffer); - Inners_t::const_iterator aIt(mInners.begin()); - Inners_t::const_iterator aEnd(mInners.end()); - - while (aIt != aEnd) + for (const auto& rInner : mInners) { - WW8TableNodeInfoInner::Pointer_t pInner = aIt->second; + WW8TableNodeInfoInner::Pointer_t pInner = rInner.second; sResult += pInner->toString(); - - ++aIt; } sResult += dbg_out(*mpNode); sResult += "</tableNodeInfo>"; diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 1681f03e629d..47022173a6ea 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1357,12 +1357,12 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool / // XML_r node should be surrounded with permission-begin and permission-end nodes if it has permission. DoWritePermissionsEnd(); - for (std::vector<const SwOLENode*>::iterator it = m_aPostponedMaths.begin(); it != m_aPostponedMaths.end(); ++it) - WritePostponedMath(*it); + for (const auto& rpMath : m_aPostponedMaths) + WritePostponedMath(rpMath); m_aPostponedMaths.clear(); - for (std::vector<const SdrObject*>::iterator it = m_aPostponedFormControls.begin(); it != m_aPostponedFormControls.end(); ++it) - WritePostponedFormControl(*it); + for (const auto& rpControl : m_aPostponedFormControls) + WritePostponedFormControl(rpControl); m_aPostponedFormControls.clear(); WritePostponedActiveXControl(false); @@ -7436,13 +7436,13 @@ void DocxAttributeOutput::FootnotesEndnotes( bool bFootnotes ) // if new special ones are added, update also WriteFootnoteEndnotePr() // footnotes/endnotes themselves - for ( FootnotesVector::const_iterator i = rVector.begin(); i != rVector.end(); ++i, ++nIndex ) + for ( const auto& rpItem : rVector ) { m_pSerializer->startElementNS( XML_w, nItem, FSNS( XML_w, XML_id ), OString::number( nIndex ).getStr(), FSEND ); - const SwNodeIndex* pIndex = (*i)->GetTextFootnote()->GetStartNode(); + const SwNodeIndex* pIndex = rpItem->GetTextFootnote()->GetStartNode(); // tag required at the start of each footnote/endnote m_footnoteEndnoteRefTag = bFootnotes ? XML_footnoteRef : XML_endnoteRef; @@ -7451,6 +7451,7 @@ void DocxAttributeOutput::FootnotesEndnotes( bool bFootnotes ) bFootnotes? TXT_FTN: TXT_EDN ); m_pSerializer->endElementNS( XML_w, nItem ); + ++nIndex; } m_pSerializer->endElementNS( XML_w, nBody ); diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 5410759ee570..91e485eaa980 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -152,11 +152,8 @@ void DocxExport::AppendBookmarks( const SwTextNode& rNode, sal_Int32 nCurrentPos IMarkVector aMarks; if ( GetBookmarks( rNode, nCurrentPos, nCurrentPos + nLen, aMarks ) ) { - for ( IMarkVector::const_iterator it = aMarks.begin(), end = aMarks.end(); - it != end; ++it ) + for ( IMark* pMark : aMarks ) { - IMark* pMark = (*it); - const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex(); const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex(); @@ -196,11 +193,8 @@ void DocxExport::AppendAnnotationMarks( const SwTextNode& rNode, sal_Int32 nCurr IMarkVector aMarks; if ( GetAnnotationMarks( rNode, nCurrentPos, nCurrentPos + nLen, aMarks ) ) { - for ( IMarkVector::const_iterator it = aMarks.begin(), end = aMarks.end(); - it != end; ++it ) + for ( IMark* pMark : aMarks ) { - IMark* pMark = (*it); - const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex(); const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex(); diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index d1f9f489c74a..b8372d5e13c1 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -1522,28 +1522,25 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho } //first, loop through ALL of the chained textboxes to identify a unique ID for each chain, and sequence number for each textbox in that chain. - std::map<OUString, MSWordExportBase::LinkedTextboxInfo>::iterator linkedTextboxesIter; if (!m_pImpl->m_rExport.m_bLinkedTextboxesHelperInitialized) { sal_Int32 nSeq = 0; - linkedTextboxesIter = m_pImpl->m_rExport.m_aLinkedTextboxesHelper.begin(); - while (linkedTextboxesIter != m_pImpl->m_rExport.m_aLinkedTextboxesHelper.end()) + for (auto& rEntry : m_pImpl->m_rExport.m_aLinkedTextboxesHelper) { //find the start of a textbox chain: has no PREVIOUS link, but does have NEXT link - if (linkedTextboxesIter->second.sPrevChain.isEmpty() - && !linkedTextboxesIter->second.sNextChain.isEmpty()) + if (rEntry.second.sPrevChain.isEmpty() && !rEntry.second.sNextChain.isEmpty()) { //assign this chain a unique ID and start a new sequence nSeq = 0; - linkedTextboxesIter->second.nId = ++m_pImpl->m_rExport.m_nLinkedTextboxesChainId; - linkedTextboxesIter->second.nSeq = nSeq; + rEntry.second.nId = ++m_pImpl->m_rExport.m_nLinkedTextboxesChainId; + rEntry.second.nSeq = nSeq; - OUString sCheckForBrokenChains = linkedTextboxesIter->first; + OUString sCheckForBrokenChains = rEntry.first; //follow the chain and assign the same id, and incremental sequence numbers. std::map<OUString, MSWordExportBase::LinkedTextboxInfo>::iterator followChainIter; - followChainIter = m_pImpl->m_rExport.m_aLinkedTextboxesHelper.find( - linkedTextboxesIter->second.sNextChain); + followChainIter + = m_pImpl->m_rExport.m_aLinkedTextboxesHelper.find(rEntry.second.sNextChain); while (followChainIter != m_pImpl->m_rExport.m_aLinkedTextboxesHelper.end()) { //verify that the NEXT textbox also points to me as the PREVIOUS. @@ -1563,7 +1560,6 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho followChainIter->second.sNextChain); } } - ++linkedTextboxesIter; } m_pImpl->m_rExport.m_bLinkedTextboxesHelperInitialized = true; } @@ -1582,7 +1578,8 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho } // second, check if THIS textbox is linked and then decide whether to write the tag txbx or linkedTxbx - linkedTextboxesIter = m_pImpl->m_rExport.m_aLinkedTextboxesHelper.find(sLinkChainName); + std::map<OUString, MSWordExportBase::LinkedTextboxInfo>::iterator linkedTextboxesIter + = m_pImpl->m_rExport.m_aLinkedTextboxesHelper.find(sLinkChainName); if (linkedTextboxesIter != m_pImpl->m_rExport.m_aLinkedTextboxesHelper.end()) { if ((linkedTextboxesIter->second.nId != 0) && (linkedTextboxesIter->second.nSeq != 0)) diff --git a/sw/source/filter/ww8/writerhelper.cxx b/sw/source/filter/ww8/writerhelper.cxx index 8f61cab73603..d396a04ad632 100644 --- a/sw/source/filter/ww8/writerhelper.cxx +++ b/sw/source/filter/ww8/writerhelper.cxx @@ -108,9 +108,9 @@ namespace { ww8::Frames aRet; - for(SwPosFlyFrames::const_iterator aIter(rFlys.begin()); aIter != rFlys.end(); ++aIter) + for(const auto& rpFly : rFlys) { - const SwFrameFormat &rEntry = (*aIter)->GetFormat(); + const SwFrameFormat &rEntry = rpFly->GetFormat(); if (const SwPosition* pAnchor = rEntry.GetAnchor().GetContentAnchor()) { @@ -122,7 +122,7 @@ namespace } else { - SwPosition aPos((*aIter)->GetNdIndex()); + SwPosition aPos(rpFly->GetNdIndex()); if (SwTextNode* pTextNd = aPos.nNode.GetNode().GetTextNode()) { diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx index 99f8c902aab5..e3910364b03e 100644 --- a/sw/source/filter/ww8/wrtw8esh.cxx +++ b/sw/source/filter/ww8/wrtw8esh.cxx @@ -1031,20 +1031,20 @@ rtl_TextEncoding MSWord_SdrAttrIter::GetNextCharSet() const sal_Int32 MSWord_SdrAttrIter::SearchNext( sal_Int32 nStartPos ) { sal_Int32 nMinPos = SAL_MAX_INT32; - for(std::vector<EECharAttrib>::const_iterator i = aTextAtrArr.begin(); i < aTextAtrArr.end(); ++i) + for(const auto& rTextAtr : aTextAtrArr) { - sal_Int32 nPos = i->nStart; // first character attribute + sal_Int32 nPos = rTextAtr.nStart; // first character attribute if( nPos >= nStartPos && nPos <= nMinPos ) { nMinPos = nPos; - SetCharSet(*i, true); + SetCharSet(rTextAtr, true); } - nPos = i->nEnd; // last character attribute + 1 + nPos = rTextAtr.nEnd; // last character attribute + 1 if( nPos >= nStartPos && nPos < nMinPos ) { nMinPos = nPos; - SetCharSet(*i, false); + SetCharSet(rTextAtr, false); } } return nMinPos; @@ -1104,15 +1104,15 @@ void MSWord_SdrAttrIter::OutAttr( sal_Int32 nSwPos ) std::set<sal_uInt16> aUsedRunWhichs; if (!aTextAtrArr.empty()) { - for(std::vector<EECharAttrib>::const_iterator i = aTextAtrArr.begin(); i < aTextAtrArr.end(); ++i) + for(const auto& rTextAtr : aTextAtrArr) { - if (nSwPos >= i->nStart && nSwPos < i->nEnd) + if (nSwPos >= rTextAtr.nStart && nSwPos < rTextAtr.nEnd) { - sal_uInt16 nWhich = i->pAttr->Which(); + sal_uInt16 nWhich = rTextAtr.pAttr->Which(); aUsedRunWhichs.insert(nWhich); } - if( nSwPos < i->nStart ) + if( nSwPos < rTextAtr.nStart ) break; } } @@ -1130,14 +1130,14 @@ void MSWord_SdrAttrIter::OutAttr( sal_Int32 nSwPos ) nTmpSwPos = nSwPos; // Did we already produce a <w:sz> element? m_rExport.m_bFontSizeWritten = false; - for(std::vector<EECharAttrib>::const_iterator i = aTextAtrArr.begin(); i < aTextAtrArr.end(); ++i) + for(const auto& rTextAtr : aTextAtrArr) { - if (nSwPos >= i->nStart && nSwPos < i->nEnd) + if (nSwPos >= rTextAtr.nStart && nSwPos < rTextAtr.nEnd) { - sal_uInt16 nWhich = i->pAttr->Which(); + sal_uInt16 nWhich = rTextAtr.pAttr->Which(); if (nWhich == EE_FEATURE_FIELD) { - OutEEField(*(i->pAttr)); + OutEEField(*(rTextAtr.pAttr)); continue; } if (nWhich == EE_FEATURE_TAB) @@ -1155,7 +1155,7 @@ void MSWord_SdrAttrIter::OutAttr( sal_Int32 nSwPos ) m_rExport.CollapseScriptsforWordOk(nScript,nWhich)) { // use always the SW-Which Id ! - std::unique_ptr<SfxPoolItem> pI(i->pAttr->Clone()); + std::unique_ptr<SfxPoolItem> pI(rTextAtr.pAttr->Clone()); pI->SetWhich( nWhich ); // Will this item produce a <w:sz> element? bool bFontSizeItem = nWhich == RES_CHRATR_FONTSIZE || nWhich == RES_CHRATR_CJK_FONTSIZE; @@ -1167,7 +1167,7 @@ void MSWord_SdrAttrIter::OutAttr( sal_Int32 nSwPos ) } } - if( nSwPos < i->nStart ) + if( nSwPos < rTextAtr.nStart ) break; } m_rExport.m_bFontSizeWritten = false; @@ -1179,16 +1179,13 @@ void MSWord_SdrAttrIter::OutAttr( sal_Int32 nSwPos ) bool MSWord_SdrAttrIter::IsTextAttr(sal_Int32 nSwPos) { - for (std::vector<EECharAttrib>::const_iterator i = aTextAtrArr.begin(); i < aTextAtrArr.end(); ++i) - { - if (nSwPos >= i->nStart && nSwPos < i->nEnd) - { - if (i->pAttr->Which() == EE_FEATURE_FIELD || - i->pAttr->Which() == EE_FEATURE_TAB) - return true; + return std::any_of(aTextAtrArr.begin(), aTextAtrArr.end(), + [nSwPos](const EECharAttrib& rTextAtr) { + return (nSwPos >= rTextAtr.nStart && nSwPos < rTextAtr.nEnd) && + (rTextAtr.pAttr->Which() == EE_FEATURE_FIELD || + rTextAtr.pAttr->Which() == EE_FEATURE_TAB); } - } - return false; + ); } // HasItem is used for the consolidation of the double attribute Underline and @@ -1202,11 +1199,11 @@ const SfxPoolItem* MSWord_SdrAttrIter::HasTextItem(sal_uInt16 nWhich) const m_rExport.m_pDoc->GetAttrPool(), nWhich); if (nWhich) { - for (std::vector<EECharAttrib>::const_iterator i = aTextAtrArr.begin(); i < aTextAtrArr.end(); ++i) + for (const auto& rTextAtr : aTextAtrArr) { - if (nWhich == i->pAttr->Which() && nTmpSwPos >= i->nStart && nTmpSwPos < i->nEnd) - return i->pAttr; // Found - if (nTmpSwPos < i->nStart) + if (nWhich == rTextAtr.pAttr->Which() && nTmpSwPos >= rTextAtr.nStart && nTmpSwPos < rTextAtr.nEnd) + return rTextAtr.pAttr; // Found + if (nTmpSwPos < rTextAtr.nStart) return nullptr; } } @@ -2839,21 +2836,15 @@ sal_Int32 SwEscherEx::WriteFlyFrame(const DrawObj &rObj, sal_uInt32 &rShapeId, static sal_uInt16 FindPos(const SwFrameFormat &rFormat, unsigned int nHdFtIndex, DrawObjPointerVector &rPVec) { - auto aEnd = rPVec.end(); - for (auto aIter = rPVec.begin(); aIter != aEnd; ++aIter) - { - const DrawObj *pObj = (*aIter); - OSL_ENSURE(pObj, "Impossible"); - if (!pObj) - continue; - if ( - nHdFtIndex == pObj->mnHdFtIndex && - &rFormat == (&pObj->maContent.GetFrameFormat()) - ) - { - return static_cast< sal_uInt16 >(aIter - rPVec.begin()); - } - } + auto aIter = std::find_if(rPVec.begin(), rPVec.end(), + [&rFormat, nHdFtIndex](const DrawObj* pObj) { + OSL_ENSURE(pObj, "Impossible"); + return pObj && + nHdFtIndex == pObj->mnHdFtIndex && + &rFormat == (&pObj->maContent.GetFrameFormat()); + }); + if (aIter != rPVec.end()) + return static_cast< sal_uInt16 >(aIter - rPVec.begin()); return USHRT_MAX; } diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index 36555f31f96e..2b59e5ec84e2 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -747,15 +747,8 @@ bool SwWW8AttrIter::IsDropCap( int nSwPos ) bool SwWW8AttrIter::RequiresImplicitBookmark() { - std::vector<aBookmarkPair>::iterator bkmkIterEnd = m_rExport.m_aImplicitBookmarks.end(); - for ( std::vector<aBookmarkPair>::iterator aIter = m_rExport.m_aImplicitBookmarks.begin(); aIter != bkmkIterEnd; ++aIter ) - { - sal_uLong sample = aIter->second; - - if ( sample == rNd.GetIndex() ) - return true; - } - return false; + return std::any_of(m_rExport.m_aImplicitBookmarks.begin(), m_rExport.m_aImplicitBookmarks.end(), + [this](const aBookmarkPair& rBookmarkPair) { return rBookmarkPair.second == rNd.GetIndex(); }); } //HasItem is for the summary of the double attributes: Underline and WordlineMode as TextItems. @@ -940,12 +933,11 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT if ( sRefType == "outline" ) { OUString sLink = sMark.copy(0, nPos); - std::vector<aBookmarkPair>::iterator bkmkIterEnd = GetExport().m_aImplicitBookmarks.end(); - for ( std::vector<aBookmarkPair>::iterator aIter = GetExport().m_aImplicitBookmarks.begin(); aIter != bkmkIterEnd; ++aIter ) + for ( const auto& rBookmarkPair : GetExport().m_aImplicitBookmarks ) { - if ( aIter->first == sLink ) + if ( rBookmarkPair.first == sLink ) { - sMark = "_toc" + OUString::number( aIter->second ); + sMark = "_toc" + OUString::number( rBookmarkPair.second ); } } } @@ -1187,21 +1179,17 @@ void SwWW8AttrIter::OutSwFormatRefMark(const SwFormatRefMark& rAttr) void SwWW8AttrIter::SplitRun( sal_Int32 nSplitEndPos ) { - for(auto aIter = maCharRuns.begin(); aIter != maCharRuns.end(); ++aIter) - { - if(aIter->mnEndPos == nSplitEndPos) - return; - else if (aIter->mnEndPos > nSplitEndPos) - { - CharRunEntry aNewEntry = *aIter; - aIter->mnEndPos = nSplitEndPos; - maCharRuns.insert( ++aIter, aNewEntry); - maCharRunIter = maCharRuns.begin(); - IterToCurrent(); - nCurrentSwPos = SearchNext(1); - break; - } - } + auto aIter = std::find_if(maCharRuns.begin(), maCharRuns.end(), + [nSplitEndPos](const CharRunEntry& rCharRun) { return rCharRun.mnEndPos >= nSplitEndPos; }); + if (aIter == maCharRuns.end() || aIter->mnEndPos == nSplitEndPos) + return; + + CharRunEntry aNewEntry = *aIter; + aIter->mnEndPos = nSplitEndPos; + maCharRuns.insert( ++aIter, aNewEntry); + maCharRunIter = maCharRuns.begin(); + IterToCurrent(); + nCurrentSwPos = SearchNext(1); } void WW8AttributeOutput::FieldVanish( const OUString& rText, ww::eField /*eType*/ ) @@ -2024,11 +2012,8 @@ void MSWordExportBase::GetSortedAnnotationMarks( const SwTextNode& rNode, sal_In { IMarkVector aSortedEnd; IMarkVector aSortedStart; - for ( IMarkVector::const_iterator it = aMarksStart.begin(), end = aMarksStart.end(); - it != end; ++it ) + for ( IMark* pMark : aMarksStart ) { - IMark* pMark = (*it); - // Remove the positions equal to the current pos const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex(); const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex(); @@ -2060,11 +2045,8 @@ void MSWordExportBase::GetSortedBookmarks( const SwTextNode& rNode, sal_Int32 nC { IMarkVector aSortedEnd; IMarkVector aSortedStart; - for ( IMarkVector::const_iterator it = aMarksStart.begin(), end = aMarksStart.end(); - it != end; ++it ) + for ( IMark* pMark : aMarksStart ) { - IMark* pMark = (*it); - // Remove the positions equal to the current pos const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex(); const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex(); diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index ca1ae82deee6..09740c9eb718 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -953,10 +953,9 @@ void WW8_WrPlc0::Append( sal_uLong nStartCpOrFc ) void WW8_WrPlc0::Write( SvStream& rStrm ) { - std::vector<sal_uLong>::const_iterator iter; - for( iter = aPos.begin(); iter != aPos.end(); ++iter ) + for( const auto& rPos : aPos ) { - rStrm.WriteUInt32(*iter); + rStrm.WriteUInt32(rPos); } } @@ -1258,10 +1257,9 @@ void MSWordSections::CheckForFacinPg( WW8Export& rWrt ) const // 2 values getting set // Dop.fFacingPages == Header and Footer different // Dop.fSwapBordersFacingPgs == mirrored borders - std::vector<WW8_SepInfo>::const_iterator iter = aSects.begin(); - for( sal_uInt16 nEnde = 0; iter != aSects.end(); ++iter ) + sal_uInt16 nEnde = 0; + for( const WW8_SepInfo& rSepInfo : aSects ) { - const WW8_SepInfo& rSepInfo = *iter; if( !rSepInfo.pSectionFormat ) { const SwPageDesc* pPd = rSepInfo.pPageDesc; diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index f1fd65a86873..8cf84557772f 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -216,13 +216,12 @@ WW8_WrtBookmarks::WW8_WrtBookmarks() WW8_WrtBookmarks::~WW8_WrtBookmarks() { - CPItr aEnd = aSttCps.end(); - for (CPItr aItr = aSttCps.begin();aItr!=aEnd;++aItr) + for (auto& rEntry : aSttCps) { - if (aItr->second) + if (rEntry.second) { - delete aItr->second; - aItr->second = nullptr; + delete rEntry.second; + rEntry.second = nullptr; } } } @@ -257,31 +256,32 @@ void WW8_WrtBookmarks::Write( WW8Export& rWrt) { if (aSttCps.empty()) return; - CPItr aItr; long n; std::vector<OUString> aNames; SvMemoryStream aTempStrm1(65535,65535); SvMemoryStream aTempStrm2(65535,65535); BKMKCPs aEndCps; - for (aItr = aSttCps.begin();aItr!=aSttCps.end();++aItr) + for (const auto& rEntry : aSttCps) { - if (aItr->second) + if (rEntry.second) { - aEndCps.insert(std::pair<long,BKMKCP*>(aItr->second->first,aItr->second)); - aNames.push_back(aItr->second->second.second); - SwWW8Writer::WriteLong( aTempStrm1, aItr->first); + aEndCps.insert(std::pair<long,BKMKCP*>(rEntry.second->first, rEntry.second)); + aNames.push_back(rEntry.second->second.second); + SwWW8Writer::WriteLong(aTempStrm1, rEntry.first); } } aTempStrm1.Seek(0); - for (aItr = aEndCps.begin(), n = 0;aItr != aEndCps.end();++aItr,++n) + n = 0; + for (const auto& rEntry : aEndCps) { - if (aItr->second) + if (rEntry.second) { - aItr->second->first = n; - SwWW8Writer::WriteLong( aTempStrm2, aItr->first); + rEntry.second->first = n; + SwWW8Writer::WriteLong( aTempStrm2, rEntry.first); } + ++n; } aTempStrm2.Seek(0); @@ -290,11 +290,11 @@ void WW8_WrtBookmarks::Write( WW8Export& rWrt) rWrt.pFib->m_fcPlcfbkf = rStrm.Tell(); rStrm.WriteStream( aTempStrm1 ); SwWW8Writer::WriteLong(rStrm, rWrt.pFib->m_ccpText + rWrt.pFib->m_ccpTxbx); - for (aItr = aSttCps.begin();aItr!=aSttCps.end();++aItr) + for (const auto& rEntry : aSttCps) { - if (aItr->second) + if (rEntry.second) { - SwWW8Writer::WriteLong(rStrm, aItr->second->first); + SwWW8Writer::WriteLong(rStrm, rEntry.second->first); } } rWrt.pFib->m_lcbPlcfbkf = rStrm.Tell() - rWrt.pFib->m_fcPlcfbkf; @@ -1488,9 +1488,8 @@ void WW8Export::AppendAnnotationMarks(const SwTextNode& rNode, sal_Int32 nCurren IMarkVector aMarks; if (GetAnnotationMarks(rNode, nCurrentPos, nCurrentPos + nLen, aMarks)) { - for (IMarkVector::const_iterator it = aMarks.begin(), end = aMarks.end(); it != end; ++it) + for (const sw::mark::IMark* pMark : aMarks) { - sw::mark::IMark* pMark = (*it); const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex(); if (nStart == nCurrentPos) { @@ -2391,23 +2390,19 @@ void WW8AttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t m_rWW8Export.InsUInt16( nTableOffset ); ww8::GridColsPtr pGridCols = GetGridCols( pTableTextNodeInfoInner ); - for ( ww8::GridCols::const_iterator it = pGridCols->begin(), - end = pGridCols->end(); it != end; ++it ) + for ( const auto nCol : *pGridCols ) { - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>( *it ) + nTableOffset ); + m_rWW8Export.InsUInt16( static_cast<sal_uInt16>(nCol) + nTableOffset ); } /* TCs */ ww8::RowSpansPtr pRowSpans = pTableTextNodeInfoInner->getRowSpansOfRow(); ww8::RowSpans::const_iterator aItRowSpans = pRowSpans->begin(); - ww8::TableBoxVector::const_iterator aIt; - ww8::TableBoxVector::const_iterator aItEnd = pTableBoxes->end(); - for (aIt = pTableBoxes->begin(); aIt != aItEnd; ++aIt, ++aItRowSpans) + for (const SwTableBox * pTabBox1 : *pTableBoxes) { sal_uInt16 npOCount = m_rWW8Export.pO->size(); - const SwTableBox * pTabBox1 = *aIt; const SwFrameFormat * pBoxFormat = nullptr; if (pTabBox1 != nullptr) pBoxFormat = pTabBox1->GetFrameFormat(); @@ -2429,6 +2424,7 @@ void WW8AttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t WW8Export::Out_SwFormatTableBox( *m_rWW8Export.pO, nullptr); // 8/16 Byte SAL_INFO( "sw.ww8.level2", "<tclength>" << ( m_rWW8Export.pO->size() - npOCount ) << "</tclength>" ); + ++aItRowSpans; } int nWidthPercent = pFormat->GetFrameSize().GetWidthPercent(); @@ -4106,14 +4102,11 @@ void MSWordExportBase::OutputEndNode( const SwEndNode &rNode ) SAL_INFO( "sw.ww8", pNodeInfo->toString()); #endif const ww8::WW8TableNodeInfo::Inners_t aInners = pNodeInfo->getInners(); - ww8::WW8TableNodeInfo::Inners_t::const_iterator aIt(aInners.begin()); - ww8::WW8TableNodeInfo::Inners_t::const_iterator aEnd(aInners.end()); - while (aIt != aEnd) - { - ww8::WW8TableNodeInfoInner::Pointer_t pInner = aIt->second; + for (const auto& rEntry : aInners) + { + ww8::WW8TableNodeInfoInner::Pointer_t pInner = rEntry.second; AttrOutput().TableNodeInfoInner(pInner); - ++aIt; - } + } } SAL_INFO( "sw.ww8", "</OutWW8_SwEndNode>" ); } diff --git a/sw/source/filter/ww8/wrtww8gr.cxx b/sw/source/filter/ww8/wrtww8gr.cxx index 3bb894d99ad2..251588a83837 100644 --- a/sw/source/filter/ww8/wrtww8gr.cxx +++ b/sw/source/filter/ww8/wrtww8gr.cxx @@ -886,18 +886,12 @@ void SwWW8WrGrf::Write() if( nPos & 0x3 ) SwWW8Writer::FillCount( rStrm, 4 - ( nPos & 0x3 ) ); - bool bDuplicated = false; - for (auto aIter2 = maDetails.begin(); aIter2 != aIter; ++aIter2) + auto aIter2 = std::find(maDetails.begin(), aIter, *aIter); + if (aIter2 != aIter) { - if (*aIter2 == *aIter) - { - aIter->mnPos = aIter2->mnPos; - bDuplicated = true; - break; - } + aIter->mnPos = aIter2->mnPos; } - - if (!bDuplicated) + else { aIter->mnPos = rStrm.Tell(); WriteGraphicNode(rStrm, *aIter); diff --git a/sw/source/filter/ww8/ww8graf2.cxx b/sw/source/filter/ww8/ww8graf2.cxx index d2d39f37d526..db8837c82849 100644 --- a/sw/source/filter/ww8/ww8graf2.cxx +++ b/sw/source/filter/ww8/ww8graf2.cxx @@ -18,6 +18,7 @@ */ #include <iterator> +#include <numeric> #include <hintids.hxx> #include <svl/urihelper.hxx> #include <svx/svdpage.hxx> @@ -83,15 +84,8 @@ void wwZOrderer::InsertEscherObject( SdrObject* pObject, wwZOrderer::myeiter wwZOrderer::MapEscherIdxToIter(sal_uLong nIdx) { - myeiter aIter = maEscherLayer.begin(); - myeiter aEnd = maEscherLayer.end(); - while (aIter != aEnd) - { - if (aIter->mnEscherShapeOrder == nIdx) - break; - ++aIter; - } - return aIter; + return std::find_if(maEscherLayer.begin(), maEscherLayer.end(), + [nIdx](const EscherShape& rShape) { return rShape.mnEscherShapeOrder == nIdx; }); } sal_uInt16 wwZOrderer::GetEscherObjectIdx(sal_uLong nSpId) @@ -187,13 +181,8 @@ void wwZOrderer::InsertTextLayerObject(SdrObject* pObject) sal_uInt16 nIdx = maIndexes.top(); myeiter aEnd = MapEscherIdxToIter(nIdx); - sal_uLong nInsertPos=0; - myeiter aIter = maEscherLayer.begin(); - while (aIter != aEnd) - { - nInsertPos += aIter->mnNoInlines+1; - ++aIter; - } + sal_uLong nInsertPos = std::accumulate(maEscherLayer.begin(), aEnd, sal_uLong(0), + [](const sal_uLong nPos, const EscherShape& rShape) { return nPos + rShape.mnNoInlines + 1; }); OSL_ENSURE(aEnd != maEscherLayer.end(), "Something very wrong here"); if (aEnd != maEscherLayer.end()) diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 6914ca7ccdc8..19171a4c8c6a 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -3909,18 +3909,15 @@ bool SwWW8ImplReader::IsParaEndInCPs(sal_Int32 nStart, sal_Int32 nEnd,bool bSdOD if (nStart == -1 || nEnd == -1 || nEnd < nStart ) return false; - for (cp_vector::const_reverse_iterator aItr = m_aEndParaPos.rbegin(); aItr!= m_aEndParaPos.rend(); ++aItr) - { - //Revised 2012.8.16,to the 0x0D,the attribute will have two situations - //*********within***********exact****** - //*********but also sample with only left and the position of 0x0d is the edge of the right side*********** - if ( bSdOD && ( (nStart < *aItr && nEnd > *aItr) || ( nStart == nEnd && *aItr == nStart)) ) - return true; - else if ( !bSdOD && (nStart < *aItr && nEnd >= *aItr) ) - return true; - } - - return false; + return std::any_of(m_aEndParaPos.rbegin(), m_aEndParaPos.rend(), + [=](const WW8_CP& rPos) { + //Revised 2012.8.16,to the 0x0D,the attribute will have two situations + //*********within***********exact****** + //*********but also sample with only left and the position of 0x0d is the edge of the right side*********** + return (bSdOD && ((nStart < rPos && nEnd > rPos) || (nStart == nEnd && rPos == nStart))) || + (!bSdOD && (nStart < rPos && nEnd >= rPos)); + } + ); } //Clear the para end position recorded in reader intermittently for the least impact on loading performance @@ -5936,16 +5933,12 @@ void SwWW8ImplReader::SetOutlineStyles() } int nCurrentMaxCount = 0; - std::map<const SwNumRule*, int>::iterator aCountIterEnd - = aWW8ListStyleCounts.end(); - for (std::map<const SwNumRule*, int>::iterator aIter - = aWW8ListStyleCounts.begin(); - aIter != aCountIterEnd; ++aIter) + for (const auto& rEntry : aWW8ListStyleCounts) { - if (aIter->second > nCurrentMaxCount) + if (rEntry.second > nCurrentMaxCount) { - nCurrentMaxCount = aIter->second; - pChosenWW8ListStyle = aIter->first; + nCurrentMaxCount = rEntry.second; + pChosenWW8ListStyle = rEntry.first; } } } @@ -5962,14 +5955,8 @@ void SwWW8ImplReader::SetOutlineStyles() // its default outline level is applied. SwNumRule aOutlineRule(*m_rDoc.GetOutlineNumRule()); bool bAppliedChangedOutlineStyle = false; - std::vector<SwWW8StyInf*>::iterator aStylesIterEnd - = aWW8BuiltInHeadingStyles.end(); - for (std::vector<SwWW8StyInf*>::iterator aStyleIter - = aWW8BuiltInHeadingStyles.begin(); - aStyleIter != aStylesIterEnd; ++aStyleIter) + for (const SwWW8StyInf* pStyleInf : aWW8BuiltInHeadingStyles) { - SwWW8StyInf* pStyleInf = (*aStyleIter); - if (!pStyleInf->m_bColl) //Character Style continue; @@ -6084,11 +6071,10 @@ void SwWW8ImplReader::GetSmartTagInfo(SwFltRDFMark& rMark) // Check if the smart tag bookmark refers to a valid factoid type. const MSOPropertyBag& rPropertyBag = m_pSmartTagData->m_aPropBags[rMark.GetHandle()]; - auto itPropertyBag = m_pSmartTagData->m_aPropBagStore.m_aFactoidTypes.begin(); - for (; itPropertyBag != m_pSmartTagData->m_aPropBagStore.m_aFactoidTypes.end(); ++itPropertyBag) - if (itPropertyBag->m_nId == rPropertyBag.m_nId) - break; - if (itPropertyBag == m_pSmartTagData->m_aPropBagStore.m_aFactoidTypes.end()) + auto& rFactoidTypes = m_pSmartTagData->m_aPropBagStore.m_aFactoidTypes; + auto itPropertyBag = std::find_if(rFactoidTypes.begin(), rFactoidTypes.end(), + [&rPropertyBag](const MSOFactoidType& rType) { return rType.m_nId == rPropertyBag.m_nId; }); + if (itPropertyBag == rFactoidTypes.end()) return; // Check if the factoid is an RDF one. diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index 527b9fcba0c5..51f6ca542053 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -2725,21 +2725,18 @@ void SwWW8ImplReader::Read_SubF_Ruby( WW8ReadFieldParams& rReadParam) sal_uInt16 nScript = g_pBreakIt->GetBreakIter()->getScriptType(sRuby, 0); //Check to see if we already have a ruby charstyle that this fits - std::vector<const SwCharFormat*>::const_iterator aEnd = - m_aRubyCharFormats.end(); - for(std::vector<const SwCharFormat*>::const_iterator aIter - = m_aRubyCharFormats.begin(); aIter != aEnd; ++aIter) + for(const auto& rpCharFormat : m_aRubyCharFormats) { const SvxFontHeightItem &rFH = - ItemGet<SvxFontHeightItem>(*(*aIter), + ItemGet<SvxFontHeightItem>(*rpCharFormat, GetWhichOfScript(RES_CHRATR_FONTSIZE,nScript)); if (rFH.GetHeight() == nFontSize*10) { - const SvxFontItem &rF = ItemGet<SvxFontItem>(*(*aIter), + const SvxFontItem &rF = ItemGet<SvxFontItem>(*rpCharFormat, GetWhichOfScript(RES_CHRATR_FONT,nScript)); if (rF.GetFamilyName() == sFontName) { - pCharFormat=*aIter; + pCharFormat = rpCharFormat; break; } } @@ -3244,14 +3241,10 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8FieldDesc* pF, OUString& rStr ) } else { - for (SwFormTokens::iterator aItr = aPattern.begin();aItr!= aPattern.end();++aItr) - { - if (aItr->eTokenType == TOKEN_PAGE_NUMS) - { - aPattern.insert(aItr,aLinkStart); - break; - } - } + auto aItr = std::find_if(aPattern.begin(), aPattern.end(), + [](const SwFormToken& rToken) { return rToken.eTokenType == TOKEN_PAGE_NUMS; }); + if (aItr != aPattern.end()) + aPattern.insert(aItr, aLinkStart); } aPattern.push_back(aLinkEnd); aForm.SetPattern(nLevel, aPattern); diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index f240b8ffe969..b422202e14e3 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -663,12 +663,10 @@ SwSectionFormat *wwSectionManager::InsertSection( return nullptr; SwPageDesc *pPage = nullptr; - auto aEnd = maSegments.rend(); - for (auto aIter = maSegments.rbegin(); aIter != aEnd; ++aIter) - { - if (nullptr != (pPage = aIter->mpPage)) - break; - } + auto aIter = std::find_if(maSegments.rbegin(), maSegments.rend(), + [](const wwSection& rSegment) { return rSegment.mpPage != nullptr; }); + if (aIter != maSegments.rend()) + pPage = aIter->mpPage; OSL_ENSURE(pPage, "no page outside this section!"); diff --git a/sw/source/filter/ww8/ww8toolbar.cxx b/sw/source/filter/ww8/ww8toolbar.cxx index 2487cbb0f9f9..eeb6f4212601 100644 --- a/sw/source/filter/ww8/ww8toolbar.cxx +++ b/sw/source/filter/ww8/ww8toolbar.cxx @@ -96,16 +96,14 @@ Customization* SwCTBWrapper::GetCustomizaton( sal_Int16 index ) SwCTB* SwCTBWrapper::GetCustomizationData( const OUString& sTBName ) { - SwCTB* pCTB = nullptr; - for ( std::vector< Customization >::iterator it = rCustomizations.begin(); it != rCustomizations.end(); ++it ) - { - if ( it->GetCustomizationData() && it->GetCustomizationData()->GetName() == sTBName ) - { - pCTB = it->GetCustomizationData(); - break; - } - } - return pCTB; + auto it = std::find_if(rCustomizations.begin(), rCustomizations.end(), + [&sTBName](Customization& rCustomization) { + SwCTB* pCTB = rCustomization.GetCustomizationData(); + return pCTB && pCTB->GetName() == sTBName; + }); + if (it != rCustomizations.end()) + return it->GetCustomizationData(); + return nullptr; } bool SwCTBWrapper::Read( SvStream& rS ) @@ -161,29 +159,27 @@ bool SwCTBWrapper::Read( SvStream& rS ) rCustomizations.push_back( aCust ); } } - std::vector< sal_Int16 >::iterator it_end = dropDownMenuIndices.end(); - for ( std::vector< sal_Int16 >::iterator it = dropDownMenuIndices.begin(); it != it_end; ++it ) + for ( const auto& rIndex : dropDownMenuIndices ) { - if (*it < 0 || static_cast<size_t>(*it) >= rCustomizations.size()) + if (rIndex < 0 || static_cast<size_t>(rIndex) >= rCustomizations.size()) continue; - rCustomizations[*it].bIsDroppedMenuTB = true; + rCustomizations[rIndex].bIsDroppedMenuTB = true; } return rS.good(); } SwTBC* SwCTBWrapper::GetTBCAtOffset( sal_uInt32 nStreamOffset ) { - for ( std::vector< SwTBC >::iterator it = rtbdc.begin(); it != rtbdc.end(); ++it ) - { - if ( (*it).GetOffset() == nStreamOffset ) - return &(*it); - } + auto it = std::find_if(rtbdc.begin(), rtbdc.end(), + [&nStreamOffset](SwTBC& rItem) { return rItem.GetOffset() == nStreamOffset; }); + if ( it != rtbdc.end() ) + return &(*it); return nullptr; } bool SwCTBWrapper::ImportCustomToolBar( SfxObjectShell& rDocSh ) { - for ( std::vector< Customization >::iterator it = rCustomizations.begin(); it != rCustomizations.end(); ++it ) + for ( auto& rCustomization : rCustomizations ) { try { @@ -197,7 +193,7 @@ bool SwCTBWrapper::ImportCustomToolBar( SfxObjectShell& rDocSh ) CustomToolBarImportHelper helper(rDocSh, xCfgMgr); helper.setMSOCommandMap( new MSOWordCommandConvertor() ); - if ( !(*it).ImportCustomToolBar( *this, helper ) ) + if ( !rCustomization.ImportCustomToolBar( *this, helper ) ) return false; } catch (...) @@ -256,20 +252,20 @@ bool Customization::ImportMenu( SwCTBWrapper& rWrapper, CustomToolBarImportHelpe { if ( tbidForTBD == 0x25 ) // we can handle in a limited way additions the built-in menu bar { - for ( std::vector< TBDelta >::iterator it = customizationDataTBDelta.begin(); it != customizationDataTBDelta.end(); ++it ) + for ( auto& rTBDelta : customizationDataTBDelta ) { // for each new menu ( control that drops a toolbar ) // import a toolbar - if ( it->ControlIsInserted() && it->ControlDropsToolBar() ) + if ( rTBDelta.ControlIsInserted() && rTBDelta.ControlDropsToolBar() ) { - Customization* pCust = pWrapper->GetCustomizaton( it->CustomizationIndex() ); + Customization* pCust = pWrapper->GetCustomizaton( rTBDelta.CustomizationIndex() ); if ( pCust ) { // currently only support built-in menu const OUString sMenuBar( "private:resource/menubar/menubar" ); // Get menu name - SwTBC* pTBC = pWrapper->GetTBCAtOffset( it->TBCStreamOffset() ); + SwTBC* pTBC = pWrapper->GetTBCAtOffset( rTBDelta.TBCStreamOffset() ); if ( !pTBC ) return false; const OUString sMenuName = pTBC->GetCustomText().replace('&','~'); @@ -442,10 +438,10 @@ bool SwCTB::ImportCustomToolBar( SwCTBWrapper& rWrapper, CustomToolBarImportHelp xProps->setPropertyValue( "UIName", uno::makeAny( name.getString() ) ); const OUString sToolBarName = "private:resource/toolbar/custom_" + name.getString(); - for ( std::vector< SwTBC >::iterator it = rTBC.begin(); it != rTBC.end(); ++it ) + for ( auto& rItem : rTBC ) { // createToolBar item for control - if ( !it->ImportToolBarControl( rWrapper, xIndexContainer, helper, IsMenuToolbar() ) ) + if ( !rItem.ImportToolBarControl( rWrapper, xIndexContainer, helper, IsMenuToolbar() ) ) return false; } @@ -472,10 +468,10 @@ bool SwCTB::ImportCustomToolBar( SwCTBWrapper& rWrapper, CustomToolBarImportHelp bool SwCTB::ImportMenuTB( SwCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& xIndexContainer, CustomToolBarImportHelper& rHelper ) { - for ( std::vector< SwTBC >::iterator it = rTBC.begin(); it != rTBC.end(); ++it ) + for ( auto& rItem : rTBC ) { // createToolBar item for control - if ( !it->ImportToolBarControl( rWrapper, xIndexContainer, rHelper, true ) ) + if ( !rItem.ImportToolBarControl( rWrapper, xIndexContainer, rHelper, true ) ) return false; } return true; diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx index ade99db16295..ce3573b7b946 100644 --- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx +++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx @@ -286,10 +286,9 @@ XMLRedlineImportHelper::XMLRedlineImportHelper( XMLRedlineImportHelper::~XMLRedlineImportHelper() { // delete all left over (and obviously incomplete) RedlineInfos (and map) - RedlineMapType::iterator aFind = aRedlineMap.begin(); - for( ; aRedlineMap.end() != aFind; ++aFind ) + for( auto& rEntry : aRedlineMap ) { - RedlineInfo* pInfo = aFind->second; + RedlineInfo* pInfo = rEntry.second; // left-over redlines. Insert them if possible (but assert), // and delete the incomplete ones. Finally, delete it. diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx index d099a91c9e12..bbc59643506b 100644 --- a/sw/source/filter/xml/xmlfmte.cxx +++ b/sw/source/filter/xml/xmlfmte.cxx @@ -290,20 +290,17 @@ void SwXMLAutoStylePoolP::exportStyleAttributes( if( XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily ) { - for( std::vector< XMLPropertyState >::const_iterator - aProperty = rProperties.begin(); - aProperty != rProperties.end(); - ++aProperty ) + for( const auto& rProperty : rProperties ) { - if (aProperty->mnIndex != -1) // #i26762# + if (rProperty.mnIndex != -1) // #i26762# { switch( rPropExp.getPropertySetMapper()-> - GetEntryContextId( aProperty->mnIndex ) ) + GetEntryContextId( rProperty.mnIndex ) ) { case CTF_NUMBERINGSTYLENAME: { OUString sStyleName; - aProperty->maValue >>= sStyleName; + rProperty.maValue >>= sStyleName; // #i70748# - export also empty list styles if( !sStyleName.isEmpty() ) { @@ -319,7 +316,7 @@ void SwXMLAutoStylePoolP::exportStyleAttributes( case CTF_PAGEDESCNAME: { OUString sStyleName; - aProperty->maValue >>= sStyleName; + rProperty.maValue >>= sStyleName; GetExport().AddAttribute( XML_NAMESPACE_STYLE, sMasterPageName, GetExport().EncodeStyleName( sStyleName ) ); diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index 90501aab95b7..58ef026cf7e1 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -339,7 +339,7 @@ bool SwXMLTableFrameFormatsSort_Impl::AddCell( SwFrameFormat& rFrameFormat, return false; // order is: -/-/-/num, - // -/-/box/-, --/-/box/num, + // -/-/box/-, -/-/box/num, // -/brush/-/-, -/brush/-/num, -/brush/box/-, -/brush/box/num, // vert/-/-/-, vert/-/-/num, vert/-/box/-, ver/-/box/num, // vert/brush/-/-, vert/brush/-/num, vert/brush/box/-, diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx index 8517963383f8..2207d929a9c4 100644 --- a/sw/source/filter/xml/xmltbli.cxx +++ b/sw/source/filter/xml/xmltbli.cxx @@ -2378,20 +2378,20 @@ void SwXMLTableContext::MakeTable_( SwTableBox *pBox ) sal_Int32 nRelWidth = 0; sal_Int32 nMinRelColWidth = 0; sal_uInt32 nRelCols = 0; - for( colIter = m_aColumnWidths.begin(); colIter < m_aColumnWidths.end(); ++colIter) + for( const auto& rCol : m_aColumnWidths) { - if( colIter->isRelative ) + if( rCol.isRelative ) { - nRelWidth += colIter->width; - if( 0 == nMinRelColWidth || colIter->width < nMinRelColWidth ) - nMinRelColWidth = colIter->width; + nRelWidth += rCol.width; + if( 0 == nMinRelColWidth || rCol.width < nMinRelColWidth ) + nMinRelColWidth = rCol.width; nRelCols++; } else { - nAbsWidth += colIter->width; - if( 0 == nMinAbsColWidth || colIter->width < nMinAbsColWidth ) - nMinAbsColWidth = colIter->width; + nAbsWidth += rCol.width; + if( 0 == nMinAbsColWidth || rCol.width < nMinAbsColWidth ) + nMinAbsColWidth = rCol.width; } } sal_uInt32 nAbsCols = nCols - nRelCols; @@ -2410,20 +2410,22 @@ void SwXMLTableContext::MakeTable_( SwTableBox *pBox ) if( 0 == nMinRelColWidth ) nMinRelColWidth = nMinAbsColWidth; - for( colIter = m_aColumnWidths.begin(); nAbsCols > 0 && colIter < m_aColumnWidths.end(); ++colIter) + for( auto& rCol : m_aColumnWidths) { - if( !colIter->isRelative ) + if( !rCol.isRelative ) { if (nMinAbsColWidth == 0) throw o3tl::divide_by_zero(); sal_Int32 nVal; - if (o3tl::checked_multiply<sal_Int32>(colIter->width, nMinRelColWidth, nVal)) + if (o3tl::checked_multiply<sal_Int32>(rCol.width, nMinRelColWidth, nVal)) throw std::overflow_error("overflow in multiply"); sal_Int32 nRelCol = nVal / nMinAbsColWidth; - colIter->width = nRelCol; - colIter->isRelative = true; + rCol.width = nRelCol; + rCol.isRelative = true; nRelWidth += nRelCol; nAbsCols--; + if (nAbsCols <= 0) + break; } } } @@ -2494,9 +2496,9 @@ void SwXMLTableContext::MakeTable_( SwTableBox *pBox ) // Otherwise, if there is enough space for every column, every // column gets this space. - for( colIter = m_aColumnWidths.begin(); nRelCols > 0 && colIter < m_aColumnWidths.end(); ++colIter ) + for( auto& rCol : m_aColumnWidths ) { - if( colIter->isRelative ) + if( rCol.isRelative ) { sal_Int32 nAbsCol; if( 1 == nRelCols ) @@ -2513,20 +2515,22 @@ void SwXMLTableContext::MakeTable_( SwTableBox *pBox ) } else if( bMinExtra ) { - sal_Int32 nExtraRelCol = colIter->width - nMinRelColWidth; + sal_Int32 nExtraRelCol = rCol.width - nMinRelColWidth; nAbsCol = MINLAY + (nExtraRelCol * nExtraAbs) / nExtraRel; } else { - nAbsCol = ( colIter->width * nAbsForRelWidth) / nRelWidth; + nAbsCol = ( rCol.width * nAbsForRelWidth) / nRelWidth; } } - colIter->width = nAbsCol; - colIter->isRelative = false; + rCol.width = nAbsCol; + rCol.isRelative = false; nAbsForRelWidth -= nAbsCol; nAbsWidth += nAbsCol; nRelCols--; + if (nRelCols <= 0) + break; } } } diff --git a/sw/source/filter/xml/xmltexti.cxx b/sw/source/filter/xml/xmltexti.cxx index d1b1253b66e5..02851e8e6a48 100644 --- a/sw/source/filter/xml/xmltexti.cxx +++ b/sw/source/filter/xml/xmltexti.cxx @@ -932,16 +932,13 @@ void SwXMLTextImportHelper::endAppletOrPlugin( const sal_Int32 nCount = rParamMap.size(); uno::Sequence< beans::PropertyValue > aCommandSequence( nCount ); - std::map < const OUString, OUString > ::iterator aIter = rParamMap.begin(); - std::map < const OUString, OUString > ::iterator aEnd = rParamMap.end(); sal_Int32 nIndex=0; - while (aIter != aEnd ) + for (const auto& rParam : rParamMap ) { - aCommandSequence[nIndex].Name = (*aIter).first; + aCommandSequence[nIndex].Name = rParam.first; aCommandSequence[nIndex].Handle = -1; - aCommandSequence[nIndex].Value <<= (*aIter).second; + aCommandSequence[nIndex].Value <<= rParam.second; aCommandSequence[nIndex].State = beans::PropertyState_DIRECT_VALUE; - ++aIter; ++nIndex; } |