diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-10 23:00:45 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-11 06:14:19 +0200 |
commit | 3e11faf2d263f97a96274a8247b5a123ec8fe7c6 (patch) | |
tree | 3168800d693fc5016a5dd7fbeba161268757c248 /xmloff/source | |
parent | 56883788d0090383dad58552f5a11044ffe64a44 (diff) |
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.kaganski@collabora.com>
Diffstat (limited to 'xmloff/source')
-rw-r--r-- | xmloff/source/core/XMLEmbeddedObjectImportContext.cxx | 41 | ||||
-rw-r--r-- | xmloff/source/core/xmlexp.cxx | 56 |
2 files changed, 30 insertions, 67 deletions
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++; } } |