Use has_name/has_value in set_name/set_value

This commit is contained in:
Arseny Kapoulkine 2015-04-22 07:51:02 -07:00
parent 4649914447
commit b87160013b

View File

@ -5490,38 +5490,29 @@ namespace pugi
PUGI__FN bool xml_node::set_name(const char_t* rhs) PUGI__FN bool xml_node::set_name(const char_t* rhs)
{ {
switch (type()) if (!_root) return false;
{
case node_pi: if (impl::has_name(_root))
case node_declaration:
case node_element:
return impl::strcpy_insitu(_root->contents, _root->header, impl::xml_memory_page_contents_allocated_mask, rhs); return impl::strcpy_insitu(_root->contents, _root->header, impl::xml_memory_page_contents_allocated_mask, rhs);
default: return false;
return false;
}
} }
PUGI__FN bool xml_node::set_value(const char_t* rhs) PUGI__FN bool xml_node::set_value(const char_t* rhs)
{ {
switch (type()) if (!_root) return false;
{
case node_pi: if (impl::has_value(_root))
return impl::strcpy_insitu(_root->contents, _root->header, impl::xml_memory_page_contents_allocated_mask, rhs);
if (PUGI__NODETYPE(_root) == node_pi)
{ {
xml_node_pi_struct* pn = static_cast<xml_node_pi_struct*>(_root); xml_node_pi_struct* pn = static_cast<xml_node_pi_struct*>(_root);
return impl::strcpy_insitu(pn->pi_value, pn->pi_header, impl::xml_memory_page_contents_allocated_mask, rhs); return impl::strcpy_insitu(pn->pi_value, pn->pi_header, impl::xml_memory_page_contents_allocated_mask, rhs);
} }
case node_cdata: return false;
case node_pcdata:
case node_comment:
case node_doctype:
return impl::strcpy_insitu(_root->contents, _root->header, impl::xml_memory_page_contents_allocated_mask, rhs);
default:
return false;
}
} }
PUGI__FN xml_attribute xml_node::append_attribute(const char_t* name_) PUGI__FN xml_attribute xml_node::append_attribute(const char_t* name_)