diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-11-05 14:57:19 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-11-07 08:13:49 +0100 |
commit | db601f697acff89e216228f2d5828b1563e58aa0 (patch) | |
tree | 109c256e249cc270480c7130807699c51d8b75cf /sw/source/core/text/wrong.cxx | |
parent | 9476ecb71b1acc66506a768a5fe0c123afd46b93 (diff) |
Simplify containers iterations in sw/source/core/[t-v]*
Use range-based loop or replace with STL functions
Change-Id: Ib4a0da0c452dbfa00a1d7ec79f9570e41eda0d41
Reviewed-on: https://gerrit.libreoffice.org/62893
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/core/text/wrong.cxx')
-rw-r--r-- | sw/source/core/text/wrong.cxx | 81 |
1 files changed, 28 insertions, 53 deletions
diff --git a/sw/source/core/text/wrong.cxx b/sw/source/core/text/wrong.cxx index d85cf9a99bdf..4e1668104f32 100644 --- a/sw/source/core/text/wrong.cxx +++ b/sw/source/core/text/wrong.cxx @@ -198,18 +198,12 @@ sal_uInt16 SwWrongList::GetWrongPos( sal_Int32 nValue ) const // position of the first smart tag which covers nValue if ( !maList[0].maType.isEmpty() || maList[0].mpSubList ) { - for (std::vector<SwWrongArea>::const_iterator aIter(maList.begin()), aEnd(maList.end()); aIter != aEnd; ++aIter) - { - const sal_Int32 nSTPos = (*aIter).mnPos; - const sal_Int32 nSTLen = (*aIter).mnLen; - if ( nSTPos <= nValue && nValue < nSTPos + nSTLen ) - break; - if ( nSTPos > nValue ) - break; - - ++nMin; - } - return nMin; + auto aIter = std::find_if(maList.begin(), maList.end(), + [nValue](const SwWrongArea& rST) { + return (rST.mnPos <= nValue && nValue < rST.mnPos + rST.mnLen) + || (rST.mnPos > nValue); + }); + return static_cast<sal_uInt16>(std::distance(maList.begin(), aIter)); } --nMax; @@ -591,38 +585,36 @@ void SwWrongList::Remove(sal_uInt16 nIdx, sal_uInt16 nLen ) } void SwWrongList::RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd ) { - sal_uInt16 nDelPos = 0; - sal_uInt16 nDel = 0; - std::vector<SwWrongArea>::const_iterator aIter(maList.begin()), aEnd(maList.end()); - while( aIter != aEnd && (*aIter).mnPos < nBegin ) - { - ++aIter; - ++nDelPos; - } + std::vector<SwWrongArea>::const_iterator aEnd(maList.end()); + auto aDelIter = std::find_if(maList.cbegin(), aEnd, + [nBegin](const SwWrongArea& rST) { return rST.mnPos >= nBegin; }); + auto aIter = aDelIter; if( WRONGLIST_GRAMMAR == GetWrongListType() ) { - while( aIter != aEnd && nBegin < nEnd && nEnd > (*aIter).mnPos ) + if( nBegin < nEnd ) { - ++aIter; - ++nDel; + aIter = std::find_if(aDelIter, aEnd, + [nEnd](const SwWrongArea& rST) { return rST.mnPos >= nEnd; }); } } else { - while( aIter != aEnd && nBegin == (*aIter).mnPos && nEnd == (*aIter).mnPos +(*aIter).mnLen ) - { - ++aIter; - ++nDel; - } + aIter = std::find_if(aDelIter, aEnd, + [nBegin, nEnd](const SwWrongArea& rST) { + return (rST.mnPos != nBegin) || ((rST.mnPos + rST.mnLen) != nEnd); + }); } + auto nDel = static_cast<sal_uInt16>(std::distance(aDelIter, aIter)); if( nDel ) + { + auto nDelPos = static_cast<sal_uInt16>(std::distance(maList.cbegin(), aDelIter)); Remove( nDelPos, nDel ); + } } bool SwWrongList::LookForEntry( sal_Int32 nBegin, sal_Int32 nEnd ) { - std::vector<SwWrongArea>::iterator aIter = maList.begin(); - while( aIter != maList.end() && (*aIter).mnPos < nBegin ) - ++aIter; + auto aIter = std::find_if(maList.begin(), maList.end(), + [nBegin](const SwWrongArea& rST) { return rST.mnPos >= nBegin; }); return aIter != maList.end() && nBegin == (*aIter).mnPos && nEnd == (*aIter).mnPos + (*aIter).mnLen; @@ -632,31 +624,14 @@ void SwWrongList::Insert( const OUString& rType, css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag, sal_Int32 nNewPos, sal_Int32 nNewLen ) { - std::vector<SwWrongArea>::iterator aIter = maList.begin(); - - while ( aIter != maList.end() ) + auto aIter = std::find_if(maList.begin(), maList.end(), + [nNewPos](const SwWrongArea& rST) { return nNewPos <= rST.mnPos; }); + if ( aIter != maList.end() && nNewPos == (*aIter).mnPos ) { const sal_Int32 nSTPos = (*aIter).mnPos; - if ( nNewPos < nSTPos ) - { - // insert at current position - break; - } - else if ( nNewPos == nSTPos ) - { - while ( aIter != maList.end() && (*aIter).mnPos == nSTPos ) - { - if ( nNewLen < (*aIter).mnLen ) - { - // insert at current position - break; - } - ++aIter; - } - break; - } - ++aIter; + aIter = std::find_if(aIter, maList.end(), + [nSTPos, nNewLen](const SwWrongArea& rST) { return rST.mnPos != nSTPos || nNewLen < rST.mnLen; }); } maList.insert(aIter, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) ); |