From d2443e8948ac237d02df51810d74343ae3a0551f Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Mon, 5 Jan 2009 20:23:14 +0000 Subject: Document saving improvements - no escaping is done for ' character or for symbols in second half of ASCII table; format_utf8 is therefore gone git-svn-id: http://pugixml.googlecode.com/svn/trunk@95 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'src/pugixml.cpp') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index be3de07..0646f8b 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -405,6 +405,13 @@ namespace return reinterpret_cast(str); } + template struct opt1_to_type + { + static const bool o1; + }; + + template const bool opt1_to_type<_1>::o1 = _1; + template struct opt2_to_type { static const bool o1; @@ -428,18 +435,17 @@ namespace template const bool opt4_to_type<_1, _2, _3, _4>::o4 = _4; #ifndef PUGIXML_NO_STL - template void text_output_escaped(std::ostream& os, const char* s, opt2) + template void text_output_escaped(std::ostream& os, const char* s, opt1) { - const bool attribute = opt2::o1; - const bool utf8 = opt2::o2; + const bool attribute = opt1::o1; while (*s) { const char* prev = s; // While *s is a usual symbol - while (*s && *s != '&' && *s != '<' && *s != '>' && ((*s != '"' && *s != '\'') || !attribute) - && (*s >= 32 || (*s == '\r' && !attribute) || (*s == '\n' && !attribute) || *s == '\t')) + while (*s && *s != '&' && *s != '<' && *s != '>' && (*s != '"' || !attribute) + && (*s < 0 || *s >= 32 || (*s == '\r' && !attribute) || (*s == '\n' && !attribute) || *s == '\t')) ++s; if (prev != s) os.write(prev, static_cast(s - prev)); @@ -463,10 +469,6 @@ namespace os << """; ++s; break; - case '\'': - os << "'"; - ++s; - break; case '\r': os << " "; ++s; @@ -477,12 +479,7 @@ namespace break; default: // s is not a usual symbol { - unsigned int ch; - - if (utf8) - s = strutf8_utf16(s, ch); - else - ch = (unsigned char)*s++; + unsigned int ch = (unsigned char)*s++; os << "&#" << ch << ";"; } @@ -2209,10 +2206,7 @@ namespace pugi { os << ' ' << a.name() << "=\""; - if (flags & format_utf8) - text_output_escaped(os, a.value(), opt2_to_type<1, 1>()); - else - text_output_escaped(os, a.value(), opt2_to_type<1, 0>()); + text_output_escaped(os, a.value(), opt1_to_type<1>()); os << "\""; } @@ -2235,10 +2229,7 @@ namespace pugi { os << ">"; - if (flags & format_utf8) - text_output_escaped(os, first_child().value(), opt2_to_type<0, 1>()); - else - text_output_escaped(os, first_child().value(), opt2_to_type<0, 0>()); + text_output_escaped(os, first_child().value(), opt1_to_type<0>()); os << "\n"; } @@ -2259,10 +2250,7 @@ namespace pugi } case node_pcdata: - if (flags & format_utf8) - text_output_escaped(os, value(), opt2_to_type<0, 1>()); - else - text_output_escaped(os, value(), opt2_to_type<0, 0>()); + text_output_escaped(os, value(), opt1_to_type<0>()); break; case node_cdata: -- cgit v1.2.3