summaryrefslogtreecommitdiff
path: root/src/pugixml.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-11-20 20:29:21 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-11-20 20:29:21 -0800
commita0dc468170a9f429446feafea48fc73ae348b648 (patch)
tree779ce209ca801a9a7146c20ba3d8a8cea1acd46b /src/pugixml.cpp
parent8f85b1ba7afb77228cffb31452272854abfa931e (diff)
Refactor node type checks for attribute insertion
Add allow_insert_attribute (similar to allow_insert_child).
Diffstat (limited to 'src/pugixml.cpp')
-rw-r--r--src/pugixml.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 75b5295..420ac1f 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -3682,6 +3682,11 @@ PUGI__NS_BEGIN
return false;
}
+ PUGI__FN bool allow_insert_attribute(xml_node_type parent)
+ {
+ return parent == node_element || parent == node_declaration;
+ }
+
PUGI__FN bool allow_insert_child(xml_node_type parent, xml_node_type child)
{
if (parent != node_document && parent != node_element) return false;
@@ -4872,7 +4877,7 @@ namespace pugi
PUGI__FN xml_attribute xml_node::append_attribute(const char_t* name_)
{
- if (type() != node_element && type() != node_declaration) return xml_attribute();
+ if (!impl::allow_insert_attribute(type())) return xml_attribute();
xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root)));
if (!a) return xml_attribute();
@@ -4886,7 +4891,7 @@ namespace pugi
PUGI__FN xml_attribute xml_node::prepend_attribute(const char_t* name_)
{
- if (type() != node_element && type() != node_declaration) return xml_attribute();
+ if (!impl::allow_insert_attribute(type())) return xml_attribute();
xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root)));
if (!a) return xml_attribute();
@@ -4900,7 +4905,7 @@ namespace pugi
PUGI__FN xml_attribute xml_node::insert_attribute_after(const char_t* name_, const xml_attribute& attr)
{
- if (type() != node_element && type() != node_declaration) return xml_attribute();
+ if (!impl::allow_insert_attribute(type())) return xml_attribute();
if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute();
xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root)));
@@ -4915,7 +4920,7 @@ namespace pugi
PUGI__FN xml_attribute xml_node::insert_attribute_before(const char_t* name_, const xml_attribute& attr)
{
- if (type() != node_element && type() != node_declaration) return xml_attribute();
+ if (!impl::allow_insert_attribute(type())) return xml_attribute();
if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute();
xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root)));