From 66e1b4e03e6eb908e37a8ef3f6ab2828d30d15c8 Mon Sep 17 00:00:00 2001 From: Yan Pashkovsky Date: Thu, 7 Mar 2019 17:54:30 +0300 Subject: [PATCH] format_skip_control_chars --- src/pugixml.cpp | 7 ++++--- src/pugixml.hpp | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 6ce4553..8a3c2c9 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -3903,7 +3903,7 @@ PUGI__NS_BEGIN xml_encoding encoding; }; - PUGI__FN void text_output_escaped(xml_buffered_writer& writer, const char_t* s, chartypex_t type) + PUGI__FN void text_output_escaped(xml_buffered_writer& writer, const char_t* s, chartypex_t type, unsigned int flags) { while (*s) { @@ -3938,7 +3938,8 @@ PUGI__NS_BEGIN unsigned int ch = static_cast(*s++); assert(ch < 32); - writer.write('&', '#', static_cast((ch / 10) + '0'), static_cast((ch % 10) + '0'), ';'); + if (!(flags & format_skip_control_chars)) + writer.write('&', '#', static_cast((ch / 10) + '0'), static_cast((ch % 10) + '0'), ';'); } } } @@ -3949,7 +3950,7 @@ PUGI__NS_BEGIN if (flags & format_no_escapes) writer.write_string(s); else - text_output_escaped(writer, s, type); + text_output_escaped(writer, s, type, flags); } PUGI__FN void text_output_cdata(xml_buffered_writer& writer, const char_t* s) diff --git a/src/pugixml.hpp b/src/pugixml.hpp index bfba0e3..d01f15f 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -252,6 +252,9 @@ namespace pugi // Don't output empty element tags, instead writing an explicit start and end tag even if there are no children. This flag is off by default. const unsigned int format_no_empty_element_tags = 0x80; + // Skip characters belonging to range [0; 32) instead of "&#xNN;" encoding. This flag is off by default. + const unsigned int format_skip_control_chars = 0x100; + // The default set of formatting flags. // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none. const unsigned int format_default = format_indent;