author | František Kučera <franta-hg@frantovo.cz> |
Wed, 30 Oct 2019 16:47:42 +0100 | |
branch | v_0 |
changeset 12 | 371186f1d676 |
parent 11 | 56c84049698d |
permissions | -rw-r--r-- |
1 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
11
56c84049698d
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
1 | 8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#pragma once |
|
18 |
||
19 |
#include <iostream> |
|
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
20 |
#include <sstream> |
1 | 21 |
#include <string> |
22 |
#include <vector> |
|
23 |
#include <codecvt> |
|
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
24 |
#include <locale> |
1 | 25 |
|
26 |
#include "RelpipeXMLWriterException.h" |
|
27 |
||
28 |
using namespace std; |
|
29 |
||
30 |
namespace relpipe { |
|
31 |
namespace xmlwriter { |
|
32 |
||
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
33 |
/** |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
34 |
* A simple library for writing XML streams. |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
35 |
* |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
36 |
* Does: |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
37 |
* - convert wstring values to UTF-8 |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
38 |
* - escape values of text nodes and attributes |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
39 |
* - indent elements |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
40 |
* - preserve whitespace of text nodes |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
41 |
* - in comments: replace - with – |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
42 |
* Does not: |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
43 |
* - understand XML namespaces: |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
44 |
* - handles xmlns:x="y" as ordinary attributes |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
45 |
* - thus can not check whether elements/attributes belong to an declared namespace |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
46 |
* - thus can generate invalid XML – namespaces and their prefixes must be checked on the caller side |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
47 |
*/ |
1 | 48 |
class XMLWriter { |
49 |
private: |
|
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
50 |
const char* INDENT = "\t"; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
51 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
52 |
ostream& output; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
53 |
wstring_convert<codecvt_utf8<wchar_t>> convertor; // XML output will be always in UTF-8 |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
54 |
vector<wstring> treePosition; |
3 | 55 |
bool lastWasTextNode = false; |
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
56 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
57 |
const string escapeXmlText(const wstring& value) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
58 |
// TODO: really bad performance → rewrite |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
59 |
// 72 % of whole relpipe-out-xml according to valgrind/callgrind |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
60 |
// Moved here from XmlHandler.h (relpipe-out-xml). |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
61 |
std::wstringstream result; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
62 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
63 |
for (auto & ch : value) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
64 |
switch (ch) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
65 |
case L'&': result << L"&"; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
66 |
break; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
67 |
case L'<': result << L"<"; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
68 |
break; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
69 |
case L'>': result << L">"; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
70 |
break; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
71 |
case L'\'': result << L"'"; // TODO: escape ' and " only in attributes |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
72 |
break; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
73 |
case L'"': result << L"""; // TODO: escape ' and " only in attributes |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
74 |
break; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
75 |
default: result << ch; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
76 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
77 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
78 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
79 |
return convertor.to_bytes(result.str()); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
80 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
81 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
82 |
const string escapeXmlAttribute(const wstring& value) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
83 |
// TODO: escaping of ' is not necessary. |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
84 |
return escapeXmlText(value); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
85 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
86 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
87 |
const string escapeComment(const wstring& value) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
88 |
// TODO: really bad performance → rewrite |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
89 |
// 72 % of whole relpipe-out-xml according to valgrind/callgrind |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
90 |
std::wstringstream result; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
91 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
92 |
for (auto & ch : value) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
93 |
switch (ch) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
94 |
case L'-': result << L"–"; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
95 |
break; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
96 |
default: result << ch; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
97 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
98 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
99 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
100 |
return convertor.to_bytes(result.str()); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
101 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
102 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
103 |
void checkName(const wstring& name) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
104 |
// FIXME: throw exception on invalid names |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
105 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
106 |
|
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
107 |
void writeAttributes(const vector<wstring>& attributes) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
108 |
if (attributes.size() % 2) throw RelpipeXMLWriterException(L"attributes vector must contain name/value pairs (even number of elements)"); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
109 |
for (int i = 0; i < attributes.size(); i = i + 2) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
110 |
wstring name = attributes[i]; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
111 |
wstring value = attributes[i + 1]; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
112 |
checkName(name); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
113 |
output << " " << convertor.to_bytes(name) << "=\"" << escapeXmlAttribute(value) << "\""; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
114 |
} |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
115 |
} |
1 | 116 |
|
3 | 117 |
void writeIndentation(bool resetState = true) { |
118 |
if (lastWasTextNode) { |
|
119 |
if (resetState) lastWasTextNode = false; |
|
120 |
} else { |
|
121 |
output << endl; |
|
122 |
for (int i = 0; i < treePosition.size(); i++) { |
|
123 |
output << INDENT; |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
||
1 | 128 |
public: |
129 |
||
130 |
XMLWriter(std::ostream& output) : output(output) { |
|
3 | 131 |
output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
1 | 132 |
} |
133 |
||
134 |
virtual ~XMLWriter() { |
|
3 | 135 |
output << endl; |
1 | 136 |
output.flush(); |
137 |
} |
|
138 |
||
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
139 |
void writeStartElement(const wstring& name, const vector<wstring>& attributes = {}) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
140 |
checkName(name); |
3 | 141 |
writeIndentation(); |
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
142 |
treePosition.push_back(name); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
143 |
output << "<" << convertor.to_bytes(name); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
144 |
writeAttributes(attributes); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
145 |
output << ">"; |
1 | 146 |
} |
147 |
||
148 |
void writeEndElement() { |
|
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
149 |
if (treePosition.empty()) throw RelpipeXMLWriterException(L"unable to close element – all elements are already closed"); |
3 | 150 |
wstring name = treePosition.back(); |
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
151 |
treePosition.pop_back(); |
3 | 152 |
writeIndentation(); |
153 |
output << "</" << convertor.to_bytes(name) << ">"; |
|
1 | 154 |
} |
155 |
||
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
156 |
void writeEmptyElement(const wstring& name, const vector<wstring>& attributes = {}) { |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
157 |
checkName(name); |
3 | 158 |
writeIndentation(); |
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
159 |
output << "<" << convertor.to_bytes(name); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
160 |
writeAttributes(attributes); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
161 |
output << "/>"; |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
162 |
|
1 | 163 |
} |
164 |
||
165 |
void writeTextElement(const wstring& name, const vector<wstring>& attributes, const wstring& text) { |
|
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
166 |
writeStartElement(name, attributes); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
167 |
writeCharacters(text); |
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
168 |
writeEndElement(); |
1 | 169 |
} |
170 |
||
171 |
void writeCharacters(const wstring& text) { |
|
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
172 |
output << escapeXmlText(text); |
3 | 173 |
lastWasTextNode = true; |
1 | 174 |
} |
175 |
||
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
176 |
void writeComment(const wstring& text, bool addSpaces = true) { |
3 | 177 |
writeIndentation(false); |
178 |
output << (addSpaces ? "<!-- " : "<!--"); |
|
2
f21d6ae71bf0
move common XML code to relpipe-lib-xmlwriter (a header-only library)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
179 |
output << escapeComment(text); |
3 | 180 |
output << (addSpaces ? " -->" : "-->"); |
1 | 181 |
} |
182 |
||
183 |
}; |
|
184 |
||
185 |
} |
|
186 |
} |