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>
This commit is contained in:
@@ -17804,7 +17804,6 @@ writerfilter/source/ooxml/OOXMLPropertySet.cxx
|
||||
writerfilter/source/ooxml/OOXMLPropertySet.hxx
|
||||
writerfilter/source/ooxml/OOXMLStreamImpl.cxx
|
||||
writerfilter/source/ooxml/OOXMLStreamImpl.hxx
|
||||
writerfilter/source/ooxml/qnametostrcore.cxx
|
||||
xmlhelp/source/cxxhelp/inc/tvfactory.hxx
|
||||
xmlhelp/source/cxxhelp/inc/tvread.hxx
|
||||
xmlhelp/source/cxxhelp/provider/content.cxx
|
||||
|
||||
@@ -123,7 +123,6 @@ $(eval $(call gb_Library_add_exception_objects,writerfilter,\
|
||||
writerfilter/source/ooxml/OOXMLParserState \
|
||||
writerfilter/source/ooxml/OOXMLPropertySet \
|
||||
writerfilter/source/ooxml/OOXMLStreamImpl \
|
||||
writerfilter/source/ooxml/qnametostrcore \
|
||||
))
|
||||
|
||||
$(eval $(call gb_Library_add_generated_exception_objects,writerfilter,\
|
||||
|
||||
@@ -19,34 +19,15 @@
|
||||
#ifndef INCLUDED_WRITERFILTER_INC_OOXML_QNAMETOSTRING_HXX
|
||||
#define INCLUDED_WRITERFILTER_INC_OOXML_QNAMETOSTRING_HXX
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <dmapper/resourcemodel.hxx>
|
||||
|
||||
namespace writerfilter
|
||||
{
|
||||
|
||||
class QNameToString final : public virtual SvRefBase
|
||||
{
|
||||
typedef tools::SvRef<QNameToString> Pointer_t;
|
||||
typedef std::map < Id, std::string > Map;
|
||||
|
||||
static Pointer_t pInstance;
|
||||
|
||||
void init();
|
||||
|
||||
Map mMap;
|
||||
|
||||
/**
|
||||
Generated.
|
||||
*/
|
||||
QNameToString();
|
||||
|
||||
public:
|
||||
static Pointer_t const & Instance();
|
||||
|
||||
std::string operator()(Id qName);
|
||||
};
|
||||
#ifdef DBG_UTIL
|
||||
std::string QNameToString(Id);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ void LoggedStream::table(Id name, writerfilter::Reference<Table>::Pointer_t ref)
|
||||
{
|
||||
#ifdef DBG_UTIL
|
||||
mHelper.startElement("table");
|
||||
LoggedResourcesHelper::attribute("name", (*QNameToString::Instance())(name));
|
||||
LoggedResourcesHelper::attribute("name", QNameToString(name));
|
||||
#endif
|
||||
|
||||
lcl_table(name, ref);
|
||||
@@ -272,7 +272,7 @@ void LoggedStream::substream(Id name, writerfilter::Reference<Stream>::Pointer_t
|
||||
{
|
||||
#ifdef DBG_UTIL
|
||||
mHelper.startElement("substream");
|
||||
LoggedResourcesHelper::attribute("name", (*QNameToString::Instance())(name));
|
||||
LoggedResourcesHelper::attribute("name", QNameToString(name));
|
||||
#endif
|
||||
|
||||
lcl_substream(name, ref);
|
||||
@@ -341,7 +341,7 @@ void LoggedProperties::attribute(Id name, Value & val)
|
||||
{
|
||||
#ifdef DBG_UTIL
|
||||
mHelper.startElement("attribute");
|
||||
LoggedResourcesHelper::attribute("name", (*QNameToString::Instance())(name));
|
||||
LoggedResourcesHelper::attribute("name", QNameToString(name));
|
||||
LoggedResourcesHelper::attribute("value", val.toString());
|
||||
LoggedResourcesHelper::endElement();
|
||||
#endif
|
||||
@@ -353,7 +353,7 @@ void LoggedProperties::sprm(Sprm & rSprm)
|
||||
{
|
||||
#ifdef DBG_UTIL
|
||||
mHelper.startElement("sprm");
|
||||
LoggedResourcesHelper::attribute("name", (*QNameToString::Instance())(rSprm.getId()));
|
||||
LoggedResourcesHelper::attribute("name", QNameToString(rSprm.getId()));
|
||||
LoggedResourcesHelper::chars(rSprm.toString());
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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: */
|
||||
@@ -40,7 +40,7 @@ std::string RTFSprm::toString() const
|
||||
{
|
||||
OStringBuffer aBuf("RTFSprm");
|
||||
|
||||
std::string sResult = (*QNameToString::Instance())(m_nKeyword);
|
||||
std::string sResult = QNameToString(m_nKeyword);
|
||||
|
||||
aBuf.append(" ('");
|
||||
if (sResult.length() == 0)
|
||||
|
||||
Reference in New Issue
Block a user