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
This commit is contained in:
parent
4a5d55fc86
commit
62204df423
1 changed files with 11 additions and 34 deletions
|
@ -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\""));
|
||||
|
|
Loading…
Add table
Reference in a new issue