1#ifndef XMLOUTPUTSTREAM_HH
2#define XMLOUTPUTSTREAM_HH
71template<
typename Operations>
78 void begin(std::string_view tag);
79 void attribute(std::string_view name, std::string_view value);
80 void data(std::string_view value);
81 void end(std::string_view tag);
84 void writeSpaces(
unsigned n);
85 void writeChar(
char c);
86 void writeString(std::string_view s);
87 void writeEscapedString(std::string_view s);
99 std::vector<std::string> stack;
104template<
typename Writer>
108 stack.emplace_back(tag);
110 ops.check(state != DATA);
111 if (state == CLOSE) {
114 writeSpaces(2 * level);
121template<
typename Writer>
124 ops.check(level > 0);
125 ops.check(state == CLOSE);
129 writeEscapedString(value);
133template<
typename Writer>
136 ops.check(level > 0);
137 ops.check(state == CLOSE);
139 if (value.empty())
return;
142 writeEscapedString(value);
146template<
typename Writer>
150 ops.check(stack.size() == level);
151 ops.check(!stack.empty());
152 ops.check(stack.back() == tag);
155 ops.check(level > 0);
157 if (state == CLOSE) {
160 if (state == INDENT) {
161 writeSpaces(2 * level);
170template<
typename Writer>
173 static constexpr std::array<char, 64>
spaces = {
174 ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
175 ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
176 ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
177 ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
186template<
typename Writer>
192template<
typename Writer>
198template<
typename Writer>
201 XMLEscape(s, [&](std::string_view chunk) { writeString(chunk); });
void XMLEscape(std::string_view s, Output output)
'XMLOutputStream' is a helper to write an XML file in a streaming way.
void attribute(std::string_view name, std::string_view value)
void begin(std::string_view tag)
XMLOutputStream(Operations &ops_)
void end(std::string_view tag)
void data(std::string_view value)
constexpr vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
constexpr auto subspan(Range &&range, size_t offset, size_t count=std::dynamic_extent)
strCatImpl::ConcatSpaces spaces(size_t n)