1#ifndef XMLOUTPUTSTREAM_HH
2#define XMLOUTPUTSTREAM_HH
74template<
typename Operations>
81 void begin(std::string_view tag);
82 void attribute(std::string_view name, std::string_view value);
83 void data(std::string_view value);
84 void end(std::string_view tag);
86 void with_tag(std::string_view tag, std::invocable
auto next);
89 void writeSpaces(
unsigned n);
90 void writeChar(
char c);
91 void writeString(std::string_view s);
92 void writeEscapedString(std::string_view s);
102 State state = INDENT;
104 std::vector<std::string> stack;
109template<
typename Writer>
113 stack.emplace_back(tag);
115 ops.check(state != DATA);
116 if (state == CLOSE) {
119 writeSpaces(2 * level);
126template<
typename Writer>
129 ops.check(level > 0);
130 ops.check(state == CLOSE);
134 writeEscapedString(value);
138template<
typename Writer>
141 ops.check(level > 0);
142 ops.check(state == CLOSE);
144 if (value.empty())
return;
147 writeEscapedString(value);
151template<
typename Writer>
155 ops.check(stack.size() == level);
156 ops.check(!stack.empty());
157 ops.check(stack.back() == tag);
160 ops.check(level > 0);
162 if (state == CLOSE) {
165 if (state == INDENT) {
166 writeSpaces(2 * level);
175template<
typename Writer>
183template<
typename Writer>
186 static constexpr std::array<char, 64>
spaces = {
187 ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
188 ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
189 ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
190 ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
193 auto t = std::min(64u, n);
199template<
typename Writer>
205template<
typename Writer>
211template<
typename Writer>
214 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 with_tag(std::string_view tag, std::invocable auto next)
void data(std::string_view value)
constexpr auto subspan(Range &&range, size_t offset, size_t count=std::dynamic_extent)
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)