From f79549cc09f1750d312c526ffa410018aa91689c Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 4 Feb 2023 14:03:05 +0800 Subject: [PATCH] 1.13 ABI compatible --- src/pugixml.cpp | 53 +++++++++++++++++++++++++++++++------------------ src/pugixml.hpp | 29 +++++++++++++++------------ 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 9bde50df..1555b0c0 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -2457,7 +2457,7 @@ PUGI__NS_BEGIN } template - PUGI__FN bool strcpy_insitu(String& dest, int& dest_len, Header& header, uintptr_t header_mask, const char_t* source, size_t source_length, bool shallow_copy = false) + PUGI__FN bool strcpy_insitu(String& dest, int& dest_len, Header& header, uintptr_t header_mask, const char_t* source, size_t source_length, boolean shallow_copy = pugi::false_value) { dest_len = static_cast(source_length); @@ -4836,7 +4836,7 @@ PUGI__NS_BEGIN template PUGI__FN bool set_value_bool(String& dest, int& dest_len, Header& header, uintptr_t header_mask, bool value) { - return strcpy_insitu(dest, dest_len, header, header_mask, value ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false"), value ? 4 : 5, true); + return strcpy_insitu(dest, dest_len, header, header_mask, value ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false"), value ? 4 : 5, true_value); } PUGI__FN xml_parse_result load_buffer_impl(xml_document_struct* doc, xml_node_struct* root, void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own, char_t** out_buffer) @@ -5485,20 +5485,25 @@ namespace pugi } #endif - PUGI__FN bool xml_attribute::set_name(string_view_t rhs, bool shallow_copy) + PUGI__FN bool xml_attribute::set_name(string_view_t rhs, boolean shallow_copy) { if (!_attr) return false; return impl::strcpy_insitu(_attr->name, _attr->name_len, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs.data(), rhs.length(), shallow_copy); } - PUGI__FN bool xml_attribute::set_value(string_view_t rhs, bool shallow_copy) + PUGI__FN bool xml_attribute::set_value(string_view_t rhs, boolean shallow_copy) { if (!_attr) return false; return impl::strcpy_insitu(_attr->value, _attr->value_len, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs.data(), rhs.length(), shallow_copy); } + PUGI__FN bool xml_attribute::set_value(char_t* rhs, size_t sz) + { + return set_value(string_view_t{rhs, sz }); + } + PUGI__FN bool xml_attribute::set_value(int rhs) { if (!_attr) return false; @@ -5847,7 +5852,7 @@ namespace pugi return first ? xml_node(first->prev_sibling_c) : xml_node(); } - PUGI__FN bool xml_node::set_name(string_view_t rhs, bool shallow_copy) + PUGI__FN bool xml_node::set_name(string_view_t rhs, boolean shallow_copy) { xml_node_type type_ = _root ? PUGI__NODETYPE(_root) : node_null; @@ -5857,7 +5862,7 @@ namespace pugi return impl::strcpy_insitu(_root->name, _root->name_len, _root->header, impl::xml_memory_page_name_allocated_mask, rhs.data(), rhs.length(), shallow_copy); } - PUGI__FN bool xml_node::set_value(string_view_t rhs, bool shallow_copy) + PUGI__FN bool xml_node::set_value(string_view_t rhs, boolean shallow_copy) { xml_node_type type_ = _root ? PUGI__NODETYPE(_root) : node_null; @@ -5867,7 +5872,12 @@ namespace pugi return impl::strcpy_insitu(_root->value, _root->value_len, _root->header, impl::xml_memory_page_value_allocated_mask, rhs.data(), rhs.length(), shallow_copy); } - PUGI__FN xml_attribute xml_node::append_attribute(string_view_t name_, bool shallow_copy) + PUGI__FN bool xml_node::set_value(char_t* rhs, size_t sz) + { + return set_value(string_view_t{ rhs, sz }); + } + + PUGI__FN xml_attribute xml_node::append_attribute(string_view_t name_, boolean shallow_copy) { if (!impl::allow_insert_attribute(type())) return xml_attribute(); @@ -5884,7 +5894,7 @@ namespace pugi return a; } - PUGI__FN xml_attribute xml_node::prepend_attribute(string_view_t name_, bool shallow_copy) + PUGI__FN xml_attribute xml_node::prepend_attribute(string_view_t name_, boolean shallow_copy) { if (!impl::allow_insert_attribute(type())) return xml_attribute(); @@ -5901,7 +5911,7 @@ namespace pugi return a; } - PUGI__FN xml_attribute xml_node::insert_attribute_after(string_view_t name_, const xml_attribute& attr, bool shallow_copy) + PUGI__FN xml_attribute xml_node::insert_attribute_after(string_view_t name_, const xml_attribute& attr, boolean shallow_copy) { if (!impl::allow_insert_attribute(type())) return xml_attribute(); if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute(); @@ -5919,7 +5929,7 @@ namespace pugi return a; } - PUGI__FN xml_attribute xml_node::insert_attribute_before(string_view_t name_, const xml_attribute& attr, bool shallow_copy) + PUGI__FN xml_attribute xml_node::insert_attribute_before(string_view_t name_, const xml_attribute& attr, boolean shallow_copy) { if (!impl::allow_insert_attribute(type())) return xml_attribute(); if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute(); @@ -6019,7 +6029,7 @@ namespace pugi impl::append_node(n._root, _root); - if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml"), true); + if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml"), true_value); return n; } @@ -6036,7 +6046,7 @@ namespace pugi impl::prepend_node(n._root, _root); - if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml"), true); + if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml"), true_value); return n; } @@ -6054,7 +6064,7 @@ namespace pugi impl::insert_node_before(n._root, node._root); - if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml"), true); + if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml"), true_value); return n; } @@ -6072,12 +6082,12 @@ namespace pugi impl::insert_node_after(n._root, node._root); - if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml"), true); + if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml"), true_value); return n; } - PUGI__FN xml_node xml_node::append_child(string_view_t name_, bool shallow_copy) + PUGI__FN xml_node xml_node::append_child(string_view_t name_, boolean shallow_copy) { xml_node result = append_child(node_element); @@ -6086,7 +6096,7 @@ namespace pugi return result; } - PUGI__FN xml_node xml_node::prepend_child(string_view_t name_, bool shallow_copy) + PUGI__FN xml_node xml_node::prepend_child(string_view_t name_, boolean shallow_copy) { xml_node result = prepend_child(node_element); @@ -6095,7 +6105,7 @@ namespace pugi return result; } - PUGI__FN xml_node xml_node::insert_child_after(string_view_t name_, const xml_node& node, bool shallow_copy) + PUGI__FN xml_node xml_node::insert_child_after(string_view_t name_, const xml_node& node, boolean shallow_copy) { xml_node result = insert_child_after(node_element, node); @@ -6104,7 +6114,7 @@ namespace pugi return result; } - PUGI__FN xml_node xml_node::insert_child_before(string_view_t name_, const xml_node& node, bool shallow_copy) + PUGI__FN xml_node xml_node::insert_child_before(string_view_t name_, const xml_node& node, boolean shallow_copy) { xml_node result = insert_child_before(node_element, node); @@ -6720,13 +6730,18 @@ namespace pugi } #endif - PUGI__FN bool xml_text::set(string_view_t rhs, bool shallow_copy) + PUGI__FN bool xml_text::set(string_view_t rhs, boolean shallow_copy) { xml_node_struct* dn = _data_new(); return dn ? impl::strcpy_insitu(dn->value, dn->value_len, dn->header, impl::xml_memory_page_value_allocated_mask, rhs.data(), rhs.length(), shallow_copy) : false; } + PUGI__FN bool xml_text::set(char_t* rhs, size_t sz) + { + return set(string_view_t{ rhs, sz }); + } + PUGI__FN bool xml_text::set(int rhs) { xml_node_struct* dn = _data_new(); diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 58dbb787..308271c5 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -568,8 +568,9 @@ namespace pugi bool as_bool(bool def = false) const; // Set attribute name/value (returns false if attribute is empty or there is not enough memory) - bool set_name(string_view_t rhs, bool shallow_copy = false); - bool set_value(string_view_t rhs, bool shallow_copy = false); + bool set_name(string_view_t rhs, boolean shallow_copy = pugi::false_value); + bool set_value(string_view_t rhs, boolean shallow_copy = pugi::false_value); + bool set_value(char_t*, size_t sz); // 1.13 ABI compatible // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") bool set_value(int rhs); @@ -702,14 +703,15 @@ namespace pugi string_view_t child_value(string_view_t name) const; // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value) - bool set_name(string_view_t rhs, bool shallow_copy = false); - bool set_value(string_view_t rhs, bool shallow_copy = false); + bool set_name(string_view_t rhs, boolean shallow_copy = pugi::false_value); + bool set_value(string_view_t rhs, boolean shallow_copy = pugi::false_value); + bool set_value(char_t* rhs, size_t sz); // 1.13 ABI compatible // Add attribute with specified name. Returns added attribute, or empty attribute on errors. - xml_attribute append_attribute(string_view_t name, bool shallow_copy = false); - xml_attribute prepend_attribute(string_view_t name, bool shallow_copy = false); - xml_attribute insert_attribute_after(string_view_t name, const xml_attribute& attr, bool shallow_copy = false); - xml_attribute insert_attribute_before(string_view_t name, const xml_attribute& attr, bool shallow_copy = false); + xml_attribute append_attribute(string_view_t name, boolean shallow_copy = pugi::false_value); + xml_attribute prepend_attribute(string_view_t name, boolean shallow_copy = pugi::false_value); + xml_attribute insert_attribute_after(string_view_t name, const xml_attribute& attr, boolean shallow_copy = pugi::false_value); + xml_attribute insert_attribute_before(string_view_t name, const xml_attribute& attr, boolean shallow_copy = pugi::false_value); // Add a copy of the specified attribute. Returns added attribute, or empty attribute on errors. xml_attribute append_copy(const xml_attribute& proto); @@ -724,10 +726,10 @@ namespace pugi xml_node insert_child_before(xml_node_type type, const xml_node& node); // Add child element with specified name. Returns added node, or empty node on errors. - xml_node append_child(string_view_t name, bool shallow_copy = false); - xml_node prepend_child(string_view_t name, bool shallow_copy = false); - xml_node insert_child_after(string_view_t name, const xml_node& node, bool shallow_copy = false); - xml_node insert_child_before(string_view_t name, const xml_node& node, bool shallow_copy = false); + xml_node append_child(string_view_t name, boolean shallow_copy = pugi::false_value); + xml_node prepend_child(string_view_t name, boolean shallow_copy = pugi::false_value); + xml_node insert_child_after(string_view_t name, const xml_node& node, boolean shallow_copy = pugi::false_value); + xml_node insert_child_before(string_view_t name, const xml_node& node, boolean shallow_copy = pugi::false_value); // Add a copy of the specified node as a child. Returns added node, or empty node on errors. xml_node append_copy(const xml_node& proto); @@ -931,7 +933,8 @@ namespace pugi bool as_bool(bool def = false) const; // Set text (returns false if object is empty or there is not enough memory) - bool set(string_view_t rhs, bool shallow_copy = false); + bool set(string_view_t rhs, boolean shallow_copy = pugi::false_value); + bool set(char_t* rhs, size_t sz); // 1.13 ABI compatible // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") bool set(int rhs);