Pugixml XML parser

Update to upstream master
This commit is contained in:
Laurent Trinques
2020-07-26 16:14:31 +02:00
parent a2eb92803a
commit 9cdc023f31
3 changed files with 115 additions and 89 deletions

View File

@@ -72,4 +72,3 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */

View File

@@ -378,7 +378,7 @@ PUGI__NS_BEGIN
static PUGI__UNSIGNED_OVERFLOW unsigned int hash(const void* key) static PUGI__UNSIGNED_OVERFLOW unsigned int hash(const void* key)
{ {
unsigned int h = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(key)); unsigned int h = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(key) & 0xffffffff);
// MurmurHash3 32-bit finalizer // MurmurHash3 32-bit finalizer
h ^= h >> 16; h ^= h >> 16;
@@ -4435,6 +4435,9 @@ PUGI__NS_BEGIN
while (sit && sit != sn) while (sit && sit != sn)
{ {
// loop invariant: dit is inside the subtree rooted at dn
assert(dit);
// when a tree is copied into one of the descendants, we need to skip that subtree to avoid an infinite loop // when a tree is copied into one of the descendants, we need to skip that subtree to avoid an infinite loop
if (sit != dn) if (sit != dn)
{ {
@@ -4464,9 +4467,14 @@ PUGI__NS_BEGIN
sit = sit->parent; sit = sit->parent;
dit = dit->parent; dit = dit->parent;
// loop invariant: dit is inside the subtree rooted at dn while sit is inside sn
assert(sit == sn || dit);
} }
while (sit != sn); while (sit != sn);
} }
assert(!sit || dit == dn->parent);
} }
PUGI__FN void node_copy_attribute(xml_attribute_struct* da, xml_attribute_struct* sa) PUGI__FN void node_copy_attribute(xml_attribute_struct* da, xml_attribute_struct* sa)
@@ -6949,8 +6957,7 @@ namespace pugi
{ {
reset(); reset();
for (xml_node cur = proto.first_child(); cur; cur = cur.next_sibling()) impl::node_copy_tree(_root, proto._root);
append_copy(cur);
} }
PUGI__FN void xml_document::_create() PUGI__FN void xml_document::_create()
@@ -10414,11 +10421,16 @@ PUGI__NS_BEGIN
if (_rettype == xpath_type_boolean) if (_rettype == xpath_type_boolean)
return _data.variable->get_boolean(); return _data.variable->get_boolean();
// variable needs to be converted to the correct type, this is handled by the fallthrough block below
break;
} }
// fallthrough
default: default:
{ ;
}
// none of the ast types that return the value directly matched, we need to perform type conversion
switch (_rettype) switch (_rettype)
{ {
case xpath_type_number: case xpath_type_number:
@@ -10443,8 +10455,6 @@ PUGI__NS_BEGIN
return false; return false;
} }
} }
}
}
double eval_number(const xpath_context& c, const xpath_stack& stack) double eval_number(const xpath_context& c, const xpath_stack& stack)
{ {
@@ -10549,11 +10559,16 @@ PUGI__NS_BEGIN
if (_rettype == xpath_type_number) if (_rettype == xpath_type_number)
return _data.variable->get_number(); return _data.variable->get_number();
// variable needs to be converted to the correct type, this is handled by the fallthrough block below
break;
} }
// fallthrough
default: default:
{ ;
}
// none of the ast types that return the value directly matched, we need to perform type conversion
switch (_rettype) switch (_rettype)
{ {
case xpath_type_boolean: case xpath_type_boolean:
@@ -10577,9 +10592,6 @@ PUGI__NS_BEGIN
assert(false && "Wrong expression for return type number"); // unreachable assert(false && "Wrong expression for return type number"); // unreachable
return 0; return 0;
} }
}
}
} }
xpath_string eval_string_concat(const xpath_context& c, const xpath_stack& stack) xpath_string eval_string_concat(const xpath_context& c, const xpath_stack& stack)
@@ -10833,11 +10845,16 @@ PUGI__NS_BEGIN
if (_rettype == xpath_type_string) if (_rettype == xpath_type_string)
return xpath_string::from_const(_data.variable->get_string()); return xpath_string::from_const(_data.variable->get_string());
// variable needs to be converted to the correct type, this is handled by the fallthrough block below
break;
} }
// fallthrough
default: default:
{ ;
}
// none of the ast types that return the value directly matched, we need to perform type conversion
switch (_rettype) switch (_rettype)
{ {
case xpath_type_boolean: case xpath_type_boolean:
@@ -10861,8 +10878,6 @@ PUGI__NS_BEGIN
return xpath_string(); return xpath_string();
} }
} }
}
}
xpath_node_set_raw eval_node_set(const xpath_context& c, const xpath_stack& stack, nodeset_eval_t eval) xpath_node_set_raw eval_node_set(const xpath_context& c, const xpath_stack& stack, nodeset_eval_t eval)
{ {
@@ -10982,14 +10997,19 @@ PUGI__NS_BEGIN
return ns; return ns;
} }
// variable needs to be converted to the correct type, this is handled by the fallthrough block below
break;
} }
// fallthrough
default: default:
;
}
// none of the ast types that return the value directly matched, but conversions to node set are invalid
assert(false && "Wrong expression for return type node set"); // unreachable assert(false && "Wrong expression for return type node set"); // unreachable
return xpath_node_set_raw(); return xpath_node_set_raw();
} }
}
void optimize(xpath_allocator* alloc) void optimize(xpath_allocator* alloc)
{ {
@@ -12926,4 +12946,3 @@ namespace pugi
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */

View File

@@ -111,6 +111,15 @@
# endif # endif
#endif #endif
// If C++ is 2011 or higher, use 'nullptr'
#ifndef PUGIXML_NULL
# if __cplusplus >= 201103
# define PUGIXML_NULL nullptr
# else
# define PUGIXML_NULL 0
# endif
#endif
// Character interface macros // Character interface macros
#ifdef PUGIXML_WCHAR_MODE #ifdef PUGIXML_WCHAR_MODE
# define PUGIXML_TEXT(t) L ## t # define PUGIXML_TEXT(t) L ## t
@@ -661,15 +670,15 @@ namespace pugi
#ifndef PUGIXML_NO_XPATH #ifndef PUGIXML_NO_XPATH
// Select single node by evaluating XPath query. Returns first node from the resulting node set. // Select single node by evaluating XPath query. Returns first node from the resulting node set.
xpath_node select_node(const char_t* query, xpath_variable_set* variables = 0) const; xpath_node select_node(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL) const;
xpath_node select_node(const xpath_query& query) const; xpath_node select_node(const xpath_query& query) const;
// Select node set by evaluating XPath query // Select node set by evaluating XPath query
xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = 0) const; xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL) const;
xpath_node_set select_nodes(const xpath_query& query) const; xpath_node_set select_nodes(const xpath_query& query) const;
// (deprecated: use select_node instead) Select single node by evaluating XPath query. // (deprecated: use select_node instead) Select single node by evaluating XPath query.
PUGIXML_DEPRECATED xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const; PUGIXML_DEPRECATED xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL) const;
PUGIXML_DEPRECATED xpath_node select_single_node(const xpath_query& query) const; PUGIXML_DEPRECATED xpath_node select_single_node(const xpath_query& query) const;
#endif #endif
@@ -1212,7 +1221,7 @@ namespace pugi
public: public:
// Construct a compiled object from XPath expression. // Construct a compiled object from XPath expression.
// If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on compilation errors. // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on compilation errors.
explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0); explicit xpath_query(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL);
// Constructor // Constructor
xpath_query(); xpath_query();
@@ -1488,4 +1497,3 @@ namespace std
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */