LibreOffice Module writerfilter (master) 1
qnametostr.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#
3# This file is part of the LibreOffice project.
4#
5# This Source Code Form is subject to the terms of the Mozilla Public
6# License, v. 2.0. If a copy of the MPL was not distributed with this
7# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8#
9
10import xml.sax
11import sys
12
13
14class ContentHandler(xml.sax.handler.ContentHandler):
15 def __init__(self):
16 self.tokens = []
17
18 def startDocument(self):
19 print("""
20#include "ooxml/resourceids.hxx"
21#include "ooxml/QNameToString.hxx"
22#include "unordered_map"
23
24namespace writerfilter
25{
26
27#ifdef DBG_UTIL
28
29 /* ooxml */
30 static const std::unordered_map<Id, const char*> g_QNameToStringMap {
31""")
32
33 def endDocument(self):
34 print("""
35 };
36
37 std::string QNameToString(Id qName)
38 {
39 auto it = g_QNameToStringMap.find(qName);
40 if (it == g_QNameToStringMap.end())
41 return std::string();
42
43 return it->second;
44 }
45
46#endif
47}
48""")
49
50 def startElement(self, name, attrs):
51 for k, v in list(attrs.items()):
52 if k == "tokenid":
53 if v.startswith("ooxml:"):
54 token = v.replace('ooxml:', '')
55 if token not in self.tokens:
56 print(""" { NS_ooxml::LN_%s, "ooxml:%s" },""" % (token, token))
57 self.tokens.append(token)
58
59
60parser = xml.sax.make_parser()
61parser.setContentHandler(ContentHandler())
62parser.parse(sys.argv[1])
63
64# vim:set shiftwidth=4 softtabstop=4 expandtab:
def startElement(self, name, attrs)
Definition: qnametostr.py:50
std::string QNameToString(Id)