sptk2 logo
SPTK Home Page
ImportXML.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/Buffer.h>
30#include <sptk5/RegularExpression.h>
31#include <sptk5/xdoc/Node.h>
32#include <sptk5/xdoc/XMLDocType.h>
33
34#include <map>
35#include <string>
36
37namespace sptk::xdoc {
38
50class SP_EXPORT ImportXML
51{
52public:
53 enum class Mode : uint8_t
54 {
55 Compact,
56 KeepFormatting
57 };
58
62 ImportXML() = default;
63
64 virtual ~ImportXML() = default;
65
70 {
71 return m_doctype;
72 }
73
79 [[maybe_unused]] void indentSpaces(int i)
80 {
81 }
82
87 void parse(const SNode& node, const char* _buffer, Mode formatting = Mode::Compact);
88
89private:
90 XMLDocType m_doctype;
91 Buffer m_encodeBuffer;
92 Buffer m_decodeBuffer;
93
97 void processAttributes(Node& node, const char* ptr);
98
99 static char* readComment(const SNode& currentNode, char* nodeName, char* nodeEnd, char* tokenEnd);
100
101 static char* readCDataSection(const SNode& currentNode, char* nodeName, char* nodeEnd, char* tokenEnd,
102 Mode formatting);
103
104 static char* readXMLDocType(char* tokenEnd);
105
106 static const RegularExpression parseAttributes;
107
108 static char* readExclamationTag(const SNode& currentNode, char* nodeName, char* tokenEnd, char* nodeEnd, Mode formatting);
109
110 char* readProcessingInstructions(const SNode& currentNode, const char* nodeName, char* tokenEnd, char*& nodeEnd,
111 bool isRootNode);
112
113 char* readOpenningTag(SNode& currentNode, const char* nodeName, char* tokenEnd, char*& nodeEnd);
114
115 static char* readClosingTag(const SNode& currentNode, const char* nodeName, char* tokenEnd, char*& nodeEnd);
116
117 void readText(const SNode& currentNode, XMLDocType* doctype, const char* nodeStart, const char* textStart,
118 Mode formatting);
119
120 static SNode detectArray(const SNode& node);
121};
122
126} // namespace sptk::xdoc
Definition: Buffer.h:51
Definition: ImportXML.h:51
void indentSpaces(int i)
Definition: ImportXML.h:79
XMLDocType & docType()
Definition: ImportXML.h:69
void parse(const SNode &node, const char *_buffer, Mode formatting=Mode::Compact)
Mode
Definition: ImportXML.h:54
Definition: Node.h:48
Definition: XMLDocType.h:50

Fri Oct 14 2022 09:58:32: SPTK 5.4.1