[Libreoffice-commits] core.git: uui/source

Arkadiy Illarionov (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 25 19:40:32 UTC 2019


 uui/source/getcontinuations.hxx      |   24 ++++-----
 uui/source/iahndl-authentication.cxx |    6 +-
 uui/source/iahndl-filter.cxx         |   86 ++++++++++++++++-------------------
 uui/source/iahndl-ssl.cxx            |   19 +++----
 uui/source/iahndl.cxx                |    8 +--
 uui/source/passwordcontainer.cxx     |    4 -
 6 files changed, 68 insertions(+), 79 deletions(-)

New commits:
commit 75957a96c43b83418d387e9174415b6d90cf9c63
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sun Jun 23 15:42:31 2019 +0300
Commit:     Arkadiy Illarionov <qarkai at gmail.com>
CommitDate: Tue Jun 25 21:39:40 2019 +0200

    Simplify Sequence iterations in uui
    
    Use range-based loops or replace with STL functions
    
    Change-Id: I36ca6016d23360d121935d9f25e8cc8d2dad08c3
    Reviewed-on: https://gerrit.libreoffice.org/74625
    Tested-by: Jenkins
    Reviewed-by: Arkadiy Illarionov <qarkai at gmail.com>

diff --git a/uui/source/getcontinuations.hxx b/uui/source/getcontinuations.hxx
index 8175b002b974..03dc049f45d1 100644
--- a/uui/source/getcontinuations.hxx
+++ b/uui/source/getcontinuations.hxx
@@ -50,11 +50,11 @@ void getContinuations(
     css::uno::Reference< t1 > * pContinuation1,
     css::uno::Reference< t2 > * pContinuation2)
 {
-    for (sal_Int32 i = 0; i < rContinuations.getLength(); ++i)
+    for (const auto& rContinuation : rContinuations)
     {
-        if (setContinuation(rContinuations[i], pContinuation1))
+        if (setContinuation(rContinuation, pContinuation1))
             continue;
-        if (setContinuation(rContinuations[i], pContinuation2))
+        if (setContinuation(rContinuation, pContinuation2))
             continue;
     }
 }
@@ -67,13 +67,13 @@ void getContinuations(
     css::uno::Reference< t2 > * pContinuation2,
     css::uno::Reference< t3 > * pContinuation3)
 {
-    for (sal_Int32 i = 0; i < rContinuations.getLength(); ++i)
+    for (const auto& rContinuation : rContinuations)
     {
-        if (setContinuation(rContinuations[i], pContinuation1))
+        if (setContinuation(rContinuation, pContinuation1))
             continue;
-        if (setContinuation(rContinuations[i], pContinuation2))
+        if (setContinuation(rContinuation, pContinuation2))
             continue;
-        if (setContinuation(rContinuations[i], pContinuation3))
+        if (setContinuation(rContinuation, pContinuation3))
             continue;
     }
 }
@@ -87,15 +87,15 @@ void getContinuations(
     css::uno::Reference< t3 > * pContinuation3,
     css::uno::Reference< t4 > * pContinuation4)
 {
-    for (sal_Int32 i = 0; i < rContinuations.getLength(); ++i)
+    for (const auto& rContinuation : rContinuations)
     {
-        if (setContinuation(rContinuations[i], pContinuation1))
+        if (setContinuation(rContinuation, pContinuation1))
             continue;
-        if (setContinuation(rContinuations[i], pContinuation2))
+        if (setContinuation(rContinuation, pContinuation2))
             continue;
-        if (setContinuation(rContinuations[i], pContinuation3))
+        if (setContinuation(rContinuation, pContinuation3))
             continue;
-        if (setContinuation(rContinuations[i], pContinuation4))
+        if (setContinuation(rContinuation, pContinuation4))
             continue;
     }
 }
diff --git a/uui/source/iahndl-authentication.cxx b/uui/source/iahndl-authentication.cxx
index 114cf8b87563..b6c74f4926db 100644
--- a/uui/source/iahndl-authentication.cxx
+++ b/uui/source/iahndl-authentication.cxx
@@ -137,9 +137,9 @@ void getRememberModes(
         bool bHasRememberModeSession = false;
         bool bHasRememberModePersistent = false;
 
-        for (sal_Int32 i = 0; i < nCount; ++i)
+        for (const auto& rRememberMode : rRememberModes)
         {
-            switch ( rRememberModes[i] )
+            switch ( rRememberMode )
             {
             case ucb::RememberAuthentication_NO:
                 break;
@@ -150,7 +150,7 @@ void getRememberModes(
                 bHasRememberModePersistent = true;
                 break;
             default:
-                SAL_WARN( "uui", "Unsupported RememberAuthentication value" << static_cast<sal_Int32>(rRememberModes[i]) );
+                SAL_WARN( "uui", "Unsupported RememberAuthentication value" << static_cast<sal_Int32>(rRememberMode) );
                 break;
             }
         }
diff --git a/uui/source/iahndl-filter.cxx b/uui/source/iahndl-filter.cxx
index 64bc7fe7ebc5..a2cdb255a6d9 100644
--- a/uui/source/iahndl-filter.cxx
+++ b/uui/source/iahndl-filter.cxx
@@ -205,68 +205,62 @@ handleFilterOptionsRequest_(
         try
         {
             OUString aFilterName;
-            sal_Int32 nPropCount = rRequest.rProperties.getLength();
-            for( sal_Int32 ind = 0; ind < nPropCount; ++ind )
+            auto pProperty = std::find_if(rRequest.rProperties.begin(), rRequest.rProperties.end(),
+                [](const beans::PropertyValue& rProp) { return rProp.Name == "FilterName"; });
+            if (pProperty != rRequest.rProperties.end())
             {
-                if( rRequest.rProperties[ind].Name == "FilterName" )
-                {
-                    rRequest.rProperties[ind].Value >>= aFilterName;
-                    break;
-                }
+                pProperty->Value >>= aFilterName;
             }
 
             uno::Sequence < beans::PropertyValue > aProps;
             if ( xFilterCFG->getByName( aFilterName ) >>= aProps )
             {
-                sal_Int32 nPropertyCount = aProps.getLength();
-                for( sal_Int32 nProperty=0;
-                     nProperty < nPropertyCount;
-                     ++nProperty )
-                    if( aProps[nProperty].Name == "UIComponent" )
+                auto pProp = std::find_if(aProps.begin(), aProps.end(),
+                    [](const beans::PropertyValue& rProp) { return rProp.Name == "UIComponent"; });
+                if (pProp != aProps.end())
+                {
+                    OUString aServiceName;
+                    pProp->Value >>= aServiceName;
+                    if( !aServiceName.isEmpty() )
                     {
-                        OUString aServiceName;
-                        aProps[nProperty].Value >>= aServiceName;
-                        if( !aServiceName.isEmpty() )
+                        uno::Sequence<uno::Any> aDialogArgs(comphelper::InitAnyPropertySequence(
                         {
-                            uno::Sequence<uno::Any> aDialogArgs(comphelper::InitAnyPropertySequence(
-                            {
-                                {"ParentWindow", uno::Any(rWindow)},
-                            }));
+                            {"ParentWindow", uno::Any(rWindow)},
+                        }));
 
+                        uno::Reference<
+                            ui::dialogs::XExecutableDialog > xFilterDialog(
+                                xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+                                    aServiceName, aDialogArgs, xContext ),
+                                uno::UNO_QUERY );
+
+                        uno::Reference< beans::XPropertyAccess >
+                            xFilterProperties( xFilterDialog,
+                                               uno::UNO_QUERY );
+
+                        if( xFilterDialog.is() && xFilterProperties.is() )
+                        {
                             uno::Reference<
-                                ui::dialogs::XExecutableDialog > xFilterDialog(
-                                    xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
-                                        aServiceName, aDialogArgs, xContext ),
-                                    uno::UNO_QUERY );
+                                document::XImporter > xImporter(
+                                    xFilterDialog, uno::UNO_QUERY );
+                            if( xImporter.is() )
+                                xImporter->setTargetDocument(
+                                    uno::Reference< lang::XComponent >(
+                                        rRequest.rModel, uno::UNO_QUERY ) );
 
-                            uno::Reference< beans::XPropertyAccess >
-                                xFilterProperties( xFilterDialog,
-                                                   uno::UNO_QUERY );
+                            xFilterProperties->setPropertyValues(
+                                rRequest.rProperties );
 
-                            if( xFilterDialog.is() && xFilterProperties.is() )
+                            if( xFilterDialog->execute() )
                             {
-                                uno::Reference<
-                                    document::XImporter > xImporter(
-                                        xFilterDialog, uno::UNO_QUERY );
-                                if( xImporter.is() )
-                                    xImporter->setTargetDocument(
-                                        uno::Reference< lang::XComponent >(
-                                            rRequest.rModel, uno::UNO_QUERY ) );
-
-                                xFilterProperties->setPropertyValues(
-                                    rRequest.rProperties );
-
-                                if( xFilterDialog->execute() )
-                                {
-                                    xFilterOptions->setFilterOptions(
-                                        xFilterProperties->getPropertyValues() );
-                                    xFilterOptions->select();
-                                    return;
-                                }
+                                xFilterOptions->setFilterOptions(
+                                    xFilterProperties->getPropertyValues() );
+                                xFilterOptions->select();
+                                return;
                             }
                         }
-                        break;
                     }
+                }
             }
         }
         catch( container::NoSuchElementException& )
diff --git a/uui/source/iahndl-ssl.cxx b/uui/source/iahndl-ssl.cxx
index 7c46810def31..74eaa40748ec 100644
--- a/uui/source/iahndl-ssl.cxx
+++ b/uui/source/iahndl-ssl.cxx
@@ -82,9 +82,7 @@ bool
 isDomainMatch(
               const OUString& hostName, const uno::Sequence< OUString >& certHostNames)
 {
-    for ( int i = 0; i < certHostNames.getLength(); i++){
-       OUString element = certHostNames[i];
-
+    for ( const OUString& element : certHostNames){
        if (element.isEmpty())
            continue;
 
@@ -260,15 +258,14 @@ handleCertificateValidationRequest_(
 
     uno::Sequence< uno::Reference< security::XCertificateExtension > > extensions = rRequest.Certificate->getExtensions();
     uno::Reference< security::XSanExtension > sanExtension;
-    for (sal_Int32 i = 0 ; i < extensions.getLength(); ++i)
+    auto pExtension = std::find_if(extensions.begin(), extensions.end(),
+        [](const uno::Reference< security::XCertificateExtension >& element) {
+            OString aId ( reinterpret_cast<const char *>(element->getExtensionId().getConstArray()), element->getExtensionId().getLength());
+            return aId == OID_SUBJECT_ALTERNATIVE_NAME;
+        });
+    if (pExtension != extensions.end())
     {
-        uno::Reference< security::XCertificateExtension >element = extensions[i];
-        OString aId ( reinterpret_cast<const char *>(element->getExtensionId().getConstArray()), element->getExtensionId().getLength());
-        if (aId == OID_SUBJECT_ALTERNATIVE_NAME)
-        {
-           sanExtension = uno::Reference<security::XSanExtension>(element, uno::UNO_QUERY);
-           break;
-        }
+       sanExtension = uno::Reference<security::XSanExtension>(*pExtension, uno::UNO_QUERY);
     }
 
     std::vector<security::CertAltNameEntry> altNames;
diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx
index f0c6cdb67016..4b074d151984 100644
--- a/uui/source/iahndl.cxx
+++ b/uui/source/iahndl.cxx
@@ -884,20 +884,18 @@ UUIInteractionHelper::getInteractionHandlerList(
         uno::Reference< container::XNameAccess > xNameAccess(
             xInterface, uno::UNO_QUERY_THROW );
         uno::Sequence< OUString > aElems = xNameAccess->getElementNames();
-        const OUString* pElems = aElems.getConstArray();
-        sal_Int32 nCount = aElems.getLength();
 
-        if ( nCount > 0 )
+        if ( aElems.hasElements() )
         {
             uno::Reference< container::XHierarchicalNameAccess >
                                 xHierNameAccess( xInterface, uno::UNO_QUERY_THROW );
 
             // Iterate over children.
-            for ( sal_Int32 n = 0; n < nCount; ++n )
+            for ( const auto& rElem : aElems )
             {
                 OUStringBuffer aElemBuffer;
                 aElemBuffer.append( "['" );
-                aElemBuffer.append( pElems[ n ] );
+                aElemBuffer.append( rElem );
 
                 try
                 {
diff --git a/uui/source/passwordcontainer.cxx b/uui/source/passwordcontainer.cxx
index de057886e792..5335930c1199 100644
--- a/uui/source/passwordcontainer.cxx
+++ b/uui/source/passwordcontainer.cxx
@@ -370,9 +370,9 @@ PasswordContainerInteractionHandler::handleInteractionRequest(
     uno::Reference< ucb::XInteractionSupplyAuthentication >
         xSupplyAuthentication;
 
-    for ( sal_Int32 i = 0; i < rContinuations.getLength(); ++i )
+    for ( const auto& rContinuation : rContinuations )
     {
-        xSupplyAuthentication.set( rContinuations[i], uno::UNO_QUERY );
+        xSupplyAuthentication.set( rContinuation, uno::UNO_QUERY );
         if( xSupplyAuthentication.is() )
             break;
     }


More information about the Libreoffice-commits mailing list