include/xmloff/XMLFilterServiceNames.h                |   30 ++++-----
 sw/source/filter/xml/xmltexti.cxx                     |   50 +++-------------
 xmloff/source/core/XMLEmbeddedObjectImportContext.cxx |   41 ++++---------
 xmloff/source/core/xmlexp.cxx                         |   56 +++++-------------
 4 files changed, 57 insertions(+), 120 deletions(-)

New commits:
commit 3e11faf2d263f97a96274a8247b5a123ec8fe7c6
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Oct 10 23:00:45 2021 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Oct 11 06:14:19 2021 +0200

    Expand some defines and simplify loops
    
    Change-Id: I5cbfa815fb2b3d92eac1959ece67160fae4cd556
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123170
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/xmloff/XMLFilterServiceNames.h 
b/include/xmloff/XMLFilterServiceNames.h
index ea98ba8bf47e..31549345bec4 100644
--- a/include/xmloff/XMLFilterServiceNames.h
+++ b/include/xmloff/XMLFilterServiceNames.h
@@ -17,24 +17,24 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#ifndef INCLUDED_XMLOFF_XMLFILTERSERVICENAMES_H
-#define INCLUDED_XMLOFF_XMLFILTERSERVICENAMES_H
+#pragma once
 
+#include <sal/config.h>
 
-#define XML_IMPORT_FILTER_WRITER    "com.sun.star.comp.Writer.XMLOasisImporter"
-#define XML_IMPORT_FILTER_CALC      "com.sun.star.comp.Calc.XMLOasisImporter"
-#define XML_IMPORT_FILTER_DRAW      "com.sun.star.comp.Draw.XMLOasisImporter"
-#define XML_IMPORT_FILTER_IMPRESS   
"com.sun.star.comp.Impress.XMLOasisImporter"
-#define XML_IMPORT_FILTER_MATH      "com.sun.star.comp.Math.XMLImporter"
-#define XML_IMPORT_FILTER_CHART     "com.sun.star.comp.Chart.XMLOasisImporter"
+#include <rtl/ustring.hxx>
 
-#define XML_EXPORT_FILTER_WRITER    "com.sun.star.comp.Writer.XMLOasisExporter"
-#define XML_EXPORT_FILTER_CALC      "com.sun.star.comp.Calc.XMLOasisExporter"
-#define XML_EXPORT_FILTER_DRAW      "com.sun.star.comp.Draw.XMLOasisExporter"
-#define XML_EXPORT_FILTER_IMPRESS   
"com.sun.star.comp.Impress.XMLOasisExporter"
-#define XML_EXPORT_FILTER_MATH      "com.sun.star.comp.Math.XMLExporter"
-#define XML_EXPORT_FILTER_CHART     "com.sun.star.comp.Chart.XMLOasisExporter"
+inline constexpr OUStringLiteral XML_IMPORT_FILTER_WRITER = 
u"com.sun.star.comp.Writer.XMLOasisImporter";
+inline constexpr OUStringLiteral XML_IMPORT_FILTER_CALC = 
u"com.sun.star.comp.Calc.XMLOasisImporter";
+inline constexpr OUStringLiteral XML_IMPORT_FILTER_DRAW = 
u"com.sun.star.comp.Draw.XMLOasisImporter";
+inline constexpr OUStringLiteral XML_IMPORT_FILTER_IMPRESS = 
u"com.sun.star.comp.Impress.XMLOasisImporter";
+inline constexpr OUStringLiteral XML_IMPORT_FILTER_MATH = 
u"com.sun.star.comp.Math.XMLImporter";
+inline constexpr OUStringLiteral XML_IMPORT_FILTER_CHART = 
u"com.sun.star.comp.Chart.XMLOasisImporter";
 
-#endif
+inline constexpr OUStringLiteral XML_EXPORT_FILTER_WRITER = 
u"com.sun.star.comp.Writer.XMLOasisExporter";
+inline constexpr OUStringLiteral XML_EXPORT_FILTER_CALC = 
u"com.sun.star.comp.Calc.XMLOasisExporter";
+inline constexpr OUStringLiteral XML_EXPORT_FILTER_DRAW = 
u"com.sun.star.comp.Draw.XMLOasisExporter";
+inline constexpr OUStringLiteral XML_EXPORT_FILTER_IMPRESS = 
u"com.sun.star.comp.Impress.XMLOasisExporter";
+inline constexpr OUStringLiteral XML_EXPORT_FILTER_MATH = 
u"com.sun.star.comp.Math.XMLExporter";
+inline constexpr OUStringLiteral XML_EXPORT_FILTER_CHART = 
u"com.sun.star.comp.Chart.XMLOasisExporter";
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/xml/xmltexti.cxx 
b/sw/source/filter/xml/xmltexti.cxx
index c4c28b37a40c..d2d4e3e71daf 100644
--- a/sw/source/filter/xml/xmltexti.cxx
+++ b/sw/source/filter/xml/xmltexti.cxx
@@ -63,6 +63,8 @@
 #include <tools/globname.hxx>
 #include <tools/UnitConversion.hxx>
 
+#include <utility>
+
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::lang;
@@ -71,33 +73,13 @@ using namespace ::com::sun::star::frame;
 using namespace ::com::sun::star::beans;
 using namespace xml::sax;
 
-namespace {
-
-struct XMLServiceMapEntry_Impl
-{
-    const char *sFilterService;
-    sal_Int32   nFilterServiceLen;
-
-    sal_uInt32  n1;
-    sal_uInt16  n2, n3;
-    sal_uInt8   n4, n5, n6, n7, n8, n9, n10, n11;
-};
-
-}
-
-#define SERVICE_MAP_ENTRY( app, s ) \
-    { XML_IMPORT_FILTER_##app, sizeof(XML_IMPORT_FILTER_##app)-1, \
-      SO3_##s##_CLASSID }
-
-const XMLServiceMapEntry_Impl aServiceMap[] =
-{
-    SERVICE_MAP_ENTRY( WRITER, SW ),
-    SERVICE_MAP_ENTRY( CALC, SC ),
-    SERVICE_MAP_ENTRY( DRAW, SDRAW ),
-    SERVICE_MAP_ENTRY( IMPRESS, SIMPRESS ),
-    SERVICE_MAP_ENTRY( CHART, SCH ),
-    SERVICE_MAP_ENTRY( MATH, SM ),
-    { nullptr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+const std::pair<OUString, SvGUID> aServiceMap[] = {
+    { XML_IMPORT_FILTER_WRITER, { SO3_SW_CLASSID } },
+    { XML_IMPORT_FILTER_CALC, { SO3_SC_CLASSID } },
+    { XML_IMPORT_FILTER_DRAW, { SO3_SDRAW_CLASSID } },
+    { XML_IMPORT_FILTER_IMPRESS, { SO3_SIMPRESS_CLASSID } },
+    { XML_IMPORT_FILTER_CHART, { SO3_SCH_CLASSID } },
+    { XML_IMPORT_FILTER_MATH, { SO3_SM_CLASSID } },
 };
 static void lcl_putHeightAndWidth ( SfxItemSet &rItemSet,
         sal_Int32 nHeight, sal_Int32 nWidth,
@@ -250,22 +232,14 @@ uno::Reference< XPropertySet > 
SwXMLTextImportHelper::createAndInsertOLEObject(
     {
         bool bInsert = false;
         SvGlobalName aClassName;
-        const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
-        while( pEntry->sFilterService )
+        for (const auto& [sFilterService, rCLASSID] : aServiceMap)
         {
-            if( aObjName.equalsAsciiL( pEntry->sFilterService,
-                                     pEntry->nFilterServiceLen ) )
+            if (aObjName == sFilterService)
             {
-                aClassName = SvGlobalName( pEntry->n1, pEntry->n2,
-                                           pEntry->n3, pEntry->n4,
-                                           pEntry->n5, pEntry->n6,
-                                           pEntry->n7, pEntry->n8,
-                                           pEntry->n9, pEntry->n10,
-                                           pEntry->n11  );
+                aClassName = SvGlobalName(rCLASSID);
                 bInsert = true;
                 break;
             }
-            pEntry++;
         }
 
         if( bInsert )
diff --git a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx 
b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
index 6854b56d7f79..29c9f67c1274 100644
--- a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
+++ b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
@@ -20,6 +20,7 @@
 #include <sal/config.h>
 
 #include <string_view>
+#include <tuple>
 
 #include <sal/log.hxx>
 #include <com/sun/star/document/XImporter.hpp>
@@ -186,35 +187,21 @@ 
XMLEmbeddedObjectImportContext::XMLEmbeddedObjectImportContext(
 
         if( !sClass.isEmpty() )
         {
-            static struct { XMLTokenEnum eClass; std::u16string_view 
sFilterService;
-            } const aServiceMap[] = {
-                { XML_TEXT,         std::u16string_view(u"" 
XML_IMPORT_FILTER_WRITER) },
-                { XML_ONLINE_TEXT,  std::u16string_view(u"" 
XML_IMPORT_FILTER_WRITER) },
-                { XML_SPREADSHEET,  std::u16string_view(u"" 
XML_IMPORT_FILTER_CALC) },
-                { XML_DRAWING,      std::u16string_view(u"" 
XML_IMPORT_FILTER_DRAW) },
-                { XML_GRAPHICS,     std::u16string_view(u"" 
XML_IMPORT_FILTER_DRAW) },
-                { XML_PRESENTATION, std::u16string_view(u"" 
XML_IMPORT_FILTER_IMPRESS) },
-                { XML_CHART,        std::u16string_view(u"" 
XML_IMPORT_FILTER_CHART) }};
-            for (auto const & entry: aServiceMap)
+            static const std::tuple<XMLTokenEnum, OUString, SvGUID> 
aServiceMap[] = {
+                { XML_TEXT, XML_IMPORT_FILTER_WRITER, { SO3_SW_CLASSID } },
+                { XML_ONLINE_TEXT, XML_IMPORT_FILTER_WRITER, { 
SO3_SWWEB_CLASSID } },
+                { XML_SPREADSHEET, XML_IMPORT_FILTER_CALC, { SO3_SC_CLASSID } 
},
+                { XML_DRAWING, XML_IMPORT_FILTER_DRAW, { SO3_SDRAW_CLASSID } },
+                { XML_GRAPHICS, XML_IMPORT_FILTER_DRAW, { SO3_SDRAW_CLASSID } 
},
+                { XML_PRESENTATION, XML_IMPORT_FILTER_IMPRESS, { 
SO3_SIMPRESS_CLASSID } },
+                { XML_CHART, XML_IMPORT_FILTER_CHART, { SO3_SCH_CLASSID } },
+            };
+            for (auto const& [eClass, sMatchingFilterService, rCLASSID] : 
aServiceMap)
             {
-                if( IsXMLToken( sClass, entry.eClass ) )
+                if (IsXMLToken(sClass, eClass))
                 {
-                    sFilterService = entry.sFilterService;
-
-                    switch( entry.eClass )
-                    {
-                    case XML_TEXT:          aName = 
SvGlobalName(SO3_SW_CLASSID); break;
-                    case XML_ONLINE_TEXT:   aName = 
SvGlobalName(SO3_SWWEB_CLASSID); break;
-                    case XML_SPREADSHEET:   aName = 
SvGlobalName(SO3_SC_CLASSID); break;
-                    case XML_DRAWING:
-                    case XML_GRAPHICS:
-                    case XML_IMAGE:     aName = 
SvGlobalName(SO3_SDRAW_CLASSID); break;
-                    case XML_PRESENTATION:  aName = 
SvGlobalName(SO3_SIMPRESS_CLASSID); break;
-                    case XML_CHART:         aName = 
SvGlobalName(SO3_SCH_CLASSID); break;
-                    default:
-                        break;
-                    }
-
+                    sFilterService = sMatchingFilterService;
+                    aName = SvGlobalName(rCLASSID);
                     break;
                 }
             }
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index 0a29e8bf9449..0fd65e17d8f2 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -24,6 +24,7 @@
 #include <mutex>
 #include <stack>
 #include <optional>
+#include <utility>
 
 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
 #include <tools/urlobj.hxx>
@@ -109,43 +110,25 @@ using namespace ::com::sun::star::xml::sax;
 using namespace ::com::sun::star::io;
 using namespace ::xmloff::token;
 
-#define XML_MODEL_SERVICE_WRITER    "com.sun.star.text.TextDocument"
-#define XML_MODEL_SERVICE_CALC      "com.sun.star.sheet.SpreadsheetDocument"
-#define XML_MODEL_SERVICE_DRAW      "com.sun.star.drawing.DrawingDocument"
-#define XML_MODEL_SERVICE_IMPRESS   
"com.sun.star.presentation.PresentationDocument"
-#define XML_MODEL_SERVICE_MATH      "com.sun.star.formula.FormulaProperties"
-#define XML_MODEL_SERVICE_CHART     "com.sun.star.chart.ChartDocument"
+constexpr OUStringLiteral XML_MODEL_SERVICE_WRITER = 
u"com.sun.star.text.TextDocument";
+constexpr OUStringLiteral XML_MODEL_SERVICE_CALC = 
u"com.sun.star.sheet.SpreadsheetDocument";
+constexpr OUStringLiteral XML_MODEL_SERVICE_DRAW = 
u"com.sun.star.drawing.DrawingDocument";
+constexpr OUStringLiteral XML_MODEL_SERVICE_IMPRESS = 
u"com.sun.star.presentation.PresentationDocument";
+constexpr OUStringLiteral XML_MODEL_SERVICE_MATH = 
u"com.sun.star.formula.FormulaProperties";
+constexpr OUStringLiteral XML_MODEL_SERVICE_CHART = 
u"com.sun.star.chart.ChartDocument";
 
 constexpr OUStringLiteral XML_USEPRETTYPRINTING = u"UsePrettyPrinting";
 
 constexpr OUStringLiteral XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE = 
u"vnd.sun.star.GraphicObject:";
 constexpr OUStringLiteral XML_EMBEDDEDOBJECT_URL_BASE = 
u"vnd.sun.star.EmbeddedObject:";
 
-namespace {
-
-struct XMLServiceMapEntry_Impl
-{
-    const char *sModelService;
-    sal_Int32   nModelServiceLen;
-    const char *sFilterService;
-    sal_Int32   nFilterServiceLen;
-};
-
-}
-
-#define SERVICE_MAP_ENTRY( app ) \
-    { XML_MODEL_SERVICE_##app, sizeof(XML_MODEL_SERVICE_##app)-1, \
-      XML_EXPORT_FILTER_##app, sizeof(XML_EXPORT_FILTER_##app)-1 }
-
-const XMLServiceMapEntry_Impl aServiceMap[] =
-{
-    SERVICE_MAP_ENTRY( WRITER ),
-    SERVICE_MAP_ENTRY( CALC ),
-    SERVICE_MAP_ENTRY( IMPRESS ),// Impress supports DrawingDocument, too, so
-    SERVICE_MAP_ENTRY( DRAW ),   // it must appear before Draw
-    SERVICE_MAP_ENTRY( MATH ),
-    SERVICE_MAP_ENTRY( CHART ),
-    { nullptr, 0, nullptr, 0 }
+const std::pair<OUString, OUString> aServiceMap[] = {
+    { XML_MODEL_SERVICE_WRITER, XML_EXPORT_FILTER_WRITER },
+    { XML_MODEL_SERVICE_CALC, XML_EXPORT_FILTER_CALC },
+    { XML_MODEL_SERVICE_IMPRESS, XML_EXPORT_FILTER_IMPRESS }, // Impress 
supports DrawingDocument,
+    { XML_MODEL_SERVICE_DRAW, XML_EXPORT_FILTER_DRAW }, // too, so it must 
appear before Draw
+    { XML_MODEL_SERVICE_MATH, XML_EXPORT_FILTER_MATH },
+    { XML_MODEL_SERVICE_CHART, XML_EXPORT_FILTER_CHART },
 };
 
 namespace {
@@ -2043,20 +2026,13 @@ void SvXMLExport::ExportEmbeddedOwnObject( Reference< 
XComponent > const & rComp
     Reference < lang::XServiceInfo > xServiceInfo( rComp, UNO_QUERY );
     if( xServiceInfo.is() )
     {
-        const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
-        while( pEntry->sModelService )
+        for (const auto& [sModelService, sMatchingFilterService] : aServiceMap)
         {
-            OUString sModelService( pEntry->sModelService,
-                                    pEntry->nModelServiceLen,
-                                       RTL_TEXTENCODING_ASCII_US );
             if( xServiceInfo->supportsService( sModelService ) )
             {
-                sFilterService = OUString( pEntry->sFilterService,
-                                           pEntry->nFilterServiceLen,
-                                              RTL_TEXTENCODING_ASCII_US );
+                sFilterService = sMatchingFilterService;
                 break;
             }
-            pEntry++;
         }
     }
 

Reply via email to