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

Arkadiy Illarionov (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 24 07:09:09 UTC 2019


 uui/source/iahndl-ioexceptions.cxx |   51 ++++++++++---------------------------
 1 file changed, 15 insertions(+), 36 deletions(-)

New commits:
commit aed859c4825e10f0981686b9d8476538255b666f
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sun Jun 23 13:35:31 2019 +0300
Commit:     Arkadiy Illarionov <qarkai at gmail.com>
CommitDate: Mon Jun 24 09:08:12 2019 +0200

    tdf#39593 Replace copy-pasted functions with template
    
    Change-Id: Idcb6c3e13713a9c7cc545d1e287481fe6ccadba8
    Reviewed-on: https://gerrit.libreoffice.org/74595
    Tested-by: Jenkins
    Reviewed-by: Arkadiy Illarionov <qarkai at gmail.com>

diff --git a/uui/source/iahndl-ioexceptions.cxx b/uui/source/iahndl-ioexceptions.cxx
index bd85abbdcb1e..6da1ea3a6fab 100644
--- a/uui/source/iahndl-ioexceptions.cxx
+++ b/uui/source/iahndl-ioexceptions.cxx
@@ -30,17 +30,18 @@ using namespace com::sun::star;
 
 namespace {
 
+template<class T>
 bool
-getStringRequestArgument(uno::Sequence< uno::Any > const & rArguments,
-                         OUString const & rKey,
-                         OUString * pValue)
+getRequestArgument(uno::Sequence< uno::Any > const & rArguments,
+                   OUString const & rKey,
+                   T * pValue)
 {
-    for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
+    for (const auto& rArgument : rArguments)
     {
         beans::PropertyValue aProperty;
-        if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
+        if ((rArgument >>= aProperty) && aProperty.Name == rKey)
         {
-            OUString aValue;
+            T aValue;
             if (aProperty.Value >>= aValue)
             {
                 if (pValue)
@@ -53,36 +54,14 @@ getStringRequestArgument(uno::Sequence< uno::Any > const & rArguments,
 }
 
 bool
-getBoolRequestArgument(uno::Sequence< uno::Any > const & rArguments,
-                       OUString const & rKey,
-                       bool * pValue)
-{
-    for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
-    {
-        beans::PropertyValue aProperty;
-        if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
-        {
-            bool bValue;
-            if (aProperty.Value >>= bValue)
-            {
-                if (pValue)
-                    *pValue = bValue;
-                return true;
-            }
-        }
-    }
-    return false;
-}
-
-bool
 getResourceNameRequestArgument(uno::Sequence< uno::Any > const & rArguments,
                                OUString * pValue)
 {
-    if (!getStringRequestArgument(rArguments, "Uri",  pValue))
+    if (!getRequestArgument(rArguments, "Uri",  pValue))
         return false;
     // Use the resource name only for file URLs, to avoid confusion:
     if (pValue && comphelper::isFileUrl(*pValue))
-        getStringRequestArgument(rArguments, "ResourceName", pValue);
+        getRequestArgument(rArguments, "ResourceName", pValue);
     return true;
 }
 
@@ -183,7 +162,7 @@ UUIInteractionHelper::handleInteractiveIOException(
         case ucb::IOErrorCode_CANT_CREATE:
             {
                 OUString aArgFolder;
-                if (getStringRequestArgument(aRequestArguments, "Folder", &aArgFolder))
+                if (getRequestArgument(aRequestArguments, "Folder", &aArgFolder))
                 {
                     OUString aArgUri;
                     if (getResourceNameRequestArgument(aRequestArguments,
@@ -212,9 +191,9 @@ UUIInteractionHelper::handleInteractiveIOException(
                                                    &aArgUri))
                 {
                     OUString aResourceType;
-                    getStringRequestArgument(aRequestArguments, "ResourceType", &aResourceType);
+                    getRequestArgument(aRequestArguments, "ResourceType", &aResourceType);
                     bool bRemovable = false;
-                    getBoolRequestArgument(aRequestArguments, "Removable", &bRemovable);
+                    getRequestArgument(aRequestArguments, "Removable", &bRemovable);
                     nErrorCode = aResourceType == "volume"
                         ? (bRemovable
                            ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
@@ -233,8 +212,8 @@ UUIInteractionHelper::handleInteractiveIOException(
             {
                 OUString aArgVolume;
                 OUString aArgOtherVolume;
-                if (getStringRequestArgument(aRequestArguments, "Volume", &aArgVolume)
-                    && getStringRequestArgument(aRequestArguments, "OtherVolume",
+                if (getRequestArgument(aRequestArguments, "Volume", &aArgVolume)
+                    && getRequestArgument(aRequestArguments, "OtherVolume",
                         &aArgOtherVolume))
                 {
                     nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][1];
@@ -254,7 +233,7 @@ UUIInteractionHelper::handleInteractiveIOException(
                            &aArgUri))
                 {
                     OUString aResourceType;
-                    getStringRequestArgument(aRequestArguments, "ResourceType",
+                    getRequestArgument(aRequestArguments, "ResourceType",
                                             &aResourceType);
                     nErrorCode = aResourceType == "volume"
                         ? ERRCODE_UUI_IO_NOTEXISTS_VOLUME


More information about the Libreoffice-commits mailing list