summaryrefslogtreecommitdiff
path: root/writerfilter/source/ooxml
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-04-08 11:49:28 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-04-08 13:03:58 +0200
commit18e5d441ca3c3f0b59db8beaa87e3565489db6f1 (patch)
treef9b515737eede4fb47a569167c96563d27ed2ccb /writerfilter/source/ooxml
parent08a11f8fe19560b000c62da00d7425b4f500d605 (diff)
simplify QNameToString
no need for it to be a class, and no need for the data to be allocated at runtime Change-Id: I80bca34b2af221534eae5a6e90de369fa29037e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91878 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'writerfilter/source/ooxml')
-rw-r--r--writerfilter/source/ooxml/OOXMLPropertySet.cxx2
-rw-r--r--writerfilter/source/ooxml/qnametostr.py21
-rw-r--r--writerfilter/source/ooxml/qnametostrcore.cxx55
3 files changed, 17 insertions, 61 deletions
diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.cxx b/writerfilter/source/ooxml/OOXMLPropertySet.cxx
index 23a6e7861231..b8071011422b 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySet.cxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySet.cxx
@@ -70,7 +70,7 @@ writerfilter::Reference<Properties>::Pointer_t OOXMLProperty::getProps()
#ifdef DBG_UTIL
string OOXMLProperty::getName() const
{
- string sResult((*QNameToString::Instance())(mId));
+ string sResult(QNameToString(mId));
if (sResult.length() == 0)
sResult = fastTokenToId(mId);
diff --git a/writerfilter/source/ooxml/qnametostr.py b/writerfilter/source/ooxml/qnametostr.py
index 473efc096196..c7fdcc1180da 100644
--- a/writerfilter/source/ooxml/qnametostr.py
+++ b/writerfilter/source/ooxml/qnametostr.py
@@ -20,20 +20,31 @@ class ContentHandler(xml.sax.handler.ContentHandler):
print("""
#include "ooxml/resourceids.hxx"
#include "ooxml/QNameToString.hxx"
+#include "unordered_map"
namespace writerfilter
{
-void QNameToString::init()
-{
#ifdef DBG_UTIL
+
/* ooxml */
+ static const std::unordered_map<Id, const char*> g_QNameToStringMap {
""")
def endDocument(self):
- print("""#endif
-}
+ print("""
+ };
+
+ std::string QNameToString(Id qName)
+ {
+ auto it = g_QNameToStringMap.find(qName);
+ if (it == g_QNameToStringMap.end())
+ return std::string();
+
+ return it->second;
+ }
+#endif
}
""")
@@ -43,7 +54,7 @@ void QNameToString::init()
if v.startswith("ooxml:"):
token = v.replace('ooxml:', '')
if token not in self.tokens:
- print(""" mMap[NS_ooxml::LN_%s] = "ooxml:%s";""" % (token, token))
+ print(""" { NS_ooxml::LN_%s, "ooxml:%s" },""" % (token, token))
self.tokens.append(token)
diff --git a/writerfilter/source/ooxml/qnametostrcore.cxx b/writerfilter/source/ooxml/qnametostrcore.cxx
deleted file mode 100644
index 0794f5ca427e..000000000000
--- a/writerfilter/source/ooxml/qnametostrcore.cxx
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <ooxml/QNameToString.hxx>
-
-namespace writerfilter
-{
-
-QNameToString::Pointer_t QNameToString::pInstance;
-
-QNameToString::Pointer_t const & QNameToString::Instance()
-{
- if (pInstance.get() == nullptr)
- pInstance = QNameToString::Pointer_t(new QNameToString());
-
- return pInstance;
-}
-
-std::string QNameToString::operator()(Id qName)
-{
-#ifdef DBG_UTIL
- Map::const_iterator aIt = mMap.find(qName);
-
- if (aIt != mMap.end())
- return aIt->second;
-#else
- (void) qName;
-#endif
- return std::string();
-}
-
-QNameToString::QNameToString()
-{
- init();
-}
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */