diff options
author | arseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640> | 2012-03-27 04:23:05 +0000 |
---|---|---|
committer | arseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640> | 2012-03-27 04:23:05 +0000 |
commit | 62204df423eea909798045c834fc6aafa2ed17fe (patch) | |
tree | d2061e02e52aff2d7fae288bc97acbaa856a9f92 /src | |
parent | 4a5d55fc8627866e5c72db7efeb20d869ad7b669 (diff) |
Write BOM as U+FEFF to buffered writer; this makes sure we don't have a very small unbuffered write with custom writer implementations
git-svn-id: http://pugixml.googlecode.com/svn/trunk@887 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src')
-rw-r--r-- | src/pugixml.cpp | 45 |
1 files changed, 11 insertions, 34 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 01eeaaf..bee8f4a 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -2989,38 +2989,6 @@ PUGI__NS_BEGIN xml_encoding encoding; }; - PUGI__FN void write_bom(xml_writer& writer, xml_encoding encoding) - { - switch (encoding) - { - case encoding_utf8: - writer.write("\xef\xbb\xbf", 3); - break; - - case encoding_utf16_be: - writer.write("\xfe\xff", 2); - break; - - case encoding_utf16_le: - writer.write("\xff\xfe", 2); - break; - - case encoding_utf32_be: - writer.write("\x00\x00\xfe\xff", 4); - break; - - case encoding_utf32_le: - writer.write("\xff\xfe\x00\x00", 4); - break; - - case encoding_latin1: - break; - - default: - assert(!"Invalid encoding"); - } - } - PUGI__FN void text_output_escaped(xml_buffered_writer& writer, const char_t* s, chartypex_t type) { while (*s) @@ -5223,10 +5191,19 @@ namespace pugi PUGI__FN void xml_document::save(xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding) const { - if (flags & format_write_bom) impl::write_bom(writer, impl::get_write_encoding(encoding)); - impl::xml_buffered_writer buffered_writer(writer, encoding); + if ((flags & format_write_bom) && encoding != encoding_latin1) + { + // BOM always represents the codepoint U+FEFF, so just write it in native encoding + #ifdef PUGIXML_WCHAR_MODE + uint16_t bom = 0xfeff; + buffered_writer.write(static_cast<wchar_t>(bom)); + #else + buffered_writer.write('\xef', '\xbb', '\xbf'); + #endif + } + if (!(flags & format_no_declaration) && !impl::has_declaration(*this)) { buffered_writer.write(PUGIXML_TEXT("<?xml version=\"1.0\"")); |