diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-02-20 01:10:07 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-20 07:17:38 +0100 |
commit | 6a143985bdc5d12d1f9e8cf8592440282986c099 (patch) | |
tree | 346e09d6ba1146b52a6a484a2883f3e898184648 /editeng | |
parent | d707a5e64ba53ddb7669cca725915527aa788a6b (diff) |
Simplify containers iterations in desktop, dtrans, editeng, extensions
Use range-based loop or replace with STL functions
Change-Id: Ic5389d123d0a6a32a8bb46b081165e94a7c55292
Reviewed-on: https://gerrit.libreoffice.org/68036
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/qa/unit/core-test.cxx | 54 | ||||
-rw-r--r-- | editeng/source/accessibility/AccessibleParaManager.cxx | 4 | ||||
-rw-r--r-- | editeng/source/accessibility/AccessibleStaticTextBase.cxx | 5 | ||||
-rw-r--r-- | editeng/source/editeng/editdoc.cxx | 29 | ||||
-rw-r--r-- | editeng/source/editeng/edtspell.cxx | 51 | ||||
-rw-r--r-- | editeng/source/editeng/impedit4.cxx | 19 | ||||
-rw-r--r-- | editeng/source/outliner/outliner.cxx | 14 |
7 files changed, 62 insertions, 114 deletions
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index 1b8c079b58ba..020a5a32d7aa 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -884,36 +884,20 @@ void Test::testHyperlinkSearch() bool hasBold(const editeng::Section& rSecAttr) { - std::vector<const SfxPoolItem*>::const_iterator it = rSecAttr.maAttributes.begin(), itEnd = rSecAttr.maAttributes.end(); - for (; it != itEnd; ++it) - { - const SfxPoolItem* p = *it; - if (p->Which() != EE_CHAR_WEIGHT) - continue; - - if (static_cast<const SvxWeightItem*>(p)->GetWeight() != WEIGHT_BOLD) - continue; - - return true; - } - return false; + return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), + [](const SfxPoolItem* p) { + return p->Which() == EE_CHAR_WEIGHT + && static_cast<const SvxWeightItem*>(p)->GetWeight() == WEIGHT_BOLD; + }); } bool hasItalic(const editeng::Section& rSecAttr) { - std::vector<const SfxPoolItem*>::const_iterator it = rSecAttr.maAttributes.begin(), itEnd = rSecAttr.maAttributes.end(); - for (; it != itEnd; ++it) - { - const SfxPoolItem* p = *it; - if (p->Which() != EE_CHAR_ITALIC) - continue; - - if (static_cast<const SvxPostureItem*>(p)->GetPosture() != ITALIC_NORMAL) - continue; - - return true; - } - return false; + return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), + [](const SfxPoolItem* p) { + return p->Which() == EE_CHAR_ITALIC + && static_cast<const SvxPostureItem*>(p)->GetPosture() == ITALIC_NORMAL; + }); } void Test::testBoldItalicCopyPaste() @@ -1104,19 +1088,11 @@ void Test::testBoldItalicCopyPaste() // Auxiliary function to test Underline text Copy/Paste using Legacy Format bool hasUnderline(const editeng::Section& rSecAttr) { - std::vector<const SfxPoolItem*>::const_iterator it = rSecAttr.maAttributes.begin(), itEnd = rSecAttr.maAttributes.end(); - for (; it != itEnd; ++it) - { - const SfxPoolItem* p = *it; - if (p->Which() != EE_CHAR_UNDERLINE) - continue; - - if (static_cast<const SvxUnderlineItem*>(p)->GetLineStyle() != LINESTYLE_SINGLE) - continue; - - return true; - } - return false; + return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), + [](const SfxPoolItem* p) { + return p->Which() == EE_CHAR_UNDERLINE + && static_cast<const SvxUnderlineItem*>(p)->GetLineStyle() == LINESTYLE_SINGLE; + }); } void Test::testUnderlineCopyPaste() diff --git a/editeng/source/accessibility/AccessibleParaManager.cxx b/editeng/source/accessibility/AccessibleParaManager.cxx index c8db48792835..8a7ce274e5d0 100644 --- a/editeng/source/accessibility/AccessibleParaManager.cxx +++ b/editeng/source/accessibility/AccessibleParaManager.cxx @@ -235,8 +235,8 @@ namespace accessibility rChild.SetState( AccessibleStateType::FOCUSED ); // add states passed from outside - for( VectorOfStates::const_iterator aIt = maChildStates.begin(), aEnd = maChildStates.end(); aIt != aEnd; ++aIt ) - rChild.SetState( *aIt ); + for( const auto& rState : maChildStates ) + rChild.SetState( rState ); } void AccessibleParaManager::SetState( sal_Int32 nChild, const sal_Int16 nStateId ) diff --git a/editeng/source/accessibility/AccessibleStaticTextBase.cxx b/editeng/source/accessibility/AccessibleStaticTextBase.cxx index 73a93f210326..c28c94b7dc99 100644 --- a/editeng/source/accessibility/AccessibleStaticTextBase.cxx +++ b/editeng/source/accessibility/AccessibleStaticTextBase.cxx @@ -913,12 +913,11 @@ namespace accessibility uno::Sequence< beans::PropertyValue > aSeq = mpImpl->GetParagraph( nPara ).getDefaultAttributes( RequestedAttributes ); PropertyValueVector aIntersectionVec; - PropertyValueVector::const_iterator aEnd = aDefAttrVec.end(); - for ( PropertyValueVector::const_iterator aItr = aDefAttrVec.begin(); aItr != aEnd; ++aItr ) + for ( const auto& rDefAttr : aDefAttrVec ) { const beans::PropertyValue* pItr = aSeq.getConstArray(); const beans::PropertyValue* pEnd = pItr + aSeq.getLength(); - const beans::PropertyValue* pFind = std::find_if( pItr, pEnd, PropertyValueEqualFunctor(*aItr) ); + const beans::PropertyValue* pFind = std::find_if( pItr, pEnd, PropertyValueEqualFunctor(rDefAttr) ); if ( pFind != pEnd ) { aIntersectionVec.push_back( *pFind ); diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index d19542ddc056..d86d39fbf18a 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -2798,12 +2798,13 @@ const EditCharAttrib* CharAttribList::FindAttrib( sal_uInt16 nWhich, sal_Int32 n { // Backwards, if one ends where the next starts. // => The starting one is the valid one ... - AttribsType::const_reverse_iterator it = aAttribs.rbegin(), itEnd = aAttribs.rend(); - for (; it != itEnd; ++it) + AttribsType::const_reverse_iterator it = std::find_if(aAttribs.rbegin(), aAttribs.rend(), + [&nWhich, &nPos](const AttribsType::value_type& rxAttr) { + return rxAttr->Which() == nWhich && rxAttr->IsIn(nPos); }); + if (it != aAttribs.rend()) { const EditCharAttrib& rAttr = **it; - if (rAttr.Which() == nWhich && rAttr.IsIn(nPos)) - return &rAttr; + return &rAttr; } return nullptr; } @@ -2812,12 +2813,13 @@ EditCharAttrib* CharAttribList::FindAttrib( sal_uInt16 nWhich, sal_Int32 nPos ) { // Backwards, if one ends where the next starts. // => The starting one is the valid one ... - AttribsType::reverse_iterator it = aAttribs.rbegin(), itEnd = aAttribs.rend(); - for (; it != itEnd; ++it) + AttribsType::reverse_iterator it = std::find_if(aAttribs.rbegin(), aAttribs.rend(), + [&nWhich, &nPos](AttribsType::value_type& rxAttr) { + return rxAttr->Which() == nWhich && rxAttr->IsIn(nPos); }); + if (it != aAttribs.rend()) { EditCharAttrib& rAttr = **it; - if (rAttr.Which() == nWhich && rAttr.IsIn(nPos)) - return &rAttr; + return &rAttr; } return nullptr; } @@ -2836,14 +2838,9 @@ const EditCharAttrib* CharAttribList::FindNextAttrib( sal_uInt16 nWhich, sal_Int bool CharAttribList::HasAttrib( sal_Int32 nStartPos, sal_Int32 nEndPos ) const { - AttribsType::const_reverse_iterator it = aAttribs.rbegin(), itEnd = aAttribs.rend(); - for (; it != itEnd; ++it) - { - const EditCharAttrib& rAttr = **it; - if (rAttr.GetStart() < nEndPos && rAttr.GetEnd() > nStartPos) - return true; - } - return false; + return std::any_of(aAttribs.rbegin(), aAttribs.rend(), + [&nStartPos, &nEndPos](const AttribsType::value_type& rxAttr) { + return rxAttr->GetStart() < nEndPos && rxAttr->GetEnd() > nStartPos; }); } diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx index 81143ce33b5a..97d37b315586 100644 --- a/editeng/source/editeng/edtspell.cxx +++ b/editeng/source/editeng/edtspell.cxx @@ -401,27 +401,22 @@ void WrongList::ClearWrongs( size_t nStart, size_t nEnd, void WrongList::InsertWrong( size_t nStart, size_t nEnd ) { - WrongList::iterator nPos = maRanges.end(); - for (WrongList::iterator i = maRanges.begin(); i != maRanges.end(); ++i) + WrongList::iterator nPos = std::find_if(maRanges.begin(), maRanges.end(), + [&nStart](const editeng::MisspellRange& rRange) { return rRange.mnStart >= nStart; }); + + if (nPos != maRanges.end()) { - if (i->mnStart >= nStart) { - nPos = i; - { - // It can really only happen that the Wrong starts exactly here - // and runs along, but not that there are several ranges ... - // Exactly in the range is no one allowed to be, otherwise this - // Method can not be called! - SAL_WARN_IF((i->mnStart != nStart || i->mnEnd <= nEnd) && i->mnStart <= nEnd, "editeng", "InsertWrong: RangeMismatch!"); - if (i->mnStart == nStart && i->mnEnd > nEnd) - i->mnStart = nEnd + 1; - } - break; + // It can really only happen that the Wrong starts exactly here + // and runs along, but not that there are several ranges ... + // Exactly in the range is no one allowed to be, otherwise this + // Method can not be called! + SAL_WARN_IF((nPos->mnStart != nStart || nPos->mnEnd <= nEnd) && nPos->mnStart <= nEnd, "editeng", "InsertWrong: RangeMismatch!"); + if (nPos->mnStart == nStart && nPos->mnEnd > nEnd) + nPos->mnStart = nEnd + 1; } - } - - if (nPos != maRanges.end()) maRanges.insert(nPos, editeng::MisspellRange(nStart, nEnd)); + } else maRanges.emplace_back(nStart, nEnd); @@ -444,20 +439,12 @@ bool WrongList::operator==(const WrongList& rCompare) const { // check direct members if(GetInvalidStart() != rCompare.GetInvalidStart() - || GetInvalidEnd() != rCompare.GetInvalidEnd() - || maRanges.size() != rCompare.maRanges.size()) + || GetInvalidEnd() != rCompare.GetInvalidEnd()) return false; - WrongList::const_iterator rCB = rCompare.maRanges.begin(); - - for (auto const& rangeA : maRanges) - { - if(rangeA.mnStart != rCB->mnStart || rangeA.mnEnd != rCB->mnEnd) - return false; - ++rCB; - } - - return true; + return std::equal(maRanges.begin(), maRanges.end(), rCompare.maRanges.begin(), rCompare.maRanges.end(), + [](const editeng::MisspellRange& a, const editeng::MisspellRange& b) { + return a.mnStart == b.mnStart && a.mnEnd == b.mnEnd; }); } bool WrongList::empty() const @@ -506,10 +493,8 @@ bool WrongList::DbgIsBuggy() const bool bError = false; for (WrongList::const_iterator i = maRanges.begin(); !bError && (i != maRanges.end()); ++i) { - for (WrongList::const_iterator j = i + 1; !bError && (j != maRanges.end()); ++j) - { - bError = i->mnStart <= j->mnEnd && j->mnStart <= i->mnEnd; - } + bError = std::any_of(i + 1, maRanges.end(), [&i](const editeng::MisspellRange& rRange) { + return i->mnStart <= rRange.mnEnd && rRange.mnStart <= i->mnEnd; }); } return bError; } diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index bf235228a05d..2ac00ef7481c 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -652,9 +652,8 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel ) rOutput.WriteCharPtr( "}}" ); // 1xparentheses paragraphs, 1xparentheses RTF document rOutput.Flush(); - std::vector<SvxFontItem*>::iterator it; - for (it = aFontTable.begin(); it != aFontTable.end(); ++it) - delete *it; + for (auto& pItem : aFontTable) + delete pItem; return rOutput.GetError(); } @@ -2122,8 +2121,6 @@ void ImpEditEngine::ApplyChangedSentence(EditView const & rEditView, aSet.Put(SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId)); SetAttribs( *aCurrentOldPosition, aSet ); } - if(aCurrentNewPortion == rNewPortions.begin()) - break; } while(aCurrentNewPortion != rNewPortions.begin()); } @@ -2139,15 +2136,14 @@ void ImpEditEngine::ApplyChangedSentence(EditView const & rEditView, //delete the sentence completely ImpDeleteSelection( aAllSentence ); - svx::SpellPortions::const_iterator aCurrentNewPortion = rNewPortions.begin(); EditPaM aCurrentPaM = aAllSentence.Min(); - while(aCurrentNewPortion != rNewPortions.end()) + for(const auto& rCurrentNewPortion : rNewPortions) { //set the language attribute LanguageType eCurLanguage = GetLanguage( aCurrentPaM ); - if(eCurLanguage != aCurrentNewPortion->eLanguage) + if(eCurLanguage != rCurrentNewPortion.eLanguage) { - SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( aCurrentNewPortion->eLanguage ); + SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( rCurrentNewPortion.eLanguage ); sal_uInt16 nLangWhichId = EE_CHAR_LANGUAGE; switch(nScriptType) { @@ -2156,12 +2152,11 @@ void ImpEditEngine::ApplyChangedSentence(EditView const & rEditView, default: break; } SfxItemSet aSet( aEditDoc.GetItemPool(), {{nLangWhichId, nLangWhichId}}); - aSet.Put(SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId)); + aSet.Put(SvxLanguageItem(rCurrentNewPortion.eLanguage, nLangWhichId)); SetAttribs( aCurrentPaM, aSet ); } //insert the new string and set the cursor to the end of the inserted string - aCurrentPaM = ImpInsertText( aCurrentPaM , aCurrentNewPortion->sText ); - ++aCurrentNewPortion; + aCurrentPaM = ImpInsertText( aCurrentPaM , rCurrentNewPortion.sText ); } } UndoActionEnd(); diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index 19fb8fa0ec47..a7ec83d0837d 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -1292,16 +1292,12 @@ size_t Outliner::InsertView( OutlinerView* pView, size_t nIndex ) void Outliner::RemoveView( OutlinerView const * pView ) { - - for ( ViewList::iterator it = aViewList.begin(); it != aViewList.end(); ++it ) + ViewList::iterator it = std::find(aViewList.begin(), aViewList.end(), pView); + if (it != aViewList.end()) { - if ( *it == pView ) - { - pView->pEditView->HideCursor(); // HACK - pEditEngine->RemoveView( pView->pEditView.get() ); - aViewList.erase( it ); - break; - } + pView->pEditView->HideCursor(); // HACK + pEditEngine->RemoveView( pView->pEditView.get() ); + aViewList.erase( it ); } } |