1 #ifndef RAPIDXML_PRINT_HPP_INCLUDED
2 #define RAPIDXML_PRINT_HPP_INCLUDED
13 #ifndef RAPIDXML_NO_STREAMS
38 template <
class OutIt,
class Ch>
40 copy_chars(
const Ch* begin,
const Ch* end, OutIt out)
52 template <
class OutIt,
class Ch>
54 copy_and_expand_chars(
const Ch* begin,
const Ch* end, Ch noexpand, OutIt out)
58 if (*begin == noexpand)
118 template <
class OutIt,
class Ch>
120 fill_chars(OutIt out,
int n, Ch ch)
122 for (
int i = 0; i < n; ++i)
131 template <
class Ch, Ch ch>
133 find_char(
const Ch* begin,
const Ch* end)
149 template <
class OutIt,
class Ch>
150 OutIt print_children(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
152 template <
class OutIt,
class Ch>
153 inline OutIt print_element_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
155 template <
class OutIt,
class Ch>
156 inline OutIt print_attributes(OutIt out,
const xml_node<Ch>* node,
int flags);
158 template <
class OutIt,
class Ch>
159 inline OutIt print_data_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
161 template <
class OutIt,
class Ch>
162 inline OutIt print_cdata_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
164 template <
class OutIt,
class Ch>
166 print_declaration_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
168 template <
class OutIt,
class Ch>
169 inline OutIt print_comment_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
171 template <
class OutIt,
class Ch>
172 inline OutIt print_doctype_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
174 template <
class OutIt,
class Ch>
175 inline OutIt print_pi_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent);
178 template <
class OutIt,
class Ch>
180 print_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
183 switch (node->
type())
188 out = print_children(out, node, flags, indent);
193 out = print_element_node(out, node, flags, indent);
198 out = print_data_node(out, node, flags, indent);
203 out = print_cdata_node(out, node, flags, indent);
208 out = print_declaration_node(out, node, flags, indent);
213 out = print_comment_node(out, node, flags, indent);
218 out = print_doctype_node(out, node, flags, indent);
223 out = print_pi_node(out, node, flags, indent);
235 *out = Ch(
'\n'), ++out;
243 template <
class OutIt,
class Ch>
245 print_children(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
249 out = print_node(out, child, flags, indent);
256 template <
class OutIt,
class Ch>
258 print_attributes(OutIt out,
const xml_node<Ch>* node,
int flags)
261 attribute = attribute->next_attribute())
263 if (attribute->name() && attribute->value())
266 *out = Ch(
' '), ++out;
268 attribute->name(), attribute->name() + attribute->name_size(), out);
269 *out = Ch(
'='), ++out;
272 if (find_char<Ch, Ch(
'"')>(attribute->value(),
273 attribute->value() + attribute->value_size()))
275 *out = Ch(
'\''), ++out;
276 out = copy_and_expand_chars(attribute->value(),
277 attribute->value() + attribute->value_size(),
280 *out = Ch(
'\''), ++out;
284 *out = Ch(
'"'), ++out;
285 out = copy_and_expand_chars(attribute->value(),
286 attribute->value() + attribute->value_size(),
289 *out = Ch(
'"'), ++out;
298 template <
class OutIt,
class Ch>
300 print_data_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
306 out = fill_chars(out, indent, Ch(
'\t'));
309 out = copy_and_expand_chars(
310 node->value(), node->value() + node->value_size(), Ch(0), out);
315 template <
class OutIt,
class Ch>
317 print_cdata_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
323 out = fill_chars(out, indent, Ch(
'\t'));
344 out = copy_chars(node->value(), node->value() + node->value_size(), out);
355 template <
class OutIt,
class Ch>
357 print_element_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
364 out = fill_chars(out, indent, Ch(
'\t'));
367 *out = Ch(
'<'), ++out;
368 out = copy_chars(node->name(), node->name() + node->name_size(), out);
369 out = print_attributes(out, node, flags);
372 if (node->value_size() == 0 && !node->
first_node())
375 *out = Ch(
'/'), ++out;
376 *out = Ch(
'>'), ++out;
381 *out = Ch(
'>'), ++out;
389 out = copy_and_expand_chars(
390 node->value(), node->value() + node->value_size(), Ch(0), out);
395 out = copy_and_expand_chars(
396 child->value(), child->value() + child->value_size(), Ch(0), out);
403 *out = Ch(
'\n'), ++out;
406 out = print_children(out, node, flags, indent + 1);
410 out = fill_chars(out, indent, Ch(
'\t'));
415 *out = Ch(
'<'), ++out;
416 *out = Ch(
'/'), ++out;
417 out = copy_chars(node->name(), node->name() + node->name_size(), out);
418 *out = Ch(
'>'), ++out;
425 template <
class OutIt,
class Ch>
427 print_declaration_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
432 out = fill_chars(out, indent, Ch(
'\t'));
435 *out = Ch(
'<'), ++out;
436 *out = Ch(
'?'), ++out;
437 *out = Ch(
'x'), ++out;
438 *out = Ch(
'm'), ++out;
439 *out = Ch(
'l'), ++out;
442 out = print_attributes(out, node, flags);
445 *out = Ch(
'?'), ++out;
446 *out = Ch(
'>'), ++out;
452 template <
class OutIt,
class Ch>
454 print_comment_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
460 out = fill_chars(out, indent, Ch(
'\t'));
463 *out = Ch(
'<'), ++out;
464 *out = Ch(
'!'), ++out;
465 *out = Ch(
'-'), ++out;
466 *out = Ch(
'-'), ++out;
467 out = copy_chars(node->value(), node->value() + node->value_size(), out);
468 *out = Ch(
'-'), ++out;
469 *out = Ch(
'-'), ++out;
470 *out = Ch(
'>'), ++out;
475 template <
class OutIt,
class Ch>
477 print_doctype_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
483 out = fill_chars(out, indent, Ch(
'\t'));
486 *out = Ch(
'<'), ++out;
487 *out = Ch(
'!'), ++out;
488 *out = Ch(
'D'), ++out;
489 *out = Ch(
'O'), ++out;
490 *out = Ch(
'C'), ++out;
491 *out = Ch(
'T'), ++out;
492 *out = Ch(
'Y'), ++out;
493 *out = Ch(
'P'), ++out;
494 *out = Ch(
'E'), ++out;
495 *out = Ch(
' '), ++out;
496 out = copy_chars(node->value(), node->value() + node->value_size(), out);
497 *out = Ch(
'>'), ++out;
502 template <
class OutIt,
class Ch>
504 print_pi_node(OutIt out,
const xml_node<Ch>* node,
int flags,
int indent)
510 out = fill_chars(out, indent, Ch(
'\t'));
513 *out = Ch(
'<'), ++out;
514 *out = Ch(
'?'), ++out;
515 out = copy_chars(node->name(), node->name() + node->name_size(), out);
516 *out = Ch(
' '), ++out;
517 out = copy_chars(node->value(), node->value() + node->value_size(), out);
518 *out = Ch(
'?'), ++out;
519 *out = Ch(
'>'), ++out;
535 template <
class OutIt,
class Ch>
539 return internal::print_node(out, &node, flags, 0);
542 #ifndef RAPIDXML_NO_STREAMS
550 inline std::basic_ostream<Ch>&
553 print(std::ostream_iterator<Ch>(out), node, flags);
562 inline std::basic_ostream<Ch>&
565 return print(out, node);