0
0
mirror of https://github.com/zeux/pugixml.git synced 2025-01-03 01:55:25 +08:00

Change has_declaration to work on node pointers

This is more for consistency with the surrounding code than for performance.
This commit is contained in:
Arseny Kapoulkine 2014-11-19 19:50:40 -08:00
parent 417048d8cb
commit 5c5038c264

View File

@ -3658,11 +3658,11 @@ PUGI__NS_BEGIN
while (node != root); while (node != root);
} }
PUGI__FN bool has_declaration(xml_node node) PUGI__FN bool has_declaration(xml_node_struct* node)
{ {
for (xml_node child = node.first_child(); child; child = child.next_sibling()) for (xml_node_struct* child = node->first_child; child; child = child->next_sibling)
{ {
xml_node_type type = child.type(); xml_node_type type = PUGI__NODETYPE(child);
if (type == node_declaration) return true; if (type == node_declaration) return true;
if (type == node_element) return false; if (type == node_element) return false;
@ -6066,7 +6066,7 @@ namespace pugi
#endif #endif
} }
if (!(flags & format_no_declaration) && !impl::has_declaration(*this)) if (!(flags & format_no_declaration) && !impl::has_declaration(_root))
{ {
buffered_writer.write_string(PUGIXML_TEXT("<?xml version=\"1.0\"")); buffered_writer.write_string(PUGIXML_TEXT("<?xml version=\"1.0\""));
if (encoding == encoding_latin1) buffered_writer.write_string(PUGIXML_TEXT(" encoding=\"ISO-8859-1\"")); if (encoding == encoding_latin1) buffered_writer.write_string(PUGIXML_TEXT(" encoding=\"ISO-8859-1\""));