unoidl/source/unoidl-write.cxx           |   12 ++++++------
 unotest/source/cpp/filters-test.cxx      |    2 +-
 unotest/source/cpp/officeconnection.cxx  |    3 +--
 unotools/source/config/compatibility.cxx |    2 +-
 unotools/source/config/fontcfg.cxx       |    5 ++---
 unotools/source/config/lingucfg.cxx      |   10 +++-------
 unotools/source/config/searchopt.cxx     |    6 ++----
 unotools/source/misc/fontcvt.cxx         |   19 +++++--------------
 unoxml/qa/unit/domtest.cxx               |    8 ++++----
 9 files changed, 25 insertions(+), 42 deletions(-)

New commits:
commit 04a58d7eae2b26559efd48ff7cdd23cec1c2187c
Author:     jsala <[email protected]>
AuthorDate: Sat Jun 25 13:35:01 2022 +0200
Commit:     Hossein <[email protected]>
CommitDate: Sun Nov 6 01:22:27 2022 +0100

    tdf#147021 Use std::size() instead of SAL_N_ELEMENTS() macro
    
    Also change some range based for.
    
    Change-Id: I32c5cbe0033c40cde3f1fc86ec8af90e558f2652
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141666
    Tested-by: Jenkins
    Reviewed-by: Hossein <[email protected]>

diff --git a/unoidl/source/unoidl-write.cxx b/unoidl/source/unoidl-write.cxx
index 84cad5bdda69..042b72c0471e 100644
--- a/unoidl/source/unoidl-write.cxx
+++ b/unoidl/source/unoidl-write.cxx
@@ -130,7 +130,7 @@ void write8(osl::File & file, sal_uInt64 value) {
     }
     unsigned char buf[1];
     buf[0] = value & 0xFF;
-    write(file, buf, SAL_N_ELEMENTS(buf));
+    write(file, buf, std::size(buf));
 }
 
 void write16(osl::File & file, sal_uInt64 value) {
@@ -142,7 +142,7 @@ void write16(osl::File & file, sal_uInt64 value) {
     unsigned char buf[2];
     buf[0] = value & 0xFF;
     buf[1] = (value >> 8) & 0xFF;
-    write(file, buf, SAL_N_ELEMENTS(buf));
+    write(file, buf, std::size(buf));
 }
 
 void write32(osl::File & file, sal_uInt64 value) {
@@ -156,7 +156,7 @@ void write32(osl::File & file, sal_uInt64 value) {
     buf[1] = (value >> 8) & 0xFF;
     buf[2] = (value >> 16) & 0xFF;
     buf[3] = (value >> 24) & 0xFF;
-    write(file, buf, SAL_N_ELEMENTS(buf));
+    write(file, buf, std::size(buf));
 }
 
 void write64(osl::File & file, sal_uInt64 value) {
@@ -169,7 +169,7 @@ void write64(osl::File & file, sal_uInt64 value) {
     buf[5] = (value >> 40) & 0xFF;
     buf[6] = (value >> 48) & 0xFF;
     buf[7] = (value >> 56) & 0xFF;
-    write(file, buf, SAL_N_ELEMENTS(buf));
+    write(file, buf, std::size(buf));
 }
 
 void writeIso60599Binary32(osl::File & file, float value) {
@@ -182,7 +182,7 @@ void writeIso60599Binary32(osl::File & file, float value) {
     std::swap(sa.buf[0], sa.buf[3]);
     std::swap(sa.buf[1], sa.buf[2]);
 #endif
-    write(file, sa.buf, SAL_N_ELEMENTS(sa.buf));
+    write(file, sa.buf, std::size(sa.buf));
 }
 
 void writeIso60599Binary64(osl::File & file, double value) {
@@ -197,7 +197,7 @@ void writeIso60599Binary64(osl::File & file, double value) {
     std::swap(sa.buf[2], sa.buf[5]);
     std::swap(sa.buf[3], sa.buf[4]);
 #endif
-    write(file, sa.buf, SAL_N_ELEMENTS(sa.buf));
+    write(file, sa.buf, std::size(sa.buf));
 }
 
 OString toAscii(OUString const & name) {
diff --git a/unotest/source/cpp/filters-test.cxx 
b/unotest/source/cpp/filters-test.cxx
index 7adbd9ca4d4d..1eaaa6219783 100644
--- a/unotest/source/cpp/filters-test.cxx
+++ b/unotest/source/cpp/filters-test.cxx
@@ -29,7 +29,7 @@ static void decode(const OUString& rIn, const OUString &rOut)
     //mcrypt --bare -a arcfour -o hex -k 435645 -s 3
     const sal_uInt8 aKey[3] = {'C', 'V', 'E'};
 
-    rtlCipherError result = rtl_cipher_init(cipher, 
rtl_Cipher_DirectionDecode, aKey, SAL_N_ELEMENTS(aKey), nullptr, 0);
+    rtlCipherError result = rtl_cipher_init(cipher, 
rtl_Cipher_DirectionDecode, aKey, std::size(aKey), nullptr, 0);
 
     CPPUNIT_ASSERT_EQUAL_MESSAGE("cipher init failed", rtl_Cipher_E_None, 
result);
 
diff --git a/unotest/source/cpp/officeconnection.cxx 
b/unotest/source/cpp/officeconnection.cxx
index 649d636d0fa6..850b19440d00 100644
--- a/unotest/source/cpp/officeconnection.cxx
+++ b/unotest/source/cpp/officeconnection.cxx
@@ -29,7 +29,6 @@
 #include <osl/process.h>
 #include <osl/test/uniquepipename.hxx>
 #include <osl/time.h>
-#include <sal/macros.h>
 #include <unotest/getargument.hxx>
 #include <unotest/officeconnection.hxx>
 #include <unotest/toabsolutefileurl.hxx>
@@ -81,7 +80,7 @@ void OfficeConnection::setUp() {
             osl_executeProcess(
                 toAbsoluteFileUrl(
                     argSoffice.copy(RTL_CONSTASCII_LENGTH("path:"))).pData,
-                args, SAL_N_ELEMENTS(args), 0, nullptr, nullptr, envs, envs == 
nullptr ? 0 : 1,
+                args, std::size(args), 0, nullptr, nullptr, envs, envs == 
nullptr ? 0 : 1,
                 &process_));
     } else if (argSoffice.match("connect:")) {
         desc = argSoffice.copy(RTL_CONSTASCII_LENGTH("connect:"));
diff --git a/unotools/source/config/compatibility.cxx 
b/unotools/source/config/compatibility.cxx
index a5ac6ea895b4..4f0e1d2ac20c 100644
--- a/unotools/source/config/compatibility.cxx
+++ b/unotools/source/config/compatibility.cxx
@@ -96,7 +96,7 @@ OUString SvtCompatibilityEntry::getName( const Index rIdx )
     };
 
     /* Size of sPropertyName array not equal size of the 
SvtCompatibilityEntry::Index enum class */
-    assert( SAL_N_ELEMENTS(sPropertyName) == static_cast<int>( 
SvtCompatibilityEntry::getElementCount() ) );
+    assert( std::size(sPropertyName) == 
SvtCompatibilityEntry::getElementCount() );
 
     return OUString::createFromAscii( sPropertyName[ static_cast<int>(rIdx) ] 
);
 }
diff --git a/unotools/source/config/fontcfg.cxx 
b/unotools/source/config/fontcfg.cxx
index 0a8ab40b3116..beeba82030d0 100644
--- a/unotools/source/config/fontcfg.cxx
+++ b/unotools/source/config/fontcfg.cxx
@@ -32,7 +32,6 @@
 #include <unotools/syslocale.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <osl/diagnose.h>
-#include <sal/macros.h>
 #include <sal/log.hxx>
 
 #include <string.h>
@@ -886,7 +885,7 @@ FontWeight FontSubstConfiguration::getSubstWeight( const 
css::uno::Reference< XN
         {
             if( !pLine->isEmpty() )
             {
-                for( weight=SAL_N_ELEMENTS(pWeightNames)-1; weight >= 0; 
weight-- )
+                for( weight=std::size(pWeightNames)-1; weight >= 0; weight-- )
                     if( pLine->equalsIgnoreAsciiCaseAscii( 
pWeightNames[weight].pName ) )
                         break;
             }
@@ -913,7 +912,7 @@ FontWidth FontSubstConfiguration::getSubstWidth( const 
css::uno::Reference< XNam
         {
             if( !pLine->isEmpty() )
             {
-                for( width=SAL_N_ELEMENTS(pWidthNames)-1; width >= 0; width-- )
+                for( width=std::size(pWidthNames)-1; width >= 0; width-- )
                     if( pLine->equalsIgnoreAsciiCaseAscii( 
pWidthNames[width].pName ) )
                         break;
             }
diff --git a/unotools/source/config/lingucfg.cxx 
b/unotools/source/config/lingucfg.cxx
index efee41e6bbb2..03969c3d1ffe 100644
--- a/unotools/source/config/lingucfg.cxx
+++ b/unotools/source/config/lingucfg.cxx
@@ -33,7 +33,6 @@
 #include <unotools/configitem.hxx>
 #include <unotools/lingucfg.hxx>
 #include <unotools/linguprops.hxx>
-#include <sal/macros.h>
 #include <comphelper/getexpandeduri.hxx>
 #include <comphelper/processfactory.hxx>
 #include <o3tl/string_view.hxx>
@@ -271,15 +270,12 @@ NamesToHdl const aNamesToHdl[] =
 uno::Sequence< OUString > SvtLinguConfigItem::GetPropertyNames()
 {
     uno::Sequence< OUString > aNames;
-
-    sal_Int32 nMax = SAL_N_ELEMENTS(aNamesToHdl);
-
-    aNames.realloc( nMax );
+    aNames.realloc(std::size(aNamesToHdl));
     OUString *pNames = aNames.getArray();
     sal_Int32 nIdx = 0;
-    for (sal_Int32 i = 0; i < nMax;  ++i)
+    for (auto const & nameToHdl: aNamesToHdl)
     {
-        const char *pFullPropName = aNamesToHdl[i].pFullPropName;
+        const char *pFullPropName = nameToHdl.pFullPropName;
         if (pFullPropName)
             pNames[ nIdx++ ] = OUString::createFromAscii( pFullPropName );
     }
diff --git a/unotools/source/config/searchopt.cxx 
b/unotools/source/config/searchopt.cxx
index 23a2ae93358f..4237fd7281dd 100644
--- a/unotools/source/config/searchopt.cxx
+++ b/unotools/source/config/searchopt.cxx
@@ -24,7 +24,6 @@
 #include <unotools/configitem.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
 #include <com/sun/star/uno/Any.h>
-#include <sal/macros.h>
 #include <osl/diagnose.h>
 #include <i18nutil/transliteration.hxx>
 
@@ -153,10 +152,9 @@ Sequence< OUString > 
SvtSearchOptions_Impl::GetPropertyNames()
         "IsUseWildcard"                         // 29
     };
 
-    const int nCount = SAL_N_ELEMENTS( aPropNames );
-    Sequence< OUString > aNames( nCount );
+    Sequence< OUString > aNames(std::size(aPropNames));
     OUString* pNames = aNames.getArray();
-    for (sal_Int32 i = 0;  i < nCount;  ++i)
+    for (std::size_t i = 0;  i < std::size(aPropNames); ++i)
         pNames[i] = OUString::createFromAscii( aPropNames[i] );
 
     return aNames;
diff --git a/unotools/source/misc/fontcvt.cxx b/unotools/source/misc/fontcvt.cxx
index 02796e7d3ca2..2c415dae969f 100644
--- a/unotools/source/misc/fontcvt.cxx
+++ b/unotools/source/misc/fontcvt.cxx
@@ -23,7 +23,6 @@
 #include <sal/log.hxx>
 #include <unotools/fontcvt.hxx>
 #include <unotools/fontdefs.hxx>
-#include <sal/macros.h>
 
 #include <cstddef>
 #include <map>
@@ -1163,11 +1162,8 @@ 
StarSymbolToMSMultiFontImpl::StarSymbolToMSMultiFontImpl()
 
     //Reverse map from a given starsymbol char to exact matches in ms symbol
     //fonts.
-    int nEntries = SAL_N_ELEMENTS(aConservativeTable);
-    int i;
-    for (i = 0; i < nEntries; ++i)
+    for (auto const & r: aConservativeTable)
     {
-        const ConvertTable& r = aConservativeTable[i];
         SymbolEntry aEntry;
         aEntry.eFont = r.meFont;
         for (aEntry.cIndex = 0xFF; aEntry.cIndex >= 0x20; --aEntry.cIndex)
@@ -1190,12 +1186,9 @@ 
StarSymbolToMSMultiFontImpl::StarSymbolToMSMultiFontImpl()
             sizeof(aTNRExtraTab))
     };
 
-     //Allow extra conversions that are not perfect, but "good enough"
-    nEntries = SAL_N_ELEMENTS(aAggressiveTable);
-
-    for (i = 0; i < nEntries; ++i)
+    //Allow extra conversions that are not perfect, but "good enough"
+    for (auto const & r: aAggressiveTable)
     {
-        const ExtendedConvertTable& r = aAggressiveTable[i];
         SymbolEntry aEntry;
         aEntry.eFont = r.meFont;
         for (int j = r.mnSize / sizeof(r.mpTable[0]) - 1; j >=0; --j)
@@ -1353,9 +1346,8 @@ const ConvertChar* ConvertChar::GetRecodeData( 
std::u16string_view rOrgFontName,
     if( aMapName == "starsymbol"
      || aMapName == "opensymbol" )
     {
-        for( std::size_t i = 0; i < SAL_N_ELEMENTS(aStarSymbolRecodeTable); 
++i)
+        for (auto const & r: aStarSymbolRecodeTable)
         {
-            const RecodeTable& r = aStarSymbolRecodeTable[i];
             if( aOrgName.equalsAscii( r.pOrgName ) )
             {
                 pCvt = &r.aCvt;
@@ -1368,9 +1360,8 @@ const ConvertChar* ConvertChar::GetRecodeData( 
std::u16string_view rOrgFontName,
     //adobe-symbol to unicode conversion in rtl instead
     else if( aMapName == "applesymbol" )
     {
-        for( std::size_t i = 0; i < SAL_N_ELEMENTS(aAppleSymbolRecodeTable); 
++i)
+        for (auto const & r: aAppleSymbolRecodeTable)
         {
-            const RecodeTable& r = aAppleSymbolRecodeTable[i];
             if( aOrgName.equalsAscii( r.pOrgName ) )
             {
                 pCvt = &r.aCvt;
diff --git a/unoxml/qa/unit/domtest.cxx b/unoxml/qa/unit/domtest.cxx
index 8aa2ba4b737f..479ff3fea697 100644
--- a/unoxml/qa/unit/domtest.cxx
+++ b/unoxml/qa/unit/domtest.cxx
@@ -204,9 +204,9 @@ struct BasicTest : public test::BootstrapFixture
         mxErrHandler.set( new ErrorHandler() );
         uno::Reference<XDocumentBuilder> xDB( 
getMultiServiceFactory()->createInstance("com.sun.star.xml.dom.DocumentBuilder"),
 uno::UNO_QUERY_THROW );
         mxDomBuilder.set( xDB );
-        mxValidInStream.set( new 
SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 
const *>(validTestFile), SAL_N_ELEMENTS(validTestFile))) );
-        mxWarningInStream.set( new 
SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 
const *>(warningTestFile), SAL_N_ELEMENTS(warningTestFile))) );
-        mxErrorInStream.set( new 
SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 
const *>(errorTestFile), SAL_N_ELEMENTS(errorTestFile))) );
+        mxValidInStream.set( new 
SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 
const *>(validTestFile), std::size(validTestFile))) );
+        mxWarningInStream.set( new 
SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 
const *>(warningTestFile), std::size(warningTestFile))) );
+        mxErrorInStream.set( new 
SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 
const *>(errorTestFile), std::size(errorTestFile))) );
         mxDomBuilder->setErrorHandler(mxErrHandler);
     }
 
@@ -288,7 +288,7 @@ struct SerializerTest : public test::BootstrapFixture
         mxErrHandler.set( new ErrorHandler() );
         uno::Reference<XDocumentBuilder> xDB( 
getMultiServiceFactory()->createInstance("com.sun.star.xml.dom.DocumentBuilder"),
 uno::UNO_QUERY_THROW );
         mxDomBuilder.set( xDB );
-        mxInStream.set( new 
SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 
const *>(validTestFile), SAL_N_ELEMENTS(validTestFile))) );
+        mxInStream.set( new 
SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 
const *>(validTestFile), std::size(validTestFile))) );
         mxDomBuilder->setErrorHandler(mxErrHandler);
         mxHandler.set( new DocumentHandler );
         mxTokHandler.set( new TokenHandler );

Reply via email to