LibreOffice Module oox (master) 1
importutils.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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#ifndef INCLUDED_OOX_MATHML_IMPORTUTILS_HXX
10#define INCLUDED_OOX_MATHML_IMPORTUTILS_HXX
11
12#include <map>
13#include <string_view>
14#include <vector>
15
16#include <com/sun/star/uno/Reference.hxx>
17#include <oox/dllapi.h>
18#include <oox/token/tokens.hxx>
19#include <rtl/ustring.hxx>
20#include <sal/types.h>
21
22namespace com::sun::star
23{
24namespace xml::sax
25{
26class XFastAttributeList;
27}
28}
29
30namespace oox::formulaimport
31{
32// used to differentiate between tags that opening or closing
33const int TAG_OPENING = 1 << 29;
34const int TAG_CLOSING = 1 << 30;
35
36// you probably want to #define these to something shorter in the .cxx file,
37// but they must be done as macros, otherwise they wouldn't be usable for case values,
38// and macros cannot be namespaced
39#define XML_STREAM_OPENING(token) (TAG_OPENING | token)
40#define XML_STREAM_CLOSING(token) (TAG_CLOSING | token)
41
112{
113public:
114 XmlStream();
118 // One could theoretically use oox::AttributeList, but that complains if the passed reference is empty,
119 // which would be complicated to avoid here. Also, parsers apparently reuse the same instance of XFastAttributeList,
120 // which means using oox::AttributeList would make them all point to the one instance.
122 {
123 OUString& operator[](int token);
124 OUString attribute(int token, const OUString& def) const;
125 bool attribute(int token, bool def) const;
126 sal_Unicode attribute(int token, sal_Unicode def) const;
127 // when adding more attribute() overloads, add also to XmlStream itself
128 protected:
129 std::map<int, OUString> attrs;
130 };
135 {
136 Tag(int token = XML_TOKEN_INVALID,
137 const css::uno::Reference<css::xml::sax::XFastAttributeList>& attributes
138 = css::uno::Reference<css::xml::sax::XFastAttributeList>());
139 Tag(int token, AttributeList attribs);
140 int token;
142 OUString text;
147 OUString attribute(int token, const OUString& def = OUString()) const;
151 bool attribute(int token, bool def) const;
155 sal_Unicode attribute(int token, sal_Unicode def) const;
156 // when adding more attribute() overloads, add also to XmlStream::AttributeList and inline below
161 operator bool() const;
162 };
166 bool atEnd() const;
170 Tag currentTag() const;
174 int currentToken() const;
178 void moveToNextTag();
185 Tag ensureOpeningTag(int token);
192 Tag checkOpeningTag(int token);
198 void ensureClosingTag(int token);
203 bool findTag(int token);
207 void handleUnexpectedTag();
208
209protected:
210 Tag checkTag(int token, bool optional);
211 bool findTagInternal(int token, bool silent);
212 void skipElementInternal(int token, bool silent);
213 std::vector<Tag> tags;
214 unsigned int pos;
215};
216
225{
226public:
227 void appendOpeningTag(int token,
228 const css::uno::Reference<css::xml::sax::XFastAttributeList>& attributes
229 = css::uno::Reference<css::xml::sax::XFastAttributeList>());
230 void appendOpeningTag(int token, const AttributeList& attribs);
231 void appendClosingTag(int token);
232 // appends the characters after the last appended token
233 void appendCharacters(std::u16string_view characters);
234};
235
236inline OUString XmlStream::Tag::attribute(int t, const OUString& def) const
237{
238 return attributes.attribute(t, def);
239}
240
241inline bool XmlStream::Tag::attribute(int t, bool def) const
242{
243 return attributes.attribute(t, def);
244}
245
247{
248 return attributes.attribute(t, def);
249}
250
251} // namespace
252
253#endif
254
255/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
This class is used for creating XmlStream.
void appendOpeningTag(int token, const css::uno::Reference< css::xml::sax::XFastAttributeList > &attributes=css::uno::Reference< css::xml::sax::XFastAttributeList >())
Class for storing a stream of xml tokens.
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
const int TAG_OPENING
Definition: importutils.hxx:33
const int TAG_CLOSING
Definition: importutils.hxx:34
sal_Int32 attribute
Structure representing a list of attributes.
OUString attribute(int token, const OUString &def) const
Definition: importutils.cxx:94
Structure representing a tag, including its attributes and content text immediately following it.
Tag(int token=XML_TOKEN_INVALID, const css::uno::Reference< css::xml::sax::XFastAttributeList > &attributes=css::uno::Reference< css::xml::sax::XFastAttributeList >())
int token
tag type, or XML_TOKEN_INVALID
OUString attribute(int token, const OUString &def=OUString()) const
This function returns value of the given attribute, or the passed default value if not found.
sal_uInt16 sal_Unicode