[Libreoffice-commits] core.git: sw/qa sw/source

Arkadiy Illarionov (via logerrit) logerrit at kemper.freedesktop.org
Mon Jul 8 19:24:35 UTC 2019


 sw/qa/extras/globalfilter/globalfilter.cxx     |    7 +--
 sw/qa/extras/inc/bordertest.hxx                |    7 +--
 sw/qa/extras/inc/swmodeltestbase.hxx           |   13 +-----
 sw/qa/extras/mailmerge/mailmerge.cxx           |    8 +--
 sw/qa/extras/tiledrendering/tiledrendering.cxx |    2 
 sw/qa/extras/uiwriter/uiwriter.cxx             |   27 ++++++------
 sw/source/core/access/acchyperlink.cxx         |    5 --
 sw/source/core/access/accpara.cxx              |   53 ++++++-------------------
 sw/source/core/access/accselectionhelper.cxx   |    8 ---
 sw/source/core/doc/docglos.cxx                 |   10 ++--
 sw/source/core/doc/docxforms.cxx               |    6 --
 sw/source/core/edit/edlingu.cxx                |   32 +++++----------
 sw/source/core/fields/authfld.cxx              |   23 +++++-----
 sw/source/core/fields/flddropdown.cxx          |    4 -
 sw/source/core/unocore/SwXTextDefaults.cxx     |    6 --
 sw/source/core/unocore/unochart.cxx            |   46 ++++++++-------------
 sw/source/core/unocore/unocoll.cxx             |   13 ++----
 sw/source/core/unocore/unocrsrhelper.cxx       |    4 -
 sw/source/core/unocore/unodraw.cxx             |   16 ++-----
 sw/source/core/unocore/unoevent.cxx            |    4 -
 sw/source/core/unocore/unoflatpara.cxx         |    8 +--
 sw/source/core/unocore/unoframe.cxx            |   10 +---
 sw/source/core/unocore/unoidx.cxx              |    8 +--
 sw/source/core/unocore/unoobj.cxx              |   31 ++++++--------
 sw/source/core/unocore/unoparagraph.cxx        |   17 ++------
 sw/source/core/unocore/unoport.cxx             |    7 ---
 sw/source/core/unocore/unosett.cxx             |   15 ++-----
 sw/source/core/unocore/unosrch.cxx             |    9 +---
 sw/source/core/unocore/unostyle.cxx            |   12 ++---
 sw/source/core/unocore/unotext.cxx             |   31 +++++---------
 sw/source/core/unocore/unotextmarkup.cxx       |   27 ++++--------
 31 files changed, 176 insertions(+), 293 deletions(-)

New commits:
commit 3e8989d47e3116a99d4b9f6d03800464ff235de8
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sat Jul 6 17:07:05 2019 +0300
Commit:     Arkadiy Illarionov <qarkai at gmail.com>
CommitDate: Mon Jul 8 21:23:39 2019 +0200

    Simplify Sequence iterations in sw/qa/* and sw/source/core/*
    
    Use range-based loops, STL and comphelper functions
    
    Change-Id: I5bd910a86bd80c553cd4a0c044a8eb61084f77ae
    Reviewed-on: https://gerrit.libreoffice.org/75167
    Tested-by: Jenkins
    Reviewed-by: Arkadiy Illarionov <qarkai at gmail.com>

diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index 012e16eb3de2..337d182b4809 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -634,9 +634,8 @@ void Test::testMSCharBackgroundEditing()
             xRun->setPropertyValue("CharHighlight", uno::makeAny(static_cast<sal_Int32>(COL_TRANSPARENT)));
             // Remove shading marker
             uno::Sequence<beans::PropertyValue> aGrabBag = getProperty<uno::Sequence<beans::PropertyValue> >(xRun,"CharInteropGrabBag");
-            for (int j = 0; j < aGrabBag.getLength(); ++j)
+            for (beans::PropertyValue& rProp : aGrabBag)
             {
-                beans::PropertyValue& rProp = aGrabBag[j];
                 if (rProp.Name == "CharShadingMarker")
                 {
                     CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), true, rProp.Value.get<bool>());
@@ -1207,7 +1206,7 @@ void Test::testDropDownFormField()
             {
                 pListEntries->second >>= vListEntries;
 
-                if(vListEntries.getLength())
+                if(vListEntries.hasElements())
                 {
                     auto pResult = pParameters->find(ODF_FORMDROPDOWN_RESULT);
                     if (pResult != pParameters->end())
@@ -1220,7 +1219,7 @@ void Test::testDropDownFormField()
             // The first one is empty
             if(nIndex == 0)
             {
-                CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(0), vListEntries.getLength());
+                CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), !vListEntries.hasElements());
                 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(-1), nSelection);
             }
             else // The second one has list and also a selected item
diff --git a/sw/qa/extras/inc/bordertest.hxx b/sw/qa/extras/inc/bordertest.hxx
index b1376ee36530..52776c38e012 100644
--- a/sw/qa/extras/inc/bordertest.hxx
+++ b/sw/qa/extras/inc/bordertest.hxx
@@ -155,7 +155,6 @@ public:
             {
                 uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW);
                 uno::Sequence<OUString> const cells = xTextTable->getCellNames();
-                sal_Int32 nLength = cells.getLength();
 
                 if(currentTable == sal_Int32(1))
                     tempMap = &map1;
@@ -174,13 +173,13 @@ public:
 
                 BorderLineMap::iterator it = tempMap->begin();
 
-                for (sal_Int32 i = 0; i < nLength; ++i)
+                for (const auto& rCell : cells)
                 {
-                    uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
+                    uno::Reference<table::XCell> xCell = xTextTable->getCellByName(rCell);
                     uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
                     uno::Any aAny = xPropSet->getPropertyValue("TopBorder");
                     table::BorderLine aBorderLine;
-                    it = tempMap->find(cells[i]);
+                    it = tempMap->find(rCell);
                     if ((aAny >>= aBorderLine) && (it!=tempMap->end()))
                     {
                         sal_Int32 innerLineWidth = aBorderLine.InnerLineWidth;
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index fac758a30ccf..db18b5d9b9be 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -603,15 +603,10 @@ protected:
             {
                 uno::Sequence< beans::PropertyValue > aPropertyValue;
                 xLevels->getByIndex(nNumberingLevel) >>= aPropertyValue;
-                for( int j = 0 ; j< aPropertyValue.getLength() ; ++j)
-                {
-                    beans::PropertyValue aProp= aPropertyValue[j];
-                    if (aProp.Name == "NumberingType")
-                    {
-                        nNumberingType = aProp.Value.get<sal_Int16>();
-                        break;
-                    }
-                }
+                auto pProp = std::find_if(aPropertyValue.begin(), aPropertyValue.end(),
+                    [](const beans::PropertyValue& rProp) { return rProp.Name == "NumberingType"; });
+                if (pProp != aPropertyValue.end())
+                    nNumberingType = pProp->Value.get<sal_Int16>();
             }
         }
         return nNumberingType;
diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx b/sw/qa/extras/mailmerge/mailmerge.cxx
index 5395afa25bce..6c5a2de4d495 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -180,14 +180,12 @@ public:
         uno::Sequence< beans::NamedValue > aSeqMailMergeArgs = comphelper::containerToSequence( mMMargs );
         uno::Any res = mxJob->execute( aSeqMailMergeArgs );
 
-        const beans::NamedValue *pArguments = aSeqMailMergeArgs.getConstArray();
         bool bOk = true;
         bool bMMFilenameFromColumn = false;
-        sal_Int32 nArgs = aSeqMailMergeArgs.getLength();
 
-        for (sal_Int32 i = 0; i < nArgs; ++i) {
-            const OUString &rName  = pArguments[i].Name;
-            const uno::Any &rValue = pArguments[i].Value;
+        for (const beans::NamedValue& rArgument : aSeqMailMergeArgs) {
+            const OUString &rName  = rArgument.Name;
+            const uno::Any &rValue = rArgument.Value;
 
             // all error checking was already done by the MM job execution
             if (rName == UNO_NAME_OUTPUT_URL)
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index c06f150ccf32..60d51cfc9739 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -2091,7 +2091,7 @@ void checkPageHeaderOrFooter(const SfxViewShell* pViewShell, sal_uInt16 nWhich,
         CPPUNIT_ASSERT_EQUAL(OUString("Default Style"), aSeq[0]);
     }
     else
-        CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSeq.getLength());
+        CPPUNIT_ASSERT(!aSeq.hasElements());
 };
 
 }
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 471d726e9626..d5a53d73841c 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -1908,17 +1908,17 @@ void SwUiWriterTest::testDefaultsOfOutlineNumbering()
     alocale.Country = "US";
     uno::Sequence<beans::PropertyValues> aPropVal(xDefNum->getDefaultContinuousNumberingLevels(alocale));
     CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aPropVal.getLength());
-    for(int i=0;i<aPropVal.getLength();i++)
+    for(const auto& rPropValues : aPropVal)
     {
-        CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aPropVal[i].getLength());
-        for(int j=0;j<aPropVal[i].getLength();j++)
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rPropValues.getLength());
+        for(const auto& rPropVal : rPropValues)
         {
-            uno::Any aAny = (aPropVal[i])[j].Value;
-            if((aPropVal[i])[j].Name == "Prefix" || (aPropVal[i])[j].Name == "Suffix" || (aPropVal[i])[j].Name == "Transliteration")
+            uno::Any aAny = rPropVal.Value;
+            if(rPropVal.Name == "Prefix" || rPropVal.Name == "Suffix" || rPropVal.Name == "Transliteration")
                 CPPUNIT_ASSERT_EQUAL(OUString("string"), aAny.getValueTypeName());
-            else if((aPropVal[i])[j].Name == "NumberingType")
+            else if(rPropVal.Name == "NumberingType")
                 CPPUNIT_ASSERT_EQUAL(OUString("short"), aAny.getValueTypeName());
-            else if((aPropVal[i])[j].Name == "NatNum")
+            else if(rPropVal.Name == "NatNum")
                 CPPUNIT_ASSERT_EQUAL(OUString("short"), aAny.getValueTypeName());
                 //It is expected to be long but right now its short !error!
             else
@@ -1981,7 +1981,7 @@ void SwUiWriterTest::testXFlatParagraph()
     xFlatPara3->changeAttributes(sal_Int32(0), sal_Int32(5), aDescriptor);
     //checking Language Portions
     uno::Sequence<::sal_Int32> aLangPortions(xFlatPara4->getLanguagePortions());
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aLangPortions.getLength());
+    CPPUNIT_ASSERT(!aLangPortions.hasElements());
     //examining Language of text
     css::lang::Locale alocale = xFlatPara4->getLanguageOfText(sal_Int32(0), sal_Int32(4));
     CPPUNIT_ASSERT_EQUAL(OUString("en"), alocale.Language);
@@ -2000,17 +2000,16 @@ void SwUiWriterTest::testTdf81995()
     alocale.Country = "US";
     uno::Sequence<uno::Reference<container::XIndexAccess>> aIndexAccess(xDefNum->getDefaultOutlineNumberings(alocale));
     CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aIndexAccess.getLength());
-    for(int i=0;i<aIndexAccess.getLength();i++)
+    for(const auto& rIndexAccess : aIndexAccess)
     {
-        CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aIndexAccess[i]->getCount());
-        for(int j=0;j<aIndexAccess[i]->getCount();j++)
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rIndexAccess->getCount());
+        for(int j=0;j<rIndexAccess->getCount();j++)
         {
             uno::Sequence<beans::PropertyValue> aProps;
-            aIndexAccess[i]->getByIndex(j) >>= aProps;
+            rIndexAccess->getByIndex(j) >>= aProps;
             CPPUNIT_ASSERT_EQUAL(sal_Int32(12), aProps.getLength());
-            for(int k=0;k<aProps.getLength();k++)
+            for(const beans::PropertyValue& rProp : aProps)
             {
-                const beans::PropertyValue& rProp = aProps[k];
                 uno::Any aAny = rProp.Value;
                 if(rProp.Name == "Prefix" || rProp.Name == "Suffix" || rProp.Name == "BulletChar" || rProp.Name == "BulletFontName" || rProp.Name == "Transliteration")
                     CPPUNIT_ASSERT_EQUAL(OUString("string"), aAny.getValueTypeName());
diff --git a/sw/source/core/access/acchyperlink.cxx b/sw/source/core/access/acchyperlink.cxx
index 4877ffbe7970..e7d756af731c 100644
--- a/sw/source/core/access/acchyperlink.cxx
+++ b/sw/source/core/access/acchyperlink.cxx
@@ -211,13 +211,10 @@ sal_Bool SAL_CALL SwAccessibleHyperlink::isValid(  )
                 uno::Reference< css::container::XNameAccess > xLinks = xLTS->getLinks();
                 uno::Reference< css::container::XNameAccess > xSubLinks;
                 const uno::Sequence< OUString > aNames( xLinks->getElementNames() );
-                const sal_uLong nLinks = aNames.getLength();
-                const OUString* pNames = aNames.getConstArray();
 
-                for( sal_uLong i = 0; i < nLinks; i++ )
+                for( const OUString& aLink : aNames )
                 {
                     uno::Any aAny;
-                    OUString aLink( *pNames++ );
                     aAny = xLinks->getByName( aLink );
                     aAny >>= xSubLinks;
                     if (xSubLinks->hasByName(sText.copy(1)) )
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 31d00a30021e..9574855492e8 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <memory>
+#include <numeric>
 #include <txtfrm.hxx>
 #include <flyfrm.hxx>
 #include <ndtxt.hxx>
@@ -1593,11 +1594,9 @@ void SwAccessibleParagraph::_getDefaultAttributesImpl(
     }
     else
     {
-        const OUString* pReqAttrs = aRequestedAttributes.getConstArray();
-        const sal_Int32 nLength = aRequestedAttributes.getLength();
-        for( sal_Int32 i = 0; i < nLength; ++i )
+        for( const OUString& rReqAttr : aRequestedAttributes )
         {
-            tAccParaPropValMap::const_iterator const aIter = aDefAttrSeq.find( pReqAttrs[i] );
+            tAccParaPropValMap::const_iterator const aIter = aDefAttrSeq.find( rReqAttr );
             if ( aIter != aDefAttrSeq.end() )
             {
                 rDefAttrSeq[ aIter->first ] = aIter->second;
@@ -1618,30 +1617,13 @@ uno::Sequence< PropertyValue > SwAccessibleParagraph::getDefaultAttributes(
 
     // #i92233#
     static const char sMMToPixelRatio[] = "MMToPixelRatio";
-    bool bProvideMMToPixelRatio( false );
-    {
-        if ( !aRequestedAttributes.hasElements() )
-        {
-            bProvideMMToPixelRatio = true;
-        }
-        else
-        {
-            const OUString* aRequestedAttrIter =
-                  std::find( aRequestedAttributes.begin(), aRequestedAttributes.end(), sMMToPixelRatio );
-            if ( aRequestedAttrIter != aRequestedAttributes.end() )
-                bProvideMMToPixelRatio = true;
-        }
-    }
+    bool bProvideMMToPixelRatio( !aRequestedAttributes.hasElements() ||
+                                 (comphelper::findValue(aRequestedAttributes, sMMToPixelRatio) != -1) );
 
     uno::Sequence< PropertyValue > aValues( aDefAttrSeq.size() +
                                             ( bProvideMMToPixelRatio ? 1 : 0 ) );
-    PropertyValue* pValues = aValues.getArray();
-    sal_Int32 i = 0;
-    for ( const auto& rEntry : aDefAttrSeq )
-    {
-        pValues[i] = rEntry.second;
-        ++i;
-    }
+    std::transform(aDefAttrSeq.begin(), aDefAttrSeq.end(), aValues.begin(),
+        [](const auto& rEntry) -> PropertyValue { return rEntry.second; });
 
     // #i92233#
     if ( bProvideMMToPixelRatio )
@@ -1654,7 +1636,7 @@ uno::Sequence< PropertyValue > SwAccessibleParagraph::getDefaultAttributes(
         rPropVal.Value <<= fRatio;
         rPropVal.Handle = -1;
         rPropVal.State = beans::PropertyState_DEFAULT_VALUE;
-        pValues[ aValues.getLength() - 1 ] = rPropVal;
+        aValues[ aValues.getLength() - 1 ] = rPropVal;
     }
 
     return aValues;
@@ -1749,11 +1731,9 @@ void SwAccessibleParagraph::_getRunAttributesImpl(
         }
         else
         {
-            const OUString* pReqAttrs = aRequestedAttributes.getConstArray();
-            const sal_Int32 nLength = aRequestedAttributes.getLength();
-            for( sal_Int32 i = 0; i < nLength; ++i )
+            for( const OUString& rReqAttr : aRequestedAttributes )
             {
-                tAccParaPropValMap::iterator aIter = aRunAttrSeq.find( pReqAttrs[i] );
+                tAccParaPropValMap::iterator aIter = aRunAttrSeq.find( rReqAttr );
                 if ( aIter != aRunAttrSeq.end() )
                 {
                     rRunAttrSeq[ (*aIter).first ] = (*aIter).second;
@@ -1835,12 +1815,9 @@ void SwAccessibleParagraph::_getSupplementalAttributesImpl(
         }
     }
 
-    const OUString* pSupplementalAttrs = aRequestedAttributes.getConstArray();
-    const sal_Int32 nSupplementalLength = aRequestedAttributes.getLength();
-
-    for( sal_Int32 index = 0; index < nSupplementalLength; ++index )
+    for( const OUString& rSupplementalAttr : aRequestedAttributes )
     {
-        tAccParaPropValMap::const_iterator const aIter = aSupplementalAttrSeq.find( pSupplementalAttrs[index] );
+        tAccParaPropValMap::const_iterator const aIter = aSupplementalAttrSeq.find( rSupplementalAttr );
         if ( aIter != aSupplementalAttrSeq.end() )
         {
             rSupplementalAttrSeq[ aIter->first ] = aIter->second;
@@ -2643,10 +2620,8 @@ sal_Bool SwAccessibleParagraph::setAttributes(
     // build sorted index array
     sal_Int32 nLength = rAttributeSet.getLength();
     const PropertyValue* pPairs = rAttributeSet.getConstArray();
-    std::vector<sal_Int32> aIndices;
-    aIndices.reserve(nLength);
-    for (sal_Int32 i = 0; i < nLength; ++i)
-        aIndices.push_back(i);
+    std::vector<sal_Int32> aIndices(nLength);
+    std::iota(aIndices.begin(), aIndices.end(), 0);
     std::sort(aIndices.begin(), aIndices.end(), IndexCompare(pPairs));
 
     // create sorted sequences according to index array
diff --git a/sw/source/core/access/accselectionhelper.cxx b/sw/source/core/access/accselectionhelper.cxx
index d37e7c1ba9be..8b1416b9d576 100644
--- a/sw/source/core/access/accselectionhelper.cxx
+++ b/sw/source/core/access/accselectionhelper.cxx
@@ -124,12 +124,8 @@ static bool lcl_getSelectedState(const SwAccessibleChild& aChild,
         if( pRStateSet.is() )
         {
             Sequence<short> aStates = pRStateSet->getStates();
-            sal_Int32 count = aStates.getLength();
-            for( sal_Int32 i = 0; i < count; i++ )
-            {
-                if( aStates[i] == AccessibleStateType::SELECTED)
-                    return true;
-            }
+            if (std::find(aStates.begin(), aStates.end(), AccessibleStateType::SELECTED) != aStates.end())
+                return true;
         }
     }
     return false;
diff --git a/sw/source/core/doc/docglos.cxx b/sw/source/core/doc/docglos.cxx
index e55d9e420871..ea05dac8a66f 100644
--- a/sw/source/core/doc/docglos.cxx
+++ b/sw/source/core/doc/docglos.cxx
@@ -57,9 +57,9 @@ void SwDoc::ReplaceUserDefinedDocumentProperties(
     uno::Sequence<beans::Property> tgtprops
         = xTargetUDSet->getPropertySetInfo()->getProperties();
 
-    for (sal_Int32 i = 0; i < tgtprops.getLength(); ++i) {
+    for (const auto& rTgtProp : tgtprops) {
         try {
-            xTargetUD->removeProperty(tgtprops [i].Name);
+            xTargetUD->removeProperty(rTgtProp.Name);
         } catch (uno::Exception &) {
             // ignore
         }
@@ -69,10 +69,10 @@ void SwDoc::ReplaceUserDefinedDocumentProperties(
         = xSourceUDSet->getPropertySetInfo();
     uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
 
-    for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) {
+    for (const auto& rSrcProp : srcprops) {
         try {
-            OUString name = srcprops[i].Name;
-            xTargetUD->addProperty(name, srcprops[i].Attributes,
+            OUString name = rSrcProp.Name;
+            xTargetUD->addProperty(name, rSrcProp.Attributes,
                 xSourceUDSet->getPropertyValue(name));
         } catch (uno::Exception &) {
             // ignore
diff --git a/sw/source/core/doc/docxforms.cxx b/sw/source/core/doc/docxforms.cxx
index 1c98d3aa7472..dc4088f734a9 100644
--- a/sw/source/core/doc/docxforms.cxx
+++ b/sw/source/core/doc/docxforms.cxx
@@ -93,12 +93,10 @@ void SwDoc::disposeXForms( )
     {
         // iterate over all models
         uno::Sequence<OUString> aNames = mxXForms->getElementNames();
-        const OUString* pNames = aNames.getConstArray();
-        sal_Int32 nNames = aNames.getLength();
-        for( sal_Int32 n = 0; (n < nNames); n++ )
+        for( const OUString& rName : aNames )
         {
             Reference< xforms::XModel > xModel(
-                mxXForms->getByName( pNames[n] ), UNO_QUERY );
+                mxXForms->getByName( rName ), UNO_QUERY );
 
             if( xModel.is() )
             {
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index 335041745d0b..40df71f1500a 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -1000,19 +1000,16 @@ bool SwEditShell::GetGrammarCorrection(
                 bRes = true;
 
                 // get suggestions to use for the specific error position
-                sal_Int32 nErrors = rResult.aErrors.getLength();
                 rSuggestions.realloc( 0 );
-                for (sal_Int32 i = 0;  i < nErrors; ++i )
+                // return suggestions for first error that includes the given error position
+                auto pError = std::find_if(rResult.aErrors.begin(), rResult.aErrors.end(),
+                    [rErrorPosInText, nLen](const linguistic2::SingleProofreadingError &rError) {
+                        return rError.nErrorStart <= rErrorPosInText
+                            && rErrorPosInText + nLen <= rError.nErrorStart + rError.nErrorLength; });
+                if (pError != rResult.aErrors.end())
                 {
-                    // return suggestions for first error that includes the given error position
-                    const linguistic2::SingleProofreadingError &rError = rResult.aErrors[i];
-                    if (rError.nErrorStart <= rErrorPosInText &&
-                        rErrorPosInText + nLen <= rError.nErrorStart + rError.nErrorLength)
-                    {
-                        rSuggestions = rError.aSuggestions;
-                        rErrorIndexInResult = i;
-                        break;
-                    }
+                    rSuggestions = pError->aSuggestions;
+                    rErrorIndexInResult = static_cast<sal_Int32>(std::distance(rResult.aErrors.begin(), pError));
                 }
             }
 
@@ -1533,15 +1530,10 @@ void SwSpellIter::CreatePortion(uno::Reference< XSpellAlternatives > const & xAl
             aPortion.aGrammarError = pGrammarResult->aErrors[0];
             aPortion.sText = pGrammarResult->aText.copy( aPortion.aGrammarError.nErrorStart, aPortion.aGrammarError.nErrorLength );
             aPortion.xGrammarChecker = pGrammarResult->xProofreader;
-            const beans::PropertyValue* pProperties = pGrammarResult->aProperties.getConstArray();
-            for( sal_Int32 nProp = 0; nProp < pGrammarResult->aProperties.getLength(); ++nProp )
-            {
-                if ( pProperties->Name == "DialogTitle" )
-                {
-                    pProperties->Value >>= aPortion.sDialogTitle;
-                    break;
-                }
-            }
+            auto pProperty = std::find_if(pGrammarResult->aProperties.begin(), pGrammarResult->aProperties.end(),
+                [](const beans::PropertyValue& rProperty) { return rProperty.Name == "DialogTitle"; });
+            if (pProperty != pGrammarResult->aProperties.end())
+                pProperty->Value >>= aPortion.sDialogTitle;
         }
     }
     else
diff --git a/sw/source/core/fields/authfld.cxx b/sw/source/core/fields/authfld.cxx
index 92557eadf4d0..b42a91e56d65 100644
--- a/sw/source/core/fields/authfld.cxx
+++ b/sw/source/core/fields/authfld.cxx
@@ -399,23 +399,23 @@ void SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId )
                 //TODO: Limiting to the first SAL_MAX_UINT16 elements of aSeq so that size of
                 // m_SortKeyArr remains in range of sal_uInt16, as GetSortKeyCount and GetSortKey
                 // still expect m_SortKeyArr to be indexed by sal_uInt16:
-                for(sal_Int32 i = 0; i < aSeq.getLength() && i < SAL_MAX_UINT16; i++)
+                auto nSize = std::min<sal_Int32>(aSeq.getLength(), SAL_MAX_UINT16);
+                for(sal_Int32 i = 0; i < nSize; i++)
                 {
-                    const PropertyValue* pValue = pValues[i].getConstArray();
                     SwTOXSortKey aSortKey;
-                    for(sal_Int32 j = 0; j < pValues[i].getLength(); j++)
+                    for(const PropertyValue& rValue : pValues[i])
                     {
-                        if(pValue[j].Name == UNO_NAME_SORT_KEY)
+                        if(rValue.Name == UNO_NAME_SORT_KEY)
                         {
-                            sal_Int16 nVal = -1; pValue[j].Value >>= nVal;
+                            sal_Int16 nVal = -1; rValue.Value >>= nVal;
                             if(nVal >= 0 && nVal < AUTH_FIELD_END)
                                 aSortKey.eField = static_cast<ToxAuthorityField>(nVal);
                             else
                                 bRet = false;
                         }
-                        else if(pValue[j].Name == UNO_NAME_IS_SORT_ASCENDING)
+                        else if(rValue.Name == UNO_NAME_IS_SORT_ASCENDING)
                         {
-                            aSortKey.bSortAscending = *o3tl::doAccess<bool>(pValue[j].Value);
+                            aSortKey.bSortAscending = *o3tl::doAccess<bool>(rValue.Value);
                         }
                     }
                     m_SortKeyArr.push_back(aSortKey);
@@ -636,21 +636,20 @@ bool    SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ )
     OUStringBuffer sBuf;
     comphelper::string::padToLength(sBuf, AUTH_FIELD_ISBN, TOX_STYLE_DELIMITER);
     OUString sToSet(sBuf.makeStringAndClear());
-    const PropertyValue* pParam = aParam.getConstArray();
-    for(sal_Int32 i = 0; i < aParam.getLength(); i++)
+    for(const PropertyValue& rParam : aParam)
     {
-        const sal_Int32 nFound = lcl_Find(pParam[i].Name);
+        const sal_Int32 nFound = lcl_Find(rParam.Name);
         if(nFound >= 0)
         {
             OUString sContent;
             if(AUTH_FIELD_AUTHORITY_TYPE == nFound)
             {
                 sal_Int16 nVal = 0;
-                pParam[i].Value >>= nVal;
+                rParam.Value >>= nVal;
                 sContent = OUString::number(nVal);
             }
             else
-                pParam[i].Value >>= sContent;
+                rParam.Value >>= sContent;
             sToSet = comphelper::string::setToken(sToSet, nFound, TOX_STYLE_DELIMITER, sContent);
         }
     }
diff --git a/sw/source/core/fields/flddropdown.cxx b/sw/source/core/fields/flddropdown.cxx
index cb7d706c3941..a90da4a2a4b7 100644
--- a/sw/source/core/fields/flddropdown.cxx
+++ b/sw/source/core/fields/flddropdown.cxx
@@ -111,9 +111,7 @@ void SwDropDownField::SetItems(const uno::Sequence<OUString> & rItems)
 {
     aValues.clear();
 
-    sal_Int32 aCount = rItems.getLength();
-    for (int i = 0; i < aCount; i++)
-        aValues.push_back(rItems[i]);
+    comphelper::sequenceToContainer(aValues, rItems);
 
     aSelectedItem.clear();
 }
diff --git a/sw/source/core/unocore/SwXTextDefaults.cxx b/sw/source/core/unocore/SwXTextDefaults.cxx
index ffbbb29f2217..41c094d6fb96 100644
--- a/sw/source/core/unocore/SwXTextDefaults.cxx
+++ b/sw/source/core/unocore/SwXTextDefaults.cxx
@@ -174,12 +174,10 @@ PropertyState SAL_CALL SwXTextDefaults::getPropertyState( const OUString& rPrope
 Sequence< PropertyState > SAL_CALL SwXTextDefaults::getPropertyStates( const Sequence< OUString >& rPropertyNames )
 {
     const sal_Int32 nCount = rPropertyNames.getLength();
-    const OUString * pNames = rPropertyNames.getConstArray();
     Sequence < PropertyState > aRet ( nCount );
-    PropertyState *pState = aRet.getArray();
 
-    for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
-        pState[nIndex] = getPropertyState( pNames[nIndex] );
+    std::transform(rPropertyNames.begin(), rPropertyNames.end(), aRet.begin(),
+        [this](const OUString& rName) -> PropertyState { return getPropertyState(rName); });
 
     return aRet;
 }
diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx
index d2dc97d216f5..eb81443bf984 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -548,39 +548,38 @@ uno::Reference< chart2::data::XDataSource > SwChartDataProvider::Impl_createData
     OSL_ENSURE( nArgs != 0, "no properties provided" );
     if (nArgs == 0)
         return xRes;
-    const beans::PropertyValue *pArg = rArguments.getConstArray();
-    for (sal_Int32 i = 0;  i < nArgs;  ++i)
+    for (const beans::PropertyValue& rArg : rArguments)
     {
-        if ( pArg[i].Name == "DataRowSource" )
+        if ( rArg.Name == "DataRowSource" )
         {
             chart::ChartDataRowSource eSource;
-            if (!(pArg[i].Value >>= eSource))
+            if (!(rArg.Value >>= eSource))
             {
                 sal_Int32 nTmp = 0;
-                if (!(pArg[i].Value >>= nTmp))
+                if (!(rArg.Value >>= nTmp))
                     throw lang::IllegalArgumentException();
                 eSource = static_cast< chart::ChartDataRowSource >( nTmp );
             }
             bDtaSrcIsColumns = eSource == chart::ChartDataRowSource_COLUMNS;
         }
-        else if ( pArg[i].Name == "FirstCellAsLabel" )
+        else if ( rArg.Name == "FirstCellAsLabel" )
         {
-            if (!(pArg[i].Value >>= bFirstIsLabel))
+            if (!(rArg.Value >>= bFirstIsLabel))
                 throw lang::IllegalArgumentException();
         }
-        else if ( pArg[i].Name == "CellRangeRepresentation" )
+        else if ( rArg.Name == "CellRangeRepresentation" )
         {
-            if (!(pArg[i].Value >>= aRangeRepresentation))
+            if (!(rArg.Value >>= aRangeRepresentation))
                 throw lang::IllegalArgumentException();
         }
-        else if ( pArg[i].Name == "SequenceMapping" )
+        else if ( rArg.Name == "SequenceMapping" )
         {
-            if (!(pArg[i].Value >>= aSequenceMapping))
+            if (!(rArg.Value >>= aSequenceMapping))
                 throw lang::IllegalArgumentException();
         }
-        else if ( pArg[i].Name == "ChartOleObjectName" )
+        else if ( rArg.Name == "ChartOleObjectName" )
         {
-            if (!(pArg[i].Value >>= aChartOleObjectName))
+            if (!(rArg.Value >>= aChartOleObjectName))
                 throw lang::IllegalArgumentException();
         }
     }
@@ -642,13 +641,12 @@ uno::Reference< chart2::data::XDataSource > SwChartDataProvider::Impl_createData
         throw lang::IllegalArgumentException();
 
     SortSubranges( aSubRanges, bDtaSrcIsColumns );
-    const OUString *pSubRanges = aSubRanges.getConstArray();
 
     // get table format for that single table from above
     SwFrameFormat    *pTableFormat  = nullptr;      // pointer to table format
     std::shared_ptr<SwUnoCursor> pUnoCursor;      // here required to check if the cells in the range do actually exist
     if (aSubRanges.hasElements())
-        GetFormatAndCreateCursorFromRangeRep( pDoc, pSubRanges[0], &pTableFormat, pUnoCursor );
+        GetFormatAndCreateCursorFromRangeRep( pDoc, aSubRanges[0], &pTableFormat, pUnoCursor );
 
     if (!pTableFormat || !pUnoCursor)
         throw lang::IllegalArgumentException();
@@ -669,12 +667,11 @@ uno::Reference< chart2::data::XDataSource > SwChartDataProvider::Impl_createData
     //!! by proceeding this way we automatically get rid of
     //!! multiple listed or overlapping cell ranges which should
     //!! just be ignored silently
-    sal_Int32 nSubRanges = aSubRanges.getLength();
-    for (sal_Int32 i = 0; i < nSubRanges; ++i)
+    for (const OUString& rSubRange : aSubRanges)
     {
         OUString aTableName, aStartCell, aEndCell;
         bool bOk2 = GetTableAndCellsFromRangeRep(
-                            pSubRanges[i], aTableName, aStartCell, aEndCell );
+                            rSubRange, aTableName, aStartCell, aEndCell );
         OSL_ENSURE(bOk2, "failed to get table and start/end cells");
 
         sal_Int32 nStartRow, nStartCol, nEndRow, nEndCol;
@@ -879,19 +876,16 @@ uno::Reference< chart2::data::XDataSource > SwChartDataProvider::Impl_createData
     }
 
     // apply 'SequenceMapping' if it was provided
-    sal_Int32 nSequenceMappingLen = aSequenceMapping.getLength();
-    if (nSequenceMappingLen)
+    if (aSequenceMapping.hasElements())
     {
-        sal_Int32 *pSequenceMapping = aSequenceMapping.getArray();
         uno::Sequence<uno::Reference<chart2::data::XLabeledDataSequence>> aOld_LDS(aLDS);
         uno::Reference<chart2::data::XLabeledDataSequence>* pOld_LDS = aOld_LDS.getArray();
 
         sal_Int32 nNewCnt = 0;
-        for (sal_Int32 i = 0; i < nSequenceMappingLen; ++i)
+        for (sal_Int32 nIdx : aSequenceMapping)
         {
             // check that index to be used is valid
             // and has not yet been used
-            sal_Int32 nIdx = pSequenceMapping[i];
             if (0 <= nIdx && nIdx < nNumLDS && pOld_LDS[nIdx].is())
             {
                 pLDS[nNewCnt++] = pOld_LDS[nIdx];
@@ -1238,14 +1232,12 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwChartDataProvider::detectArgume
     uno::Sequence< OUString > aSortedRanges;
     GetSubranges( aCellRanges, aSortedRanges, false /*sub ranges should already be normalized*/ );
     SortSubranges( aSortedRanges, (nDtaSrcIsColumns == 1) );
-    sal_Int32 nSortedRanges = aSortedRanges.getLength();
-    const OUString *pSortedRanges = aSortedRanges.getConstArray();
     OUString aSortedCellRanges;
-    for (sal_Int32 i = 0;  i < nSortedRanges;  ++i)
+    for (const OUString& rSortedRange : aSortedRanges)
     {
         if (!aSortedCellRanges.isEmpty())
             aSortedCellRanges += ";";
-        aSortedCellRanges += pSortedRanges[i];
+        aSortedCellRanges += rSortedRange;
     }
 
     // build value for 'SequenceMapping'
diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx
index dcc16bd7aa30..e9c1a8ba7c27 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -124,14 +124,11 @@ public:
                 uno::Sequence< OUString > sModuleNames = xLib->getElementNames();
                 uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY );
 
-                for ( sal_Int32 i=0; i < sModuleNames.getLength(); ++i )
-                {
-                    if ( xVBAModuleInfo->hasModuleInfo( sModuleNames[ i ] ) &&  xVBAModuleInfo->getModuleInfo( sModuleNames[ i ] ).ModuleType == script::ModuleType::DOCUMENT )
-                    {
-                        msThisDocumentCodeName = sModuleNames[ i ];
-                        break;
-                    }
-                }
+                auto pModuleName = std::find_if(sModuleNames.begin(), sModuleNames.end(), [&xVBAModuleInfo](const OUString& rName) {
+                    return xVBAModuleInfo->hasModuleInfo(rName)
+                        && xVBAModuleInfo->getModuleInfo(rName).ModuleType == script::ModuleType::DOCUMENT; });
+                if (pModuleName != sModuleNames.end())
+                    msThisDocumentCodeName = *pModuleName;
             }
             catch( uno::Exception& )
             {
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx
index 2e935b87477c..b00e4fb9ee67 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -1223,9 +1223,9 @@ void makeRedline( SwPaM const & rPaM,
             std::vector<sal_uInt16> aWhichPairs;
             std::vector<SfxItemPropertySimpleEntry const*> aEntries;
             aEntries.reserve(aRevertProperties.getLength());
-            for (sal_Int32 i = 0; i < aRevertProperties.getLength(); ++i)
+            for (const auto& rRevertProperty : aRevertProperties)
             {
-                const OUString &rPropertyName = aRevertProperties[i].Name;
+                const OUString &rPropertyName = rRevertProperty.Name;
                 SfxItemPropertySimpleEntry const* pEntry = rPropSet.getPropertyMap().getByName(rPropertyName);
 
                 if (!pEntry)
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index 58fdfa68d696..712342578872 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -2656,20 +2656,14 @@ css::drawing::PolyPolygonBezierCoords SwXShape::ConvertPolyPolygonBezierToLayout
                 const basegfx::B2DHomMatrix aMatrix(basegfx::utils::createTranslateB2DHomMatrix(
                     aTranslateDiff.X, aTranslateDiff.Y));
 
-                const sal_Int32 nOuterSequenceCount(aConvertedPath.Coordinates.getLength());
-                drawing::PointSequence* pInnerSequence = aConvertedPath.Coordinates.getArray();
-                for(sal_Int32 a(0); a < nOuterSequenceCount; a++)
+                for(drawing::PointSequence& rInnerSequence : aConvertedPath.Coordinates)
                 {
-                    const sal_Int32 nInnerSequenceCount(pInnerSequence->getLength());
-                    awt::Point* pArray = pInnerSequence->getArray();
-
-                    for(sal_Int32 b(0); b < nInnerSequenceCount; b++)
+                    for(awt::Point& rPoint : rInnerSequence)
                     {
-                        basegfx::B2DPoint aNewCoordinatePair(pArray->X, pArray->Y);
+                        basegfx::B2DPoint aNewCoordinatePair(rPoint.X, rPoint.Y);
                         aNewCoordinatePair *= aMatrix;
-                        pArray->X = basegfx::fround(aNewCoordinatePair.getX());
-                        pArray->Y = basegfx::fround(aNewCoordinatePair.getY());
-                        pArray++;
+                        rPoint.X = basegfx::fround(aNewCoordinatePair.getX());
+                        rPoint.Y = basegfx::fround(aNewCoordinatePair.getY());
                     }
                 }
             }
diff --git a/sw/source/core/unocore/unoevent.cxx b/sw/source/core/unocore/unoevent.cxx
index 823de312d97b..d3ddb75ed719 100644
--- a/sw/source/core/unocore/unoevent.cxx
+++ b/sw/source/core/unocore/unoevent.cxx
@@ -142,11 +142,9 @@ void SwHyperlinkEventDescriptor::copyMacrosFromNameReplace(
 {
     // iterate over all names (all names that *we* support)
     Sequence<OUString> aNames = getElementNames();
-    sal_Int32 nCount = aNames.getLength();
-    for(sal_Int32 i = 0; i < nCount; i++)
+    for(const OUString& rName : aNames)
     {
         // copy element for that name
-        const OUString& rName = aNames[i];
         if (xReplace->hasByName(rName))
         {
             SvBaseEventDescriptor::replaceByName(rName,
diff --git a/sw/source/core/unocore/unoflatpara.cxx b/sw/source/core/unocore/unoflatpara.cxx
index 099cf4a999df..909e6fc069e2 100644
--- a/sw/source/core/unocore/unoflatpara.cxx
+++ b/sw/source/core/unocore/unoflatpara.cxx
@@ -268,8 +268,8 @@ void SAL_CALL SwXFlatParagraph::changeText(::sal_Int32 nPos, ::sal_Int32 nLen, c
     uno::Reference< beans::XPropertySet > xPropSet( xRange, uno::UNO_QUERY );
     if ( xPropSet.is() )
     {
-        for ( sal_Int32 i = 0; i < aAttributes.getLength(); ++i )
-            xPropSet->setPropertyValue( aAttributes[i].Name, aAttributes[i].Value );
+        for ( const auto& rAttribute : aAttributes )
+            xPropSet->setPropertyValue( rAttribute.Name, rAttribute.Value );
     }
 
     IDocumentContentOperations& rIDCO = pOldTextNode->getIDocumentContentOperations();
@@ -301,8 +301,8 @@ void SAL_CALL SwXFlatParagraph::changeAttributes(::sal_Int32 nPos, ::sal_Int32 n
     uno::Reference< beans::XPropertySet > xPropSet( xRange, uno::UNO_QUERY );
     if ( xPropSet.is() )
     {
-        for ( sal_Int32 i = 0; i < aAttributes.getLength(); ++i )
-            xPropSet->setPropertyValue( aAttributes[i].Name, aAttributes[i].Value );
+        for ( const auto& rAttribute : aAttributes )
+            xPropSet->setPropertyValue( rAttribute.Name, rAttribute.Value );
     }
 
     ClearTextNode(); // TODO: is this really needed?
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index a4d54beabdd0..8c41d7fbe0fd 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1479,11 +1479,10 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any&
                     else if(aValue >>= aParam)
                     {
                         tools::PolyPolygon aPoly(static_cast<sal_uInt16>(aParam.getLength()));
-                        for(sal_Int32 i = 0; i < aParam.getLength(); i++)
+                        for(const ::drawing::PointSequence& rPointSeq : aParam)
                         {
-                            const ::drawing::PointSequence* pPointSeq = aParam.getConstArray();
-                            sal_Int32 nPoints = pPointSeq[i].getLength();
-                            const ::awt::Point* pPoints = pPointSeq[i].getConstArray();
+                            sal_Int32 nPoints = rPointSeq.getLength();
+                            const ::awt::Point* pPoints = rPointSeq.getConstArray();
                             tools::Polygon aSet( static_cast<sal_uInt16>(nPoints) );
                             for(sal_Int32 j = 0; j < nPoints; j++)
                             {
@@ -2461,8 +2460,7 @@ uno::Sequence< beans::PropertyState > SwXFrame::getPropertyStates(
     }
     else if(IsDescriptor())
     {
-        for(int i = 0; i < aPropertyNames.getLength(); i++)
-            pStates[i] = beans::PropertyState_DIRECT_VALUE;
+        std::fill(aStates.begin(), aStates.end(), beans::PropertyState_DIRECT_VALUE);
     }
     else
         throw uno::RuntimeException();
diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index f9bae53a53fc..48ac53e30dcd 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -2700,12 +2700,10 @@ SwXDocumentIndex::TokenAccess_Impl::replaceByIndex(
     }
 
     OUStringBuffer sPattern;
-    const sal_Int32 nTokens = aSeq.getLength();
-    const beans::PropertyValues* pTokens = aSeq.getConstArray();
-    for(sal_Int32 i = 0; i < nTokens; i++)
+    for(const beans::PropertyValues& rToken : aSeq)
     {
-        const beans::PropertyValue* pProperties = pTokens[i].getConstArray();
-        const sal_Int32 nProperties = pTokens[i].getLength();
+        const beans::PropertyValue* pProperties = rToken.getConstArray();
+        const sal_Int32 nProperties = rToken.getLength();
         //create an invalid token
         SwFormToken aToken(TOKEN_END);
         for(sal_Int32 j = 0; j < nProperties; j++)
diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx
index 03699a2ee9d2..cc13a87a6767 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -1786,9 +1786,9 @@ void SwUnoCursorHelper::SetPropertyValues(
     std::vector<sal_uInt16> aWhichPairs;
     std::vector<SfxItemPropertySimpleEntry const*> aEntries;
     aEntries.reserve(rPropertyValues.getLength());
-    for (sal_Int32 i = 0; i < rPropertyValues.getLength(); ++i)
+    for (const auto& rPropVal : rPropertyValues)
     {
-        const OUString &rPropertyName = rPropertyValues[i].Name;
+        const OUString &rPropertyName = rPropVal.Name;
 
         SfxItemPropertySimpleEntry const* pEntry =
             rPropSet.getPropertyMap().getByName(rPropertyName);
@@ -2263,8 +2263,8 @@ SwXTextCursor::getPropertyValues( const uno::Sequence< OUString >& aPropertyName
 {
     // a banal implementation for now
     uno::Sequence< uno::Any > aValues( aPropertyNames.getLength() );
-    for (sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
-        aValues[i] = getPropertyValue( aPropertyNames[ i ] );
+    std::transform(aPropertyNames.begin(), aPropertyNames.end(), aValues.begin(),
+        [this](const OUString& rName) -> uno::Any { return getPropertyValue( rName ); });
     return aValues;
 }
 
@@ -2350,32 +2350,30 @@ SwXTextCursor::setPropertiesToDefault(
 
     SwUnoCursor & rUnoCursor( m_pImpl->GetCursorOrThrow() );
 
-    const sal_Int32 nCount = rPropertyNames.getLength();
-    if ( nCount )
+    if ( rPropertyNames.hasElements() )
     {
         SwDoc & rDoc = *rUnoCursor.GetDoc();
-        const OUString * pNames = rPropertyNames.getConstArray();
         std::set<sal_uInt16> aWhichIds;
         std::set<sal_uInt16> aParaWhichIds;
-        for (sal_Int32 i = 0; i < nCount; i++)
+        for (const OUString& rName : rPropertyNames)
         {
             SfxItemPropertySimpleEntry const*const  pEntry =
-                m_pImpl->m_rPropSet.getPropertyMap().getByName( pNames[i] );
+                m_pImpl->m_rPropSet.getPropertyMap().getByName( rName );
             if (!pEntry)
             {
-                if (pNames[i] == UNO_NAME_IS_SKIP_HIDDEN_TEXT ||
-                    pNames[i] == UNO_NAME_IS_SKIP_PROTECTED_TEXT)
+                if (rName == UNO_NAME_IS_SKIP_HIDDEN_TEXT ||
+                    rName == UNO_NAME_IS_SKIP_PROTECTED_TEXT)
                 {
                     continue;
                 }
                 throw beans::UnknownPropertyException(
-                    "Unknown property: " + pNames[i],
+                    "Unknown property: " + rName,
                     static_cast<cppu::OWeakObject *>(this));
             }
             if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
             {
                 throw uno::RuntimeException(
-                    "setPropertiesToDefault: property is read-only: " + pNames[i],
+                    "setPropertiesToDefault: property is read-only: " + rName,
                     static_cast<cppu::OWeakObject *>(this));
             }
 
@@ -2586,7 +2584,6 @@ bool SwUnoCursorHelper::ConvertSortProperties(
     SwSortOptions& rSortOpt)
 {
     bool bRet = true;
-    const beans::PropertyValue* pProperties = rDescriptor.getConstArray();
 
     rSortOpt.bTable = false;
     rSortOpt.cDeli = ' ';
@@ -2611,10 +2608,10 @@ bool SwUnoCursorHelper::ConvertSortProperties(
     bool bOldSortdescriptor(false);
     bool bNewSortdescriptor(false);
 
-    for (sal_Int32 n = 0; n < rDescriptor.getLength(); ++n)
+    for (const beans::PropertyValue& rProperty : rDescriptor)
     {
-        uno::Any aValue( pProperties[n].Value );
-        const OUString& rPropName = pProperties[n].Name;
+        uno::Any aValue( rProperty.Value );
+        const OUString& rPropName = rProperty.Name;
 
         // old and new sortdescriptor
         if ( rPropName == "IsSortInTable" )
diff --git a/sw/source/core/unocore/unoparagraph.cxx b/sw/source/core/unocore/unoparagraph.cxx
index ce9a7d5ce5ff..f7c7949b1e34 100644
--- a/sw/source/core/unocore/unoparagraph.cxx
+++ b/sw/source/core/unocore/unoparagraph.cxx
@@ -707,17 +707,11 @@ SwXParagraph::getPropertyValuesTolerant(
 
     uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
         m_pImpl->GetPropertyValuesTolerant_Impl( rPropertyNames, false ) );
-    const beans::GetDirectPropertyTolerantResult *pTmpRes =
-        aTmpRes.getConstArray();
 
     // copy temporary result to final result type
     const sal_Int32 nLen = aTmpRes.getLength();
     uno::Sequence< beans::GetPropertyTolerantResult > aRes( nLen );
-    beans::GetPropertyTolerantResult *pRes = aRes.getArray();
-    for (sal_Int32 i = 0;  i < nLen;  i++)
-    {
-        *pRes++ = *pTmpRes++;
-    }
+    std::copy(aTmpRes.begin(), aTmpRes.end(), aRes.begin());
     return aRes;
 }
 
@@ -746,7 +740,6 @@ SwXParagraph::Impl::GetPropertyValuesTolerant_Impl(
     const SwAttrSet& rValueAttrSet = rTextNode.GetSwAttrSet();
 
     sal_Int32 nProps = rPropertyNames.getLength();
-    const OUString *pProp = rPropertyNames.getConstArray();
 
     uno::Sequence< beans::GetDirectPropertyTolerantResult > aResult( nProps );
     beans::GetDirectPropertyTolerantResult *pResult = aResult.getArray();
@@ -755,17 +748,17 @@ SwXParagraph::Impl::GetPropertyValuesTolerant_Impl(
     // get entry to start with
     const SfxItemPropertyMap &rPropMap = m_rPropSet.getPropertyMap();
 
-    for (sal_Int32 i = 0;  i < nProps;  ++i)
+    for (const OUString& rProp : rPropertyNames)
     {
         OSL_ENSURE( nIdx < nProps, "index out ouf bounds" );
         beans::GetDirectPropertyTolerantResult &rResult = pResult[nIdx];
 
         try
         {
-            rResult.Name = pProp[i];
+            rResult.Name = rProp;
 
             SfxItemPropertySimpleEntry const*const pEntry =
-                rPropMap.getByName( pProp[i] );
+                rPropMap.getByName( rProp );
             if (!pEntry)  // property available?
             {
                 rResult.Result =
@@ -788,7 +781,7 @@ SwXParagraph::Impl::GetPropertyValuesTolerant_Impl(
                     // (compare to SwXParagraph::getPropertyValue(s))
                     uno::Any aValue;
                     if (! ::sw::GetDefaultTextContentValue(
-                                aValue, pProp[i], pEntry->nWID ) )
+                                aValue, rProp, pEntry->nWID ) )
                     {
                         SwPosition aPos( rTextNode );
                         SwPaM aPam( aPos );
diff --git a/sw/source/core/unocore/unoport.cxx b/sw/source/core/unocore/unoport.cxx
index 7c03d12a7623..e97e65b32f98 100644
--- a/sw/source/core/unocore/unoport.cxx
+++ b/sw/source/core/unocore/unoport.cxx
@@ -377,7 +377,7 @@ uno::Sequence< uno::Any > SwXTextPortion::GetPropertyValues_Impl(
 {
     sal_Int32 nLength = rPropertyNames.getLength();
     const OUString *pPropertyNames = rPropertyNames.getConstArray();
-    uno::Sequence< uno::Any > aValues(rPropertyNames.getLength());
+    uno::Sequence< uno::Any > aValues(nLength);
     uno::Any *pValues = aValues.getArray();
     SwUnoCursor& rUnoCursor = GetCursor();
 
@@ -555,14 +555,11 @@ uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL SwXTextPortion::getPr
 
     uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
             GetPropertyValuesTolerant_Impl( rPropertyNames, false ) );
-    const beans::GetDirectPropertyTolerantResult *pTmpRes = aTmpRes.getConstArray();
 
     // copy temporary result to final result type
     sal_Int32 nLen = aTmpRes.getLength();
     uno::Sequence< beans::GetPropertyTolerantResult > aRes( nLen );
-    beans::GetPropertyTolerantResult *pRes = aRes.getArray();
-    for (sal_Int32 i = 0;  i < nLen;  i++)
-        *pRes++ = *pTmpRes++;
+    std::copy(aTmpRes.begin(), aTmpRes.end(), aRes.begin());
     return aRes;
 }
 
diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx
index 54cac96775b1..7e32b867274a 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -79,6 +79,7 @@
 #include <svl/listener.hxx>
 #include <paratr.hxx>
 #include <sal/log.hxx>
+#include <numeric>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -1592,12 +1593,10 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
         InChapterLast = 24
     };
 
-    const beans::PropertyValue* pPropArray = rProperties.getConstArray();
     std::vector<PropertyValue const*> aPropertyValues;
     bool bExcept = false;
-    for(sal_Int32 i = 0; i < rProperties.getLength() && !bExcept; i++)
+    for(const beans::PropertyValue& rProp : rProperties)
     {
-        const beans::PropertyValue& rProp = pPropArray[i];
         bExcept = true;
         for(size_t j = 0; j < SAL_N_ELEMENTS( aNumPropertyNames ); j++)
         {
@@ -1617,6 +1616,8 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
         }
         SAL_WARN_IF( bExcept, "sw.uno", "Unknown/incorrect property " << rProp.Name << ", failing" );
         aPropertyValues.push_back(& rProp);
+        if(bExcept)
+            break;
     }
 
     bool bWrongArg = false;
@@ -2402,12 +2403,8 @@ uno::Sequence< TextColumn > SwXTextColumns::getColumns()
 void SwXTextColumns::setColumns(const uno::Sequence< TextColumn >& rColumns)
 {
     SolarMutexGuard aGuard;
-    sal_Int32 nReferenceTemp = 0;
-    const TextColumn* prCols = rColumns.getConstArray();
-    for(long i = 0; i < rColumns.getLength(); i++)
-    {
-        nReferenceTemp += prCols[i].Width;
-    }
+    sal_Int32 nReferenceTemp = std::accumulate(rColumns.begin(), rColumns.end(), sal_Int32(0),
+        [](const sal_Int32 nSum, const TextColumn& rCol) { return nSum + rCol.Width; });
     m_bIsAutomaticWidth = false;
     m_nReference = !nReferenceTemp ? USHRT_MAX : nReferenceTemp;
     m_aTextColumns = rColumns;
diff --git a/sw/source/core/unocore/unosrch.cxx b/sw/source/core/unocore/unosrch.cxx
index 427791fc7e5d..93dee1364529 100644
--- a/sw/source/core/unocore/unosrch.cxx
+++ b/sw/source/core/unocore/unosrch.cxx
@@ -71,24 +71,21 @@ SwSearchProperties_Impl::SwSearchProperties_Impl() :
 
 void SwSearchProperties_Impl::SetProperties(const uno::Sequence< beans::PropertyValue >& aSearchAttribs)
 {
-    const beans::PropertyValue* pProps = aSearchAttribs.getConstArray();
-
     //delete all existing values
     for(size_t i = 0; i < aPropertyEntries.size(); ++i)
     {
         pValueArr[i].reset();
     }
 
-    const sal_uInt32 nLen = aSearchAttribs.getLength();
-    for(sal_uInt32 i = 0; i < nLen; ++i)
+    for(const beans::PropertyValue& rSearchAttrib : aSearchAttribs)
     {
-        const OUString& sName = pProps[i].Name;
+        const OUString& sName = rSearchAttrib.Name;
         auto aIt = std::find_if(aPropertyEntries.begin(), aPropertyEntries.end(),
             [&sName](const SfxItemPropertyNamedEntry& rProp) { return rProp.sName == sName; });
         if( aIt == aPropertyEntries.end() )
             throw beans::UnknownPropertyException();
         auto nIndex = static_cast<sal_uInt32>(std::distance(aPropertyEntries.begin(), aIt));
-        pValueArr[nIndex].reset( new beans::PropertyValue(pProps[i]) );
+        pValueArr[nIndex].reset( new beans::PropertyValue(rSearchAttrib) );
     }
 }
 
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 4f1d0571380b..204a3a737358 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -3532,17 +3532,15 @@ uno::Reference< style::XAutoStyle > SwXAutoStyleFamily::insertStyle(
         throw uno::RuntimeException();
 
     SwAttrSet aSet( m_pDocShell->GetDoc()->GetAttrPool(), pRange );
-    const beans::PropertyValue* pSeq = Values.getConstArray();
-    sal_Int32 nLen = Values.getLength();
     const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == m_eFamily);
 
     if(!bTakeCareOfDrawingLayerFillStyle)
     {
-        for( sal_Int32 i = 0; i < nLen; ++i )
+        for( const beans::PropertyValue& rValue : Values )
         {
             try
             {
-                pPropSet->setPropertyValue( pSeq[i].Name, pSeq[i].Value, aSet );
+                pPropSet->setPropertyValue( rValue.Name, rValue.Value, aSet );
             }
             catch (const beans::UnknownPropertyException &)
             {
@@ -3566,10 +3564,10 @@ uno::Reference< style::XAutoStyle > SwXAutoStyleFamily::insertStyle(
         // used slots functionality here to do this correctly
         const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
 
-        for( sal_Int32 i = 0; i < nLen; ++i )
+        for( const beans::PropertyValue& rValue : Values )
         {
-            const OUString& rPropName = pSeq[i].Name;
-            uno::Any aValue(pSeq[i].Value);
+            const OUString& rPropName = rValue.Name;
+            uno::Any aValue(rValue.Value);
             const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropName);
 
             if (!pEntry)
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 204cf81cf677..992c8be80532 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1448,16 +1448,13 @@ SwXText::insertTextContentWithProperties(
     {
         try
         {
-            const sal_Int32 nLen(rCharacterAndParagraphProperties.getLength());
             const uno::Reference< beans::XPropertySet > xAnchor(
                 xTextContent->getAnchor(), uno::UNO_QUERY);
             if (xAnchor.is())
             {
-                for (sal_Int32 nElement = 0; nElement < nLen; ++nElement)
+                for (const auto& rProperty : rCharacterAndParagraphProperties)
                 {
-                    xAnchor->setPropertyValue(
-                        rCharacterAndParagraphProperties[nElement].Name,
-                        rCharacterAndParagraphProperties[nElement].Value);
+                    xAnchor->setPropertyValue(rProperty.Name, rProperty.Value);
                 }
             }
         }
@@ -1673,11 +1670,9 @@ SwXText::convertToTextFrame(
     rNewFrame.SetSelection( aStartPam );
     try
     {
-        const beans::PropertyValue* pValues = rFrameProperties.getConstArray();
-        for (sal_Int32 nProp = 0; nProp < rFrameProperties.getLength(); ++nProp)
+        for (const beans::PropertyValue& rValue : rFrameProperties)
         {
-            rNewFrame.SwXFrame::setPropertyValue(
-                    pValues[nProp].Name, pValues[nProp].Value);
+            rNewFrame.SwXFrame::setPropertyValue(rValue.Name, rValue.Value);
         }
 
         {   // has to be in a block to remove the SwIndexes before
@@ -1975,20 +1970,17 @@ lcl_ApplyRowProperties(
 {
     uno::Reference< beans::XPropertySet > xRow;
     rRow >>= xRow;
-    const beans::PropertyValue* pProperties = rRowProperties.getConstArray();
-    for (sal_Int32 nProperty = 0; nProperty < rRowProperties.getLength();
-         ++nProperty)
+    for (const beans::PropertyValue& rProperty : rRowProperties)
     {
-        if ( pProperties[ nProperty ].Name == "TableColumnSeparators" )
+        if ( rProperty.Name == "TableColumnSeparators" )
         {
             // add the separators to access the cell's positions
             // for vertical merging later
             TableColumnSeparators aSeparators;
-            pProperties[ nProperty ].Value >>= aSeparators;
+            rProperty.Value >>= aSeparators;
             rRowSeparators = aSeparators;
         }
-        xRow->setPropertyValue(
-            pProperties[ nProperty ].Name, pProperties[ nProperty ].Value);
+        xRow->setPropertyValue(rProperty.Name, rProperty.Value);
     }
 }
 
@@ -2008,12 +2000,11 @@ lcl_ApplyCellProperties(
     const uno::Reference< uno::XInterface >& xCell,
     std::vector<VerticallyMergedCell> & rMergedCells)
 {
-    const sal_Int32 nCellProperties = rCellProperties.getLength();
     const uno::Reference< beans::XPropertySet > xCellPS(xCell, uno::UNO_QUERY);
-    for (sal_Int32 nProperty = 0; nProperty < nCellProperties; ++nProperty)
+    for (const auto& rCellProperty : rCellProperties)
     {
-        const OUString & rName  = rCellProperties[nProperty].Name;
-        const uno::Any & rValue = rCellProperties[nProperty].Value;
+        const OUString & rName  = rCellProperty.Name;
+        const uno::Any & rValue = rCellProperty.Value;
         if ( rName == "VerticalMerge" )
         {
             // determine left border position
diff --git a/sw/source/core/unocore/unotextmarkup.cxx b/sw/source/core/unocore/unotextmarkup.cxx
index 1cd5d76e779a..955793003b4a 100644
--- a/sw/source/core/unocore/unotextmarkup.cxx
+++ b/sw/source/core/unocore/unotextmarkup.cxx
@@ -396,31 +396,26 @@ void SAL_CALL SwXTextMarkup::commitMultiTextMarkup(
     if (!m_pImpl->m_pTextNode)
         return;
 
-    // check for equal length of all sequences
-    sal_Int32 nLen = rMarkups.getLength();
-
     // for grammar checking there should be exactly one sentence markup
     // and 0..n grammar markups.
     // Different markups are not expected but may be applied anyway since
     // that should be no problem...
     // but it has to be implemented, at the moment only this function is for
     // grammar markups and sentence markup only!
-    sal_Int32 nSentenceMarkUpIndex = -1;
-    const text::TextMarkupDescriptor *pMarkups = rMarkups.getConstArray();
-    sal_Int32 i;
-    for( i = 0;  i < nLen;  ++i )
+    const text::TextMarkupDescriptor *pSentenceMarkUp = nullptr;
+    for( const text::TextMarkupDescriptor &rDesc : rMarkups )
     {
-        if (pMarkups[i].nType == text::TextMarkupType::SENTENCE)
+        if (rDesc.nType == text::TextMarkupType::SENTENCE)
         {
-            if (nSentenceMarkUpIndex != -1)
+            if (pSentenceMarkUp != nullptr)
                 throw lang::IllegalArgumentException(); // there is already one sentence markup
-            nSentenceMarkUpIndex = i;
+            pSentenceMarkUp = &rDesc;
         }
-        else if( pMarkups[i].nType != text::TextMarkupType::PROOFREADING )
+        else if( rDesc.nType != text::TextMarkupType::PROOFREADING )
             return;
     }
 
-    if( nSentenceMarkUpIndex == -1 )
+    if( pSentenceMarkUp == nullptr )
         return;
 
     // get appropriate list to use...
@@ -449,16 +444,15 @@ void SAL_CALL SwXTextMarkup::commitMultiTextMarkup(
     {
         const ModelToViewHelper::ModelPosition aSentenceEnd =
             m_pImpl->m_ConversionMap.ConvertToModelPosition(
-                pMarkups[nSentenceMarkUpIndex].nOffset + pMarkups[nSentenceMarkUpIndex].nLength );
+                pSentenceMarkUp->nOffset + pSentenceMarkUp->nLength );
         bAcceptGrammarError = aSentenceEnd.mnPos > pWList->GetBeginInv();
         pWList->ClearGrammarList( aSentenceEnd.mnPos );
     }
 
     if( bAcceptGrammarError )
     {
-        for( i = 0;  i < nLen;  ++i )
+        for( const text::TextMarkupDescriptor &rDesc : rMarkups )
         {
-            const text::TextMarkupDescriptor &rDesc = pMarkups[i];
             lcl_commitGrammarMarkUp(m_pImpl->m_ConversionMap, pWList, rDesc.nType,
                 rDesc.aIdentifier, rDesc.nOffset, rDesc.nLength, rDesc.xMarkupInfoContainer );
         }
@@ -466,8 +460,7 @@ void SAL_CALL SwXTextMarkup::commitMultiTextMarkup(
     else
     {
         bRepaint = false;
-        i = nSentenceMarkUpIndex;
-        const text::TextMarkupDescriptor &rDesc = pMarkups[i];
+        const text::TextMarkupDescriptor &rDesc = *pSentenceMarkUp;
         lcl_commitGrammarMarkUp(m_pImpl->m_ConversionMap, pWList, rDesc.nType,
             rDesc.aIdentifier, rDesc.nOffset, rDesc.nLength, rDesc.xMarkupInfoContainer );
     }


More information about the Libreoffice-commits mailing list