[Libreoffice-commits] core.git: dbaccess/source include/xmloff sc/source starmath/source svx/source sw/source xmloff/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 29 17:36:29 UTC 2020


 dbaccess/source/filter/xml/xmlTableFilterList.cxx |    4 +-
 include/xmloff/xmlimp.hxx                         |   41 +++++++++++++---------
 sc/source/filter/xml/xmlbodyi.cxx                 |    2 -
 starmath/source/mathmlimport.cxx                  |    2 -
 svx/source/xml/xmlxtimp.cxx                       |   16 +++-----
 sw/source/core/swg/SwXMLSectionList.cxx           |    4 +-
 xmloff/source/draw/animationimport.cxx            |   12 +++---
 xmloff/source/draw/ximppage.cxx                   |    2 -
 xmloff/source/meta/xmlmetai.cxx                   |    2 -
 xmloff/source/script/xmlbasicscript.cxx           |    6 +--
 10 files changed, 50 insertions(+), 41 deletions(-)

New commits:
commit 3e9bef4b6ef2e1b467b46f5579b5fce201015d83
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Apr 28 16:16:34 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Apr 29 19:35:52 2020 +0200

    simplify handling of comparing XML_NAMESPACE values
    
    Change-Id: I18bbf1ee206285842250891ce556d523489855b1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93075
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/dbaccess/source/filter/xml/xmlTableFilterList.cxx b/dbaccess/source/filter/xml/xmlTableFilterList.cxx
index e147bd10a548..ddd799087a48 100644
--- a/dbaccess/source/filter/xml/xmlTableFilterList.cxx
+++ b/dbaccess/source/filter/xml/xmlTableFilterList.cxx
@@ -51,8 +51,8 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLTableFilterList::c
 {
     SvXMLImportContext *pContext = nullptr;
 
-    if ( (nElement & NMSP_MASK) == NAMESPACE_TOKEN(XML_NAMESPACE_DB) ||
-         (nElement & NMSP_MASK) == NAMESPACE_TOKEN(XML_NAMESPACE_DB_OASIS) )
+    if ( IsTokenInNamespace(nElement, XML_NAMESPACE_DB) ||
+         IsTokenInNamespace(nElement, XML_NAMESPACE_DB_OASIS) )
     {
         GetImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
         switch (nElement & TOKEN_MASK)
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 19bb0b7b5358..9b9052e46f1a 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -59,24 +59,23 @@ namespace com { namespace sun { namespace star { namespace util { class XNumberF
 namespace com { namespace sun { namespace star { namespace xml { namespace sax { class XAttributeList; } } } } }
 namespace com { namespace sun { namespace star { namespace xml { namespace sax { class XFastAttributeList; } } } } }
 namespace com { namespace sun { namespace star { namespace xml { namespace sax { class XFastContextHandler; } } } } }
-namespace comphelper { class AttributeList; }
-
-class ProgressBarHelper;
-
-#define NAMESPACE_TOKEN( prefixToken ) ( ( sal_Int32( prefixToken + 1 ) ) << NMSP_SHIFT )
-#define XML_ELEMENT( prefix, name ) ( NAMESPACE_TOKEN( XML_NAMESPACE_##prefix ) | name )
-
-const size_t NMSP_SHIFT = 16;
-const sal_Int32 TOKEN_MASK = 0xffff;
-const sal_Int32 NMSP_MASK = 0xffff0000;
-
 namespace com { namespace sun { namespace star {
     namespace frame { class XModel; }
     namespace io { class XOutputStream; }
     namespace rdf { class XMetadatable; }
 } } }
+
 namespace comphelper { class UnoInterfaceToUniqueIdentifierMapper; }
+namespace comphelper { class AttributeList; }
+
+namespace xmloff {
+    class RDFaImportHelper;
+}
+namespace xmloff::token {
+    class FastTokenHandler;
+}
 
+class ProgressBarHelper;
 class SvXMLNamespaceMap;
 class SvXMLImport_Impl;
 class SvXMLUnitConverter;
@@ -87,13 +86,25 @@ class XMLErrors;
 class StyleMap;
 enum class SvXMLErrorFlags;
 
-namespace xmloff {
-    class RDFaImportHelper;
+constexpr sal_Int32 LAST_NAMESPACE = 121; // last value in xmloff/xmnspe.hxx
+constexpr size_t NMSP_SHIFT = 16;
+constexpr sal_Int32 TOKEN_MASK = 0xffff;
+constexpr sal_Int32 NMSP_MASK = 0xffff0000;
+
+#define XML_ELEMENT( prefix, name ) ( NAMESPACE_TOKEN(XML_NAMESPACE_##prefix) | name )
+
+constexpr sal_Int32 NAMESPACE_TOKEN( sal_uInt16 prefixToken )
+{
+    return ( prefixToken + 1 ) << NMSP_SHIFT;
 }
-namespace xmloff::token {
-    class FastTokenHandler;
+
+constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
+{
+    auto nTmp = ((nToken & NMSP_MASK) >> NMSP_SHIFT) - 1;
+    return nTmp == nNamespacePrefix;
 }
 
+
 enum class SvXMLImportFlags {
     NONE            = 0x0000,
     META            = 0x0001,
diff --git a/sc/source/filter/xml/xmlbodyi.cxx b/sc/source/filter/xml/xmlbodyi.cxx
index 0dd1c421d23d..b1c687d0befa 100644
--- a/sc/source/filter/xml/xmlbodyi.cxx
+++ b/sc/source/filter/xml/xmlbodyi.cxx
@@ -95,7 +95,7 @@ ScXMLBodyContext::ScXMLBodyContext( ScXMLImport& rImport,
     for (auto &it : *rAttrList)
     {
         sal_Int32 nToken = it.getToken();
-        if( NAMESPACE_TOKEN( XML_NAMESPACE_TABLE ) == ( nToken & NMSP_MASK ) )
+        if( IsTokenInNamespace(nToken, XML_NAMESPACE_TABLE) )
         {
             const sal_Int32 nLocalToken = nToken & TOKEN_MASK;
             if( nLocalToken == XML_STRUCTURE_PROTECTED )
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index a4ef90a47504..e0dab47598b9 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -2614,7 +2614,7 @@ SvXMLImportContext *SmXMLImport::CreateFastContext(sal_Int32 nElement,
         }
         break;
         default:
-            if ((nElement & NMSP_MASK) == NAMESPACE_TOKEN(XML_NAMESPACE_OFFICE))
+            if (IsTokenInNamespace(nElement, XML_NAMESPACE_OFFICE))
                 pContext = new SmXMLOfficeContext_Impl(*this);
             else
                 pContext = new SmXMLDocContext_Impl(*this);
diff --git a/svx/source/xml/xmlxtimp.cxx b/svx/source/xml/xmlxtimp.cxx
index ea32ca9c380c..7c0a238dcebc 100644
--- a/svx/source/xml/xmlxtimp.cxx
+++ b/svx/source/xml/xmlxtimp.cxx
@@ -101,9 +101,8 @@ css::uno::Reference< css::xml::sax::XFastContextHandler >
         SvxXMLTableImportContext::createFastChildContext(sal_Int32 nElement,
             const css::uno::Reference< css::xml::sax::XFastAttributeList > & rAttrList)
 {
-    sal_Int32 nNamespace = nElement & NMSP_MASK;
-    if( NAMESPACE_TOKEN(XML_NAMESPACE_DRAW) == nNamespace ||
-        NAMESPACE_TOKEN(XML_NAMESPACE_DRAW_OOO) == nNamespace )
+    if( IsTokenInNamespace(nElement, XML_NAMESPACE_DRAW) ||
+        IsTokenInNamespace(nElement, XML_NAMESPACE_DRAW_OOO) )
     {
         SvXMLAttributeList *pAttrList = new SvXMLAttributeList;
         for (auto& aIter : sax_fastparser::castToFastAttributeList( rAttrList ))
@@ -428,13 +427,12 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer,
 SvXMLImportContext *SvxXMLXTableImport::CreateFastContext( sal_Int32 nElement,
         const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
 {
-    sal_Int32 nNamespace = nElement & NMSP_MASK;
-    if( NAMESPACE_TOKEN(XML_NAMESPACE_OOO) == nNamespace ||
-        NAMESPACE_TOKEN(XML_NAMESPACE_OFFICE) == nNamespace ||
-        NAMESPACE_TOKEN(XML_NAMESPACE_OFFICE_OOO) == nNamespace )
+    if( IsTokenInNamespace(nElement, XML_NAMESPACE_OOO) ||
+        IsTokenInNamespace(nElement, XML_NAMESPACE_OFFICE) ||
+        IsTokenInNamespace(nElement, XML_NAMESPACE_OFFICE_OOO) )
     {
-        bool bOOoFormat = (NAMESPACE_TOKEN(XML_NAMESPACE_OFFICE) == nNamespace) ||
-                          (NAMESPACE_TOKEN(XML_NAMESPACE_OFFICE_OOO) == nNamespace);
+        bool bOOoFormat = IsTokenInNamespace(nElement, XML_NAMESPACE_OFFICE) ||
+                          IsTokenInNamespace(nElement, XML_NAMESPACE_OFFICE_OOO);
         Type aType = mrTable->getElementType();
         sal_Int32 nToken = nElement & TOKEN_MASK;
 
diff --git a/sw/source/core/swg/SwXMLSectionList.cxx b/sw/source/core/swg/SwXMLSectionList.cxx
index 13282cf12aac..aa6c63b8bb29 100644
--- a/sw/source/core/swg/SwXMLSectionList.cxx
+++ b/sw/source/core/swg/SwXMLSectionList.cxx
@@ -66,8 +66,8 @@ public:
         {
             return new SvXMLSectionListContext(GetImport());
         }
-        if ((Element & NMSP_MASK) == NAMESPACE_TOKEN(XML_NAMESPACE_TEXT) ||
-            (Element & NMSP_MASK) == NAMESPACE_TOKEN(XML_NAMESPACE_TEXT_OOO))
+        if (IsTokenInNamespace(Element, XML_NAMESPACE_TEXT) ||
+            IsTokenInNamespace(Element, XML_NAMESPACE_TEXT_OOO))
         {
             auto nToken = Element & TOKEN_MASK;
             if (nToken == XML_P ||
diff --git a/xmloff/source/draw/animationimport.cxx b/xmloff/source/draw/animationimport.cxx
index cfbfee630261..ebccff3d1a22 100644
--- a/xmloff/source/draw/animationimport.cxx
+++ b/xmloff/source/draw/animationimport.cxx
@@ -562,7 +562,8 @@ void AnimationNodeContext::init_node(  const css::uno::Reference< css::xml::sax:
         for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
         {
             OUString rValue = aIter.toString();
-            switch( aIter.getToken() )
+            auto nToken = aIter.getToken();
+            switch( nToken )
             {
             case XML_ELEMENT(SMIL, XML_BEGIN):
             case XML_ELEMENT(SMIL_COMPAT, XML_BEGIN):
@@ -1077,12 +1078,11 @@ void AnimationNodeContext::init_node(  const css::uno::Reference< css::xml::sax:
 
             default:
             {
-                auto nNamespace = (aIter.getToken() & NMSP_MASK);
                 // push all unknown attributes within the presentation namespace as user data
-                if (nNamespace == NAMESPACE_TOKEN(XML_NAMESPACE_PRESENTATION)
-                    || nNamespace == NAMESPACE_TOKEN(XML_NAMESPACE_PRESENTATION_SO52)
-                    || nNamespace == NAMESPACE_TOKEN(XML_NAMESPACE_PRESENTATION_OASIS)
-                    || nNamespace == NAMESPACE_TOKEN(XML_NAMESPACE_PRESENTATION_OOO))
+                if (IsTokenInNamespace(nToken, XML_NAMESPACE_PRESENTATION)
+                    || IsTokenInNamespace(nToken, XML_NAMESPACE_PRESENTATION_SO52)
+                    || IsTokenInNamespace(nToken, XML_NAMESPACE_PRESENTATION_OASIS)
+                    || IsTokenInNamespace(nToken, XML_NAMESPACE_PRESENTATION_OOO))
                 {
                     aUserData.emplace_back( SvXMLImport::getNameFromToken(aIter.getToken()), makeAny( rValue ) );
                 }
diff --git a/xmloff/source/draw/ximppage.cxx b/xmloff/source/draw/ximppage.cxx
index 23a89e943f2d..e803eda3a8f5 100644
--- a/xmloff/source/draw/ximppage.cxx
+++ b/xmloff/source/draw/ximppage.cxx
@@ -144,7 +144,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > DrawAnnotationContext:
 {
     if( mxAnnotation.is() )
     {
-        if ((nElement & NMSP_MASK) == NAMESPACE_TOKEN(XML_NAMESPACE_DC))
+        if (IsTokenInNamespace(nElement, XML_NAMESPACE_DC))
         {
             if( (nElement & TOKEN_MASK) == XML_CREATOR )
                 return new XMLStringBufferImportContext(GetImport(), maAuthorBuffer);
diff --git a/xmloff/source/meta/xmlmetai.cxx b/xmloff/source/meta/xmlmetai.cxx
index 715bd0ba052b..20fcfb38cdf9 100644
--- a/xmloff/source/meta/xmlmetai.cxx
+++ b/xmloff/source/meta/xmlmetai.cxx
@@ -216,7 +216,7 @@ void SAL_CALL SvXMLMetaDocumentContext::characters( const OUString& /*rChars*/ )
 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLMetaDocumentContext::createFastChildContext(
     sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
 {
-    if ( nElement == ( NAMESPACE_TOKEN( XML_NAMESPACE_OFFICE ) | XML_META ) )
+    if ( nElement == XML_ELEMENT(OFFICE, XML_META) )
         return new XMLDocumentBuilderContext(
                 GetImport(), nElement, xAttrList, mxDocBuilder);
     return nullptr;
diff --git a/xmloff/source/script/xmlbasicscript.cxx b/xmloff/source/script/xmlbasicscript.cxx
index 3c1ea97dbccb..efc655eca682 100644
--- a/xmloff/source/script/xmlbasicscript.cxx
+++ b/xmloff/source/script/xmlbasicscript.cxx
@@ -109,7 +109,7 @@ Reference<XFastContextHandler>
 BasicLibrariesElement::createFastChildContext(sal_Int32 nElement,
                                               const Reference<XFastAttributeList>& xAttributes)
 {
-    if ((nElement & NMSP_MASK) != NAMESPACE_TOKEN(XML_NAMESPACE_OOO))
+    if (!IsTokenInNamespace(nElement, XML_NAMESPACE_OOO))
     {
         throw xml::sax::SAXException("illegal namespace!", Reference<XInterface>(), Any());
     }
@@ -211,7 +211,7 @@ BasicEmbeddedLibraryElement::BasicEmbeddedLibraryElement(
 Reference<XFastContextHandler> BasicEmbeddedLibraryElement::createFastChildContext(
     sal_Int32 nElement, const Reference<XFastAttributeList>& xAttributes)
 {
-    if ((nElement & NMSP_MASK) != NAMESPACE_TOKEN(XML_NAMESPACE_OOO))
+    if (!IsTokenInNamespace(nElement, XML_NAMESPACE_OOO))
     {
         throw xml::sax::SAXException("illegal namespace!", Reference<XInterface>(), Any());
     }
@@ -253,7 +253,7 @@ BasicModuleElement::createFastChildContext(sal_Int32 nElement,
 {
     // TODO: <byte-code>
 
-    if ((nElement & NMSP_MASK) != NAMESPACE_TOKEN(XML_NAMESPACE_OOO))
+    if (!IsTokenInNamespace(nElement, XML_NAMESPACE_OOO))
     {
         throw xml::sax::SAXException("illegal namespace!", Reference<XInterface>(), Any());
     }


More information about the Libreoffice-commits mailing list