mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 23:20:52 +01:00
Upgrade pugixml XML parser to 1.11 release
https://pugixml.org/docs/manual.html#v1.11
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* pugixml parser - version 1.10
|
* pugixml parser - version 1.11
|
||||||
* --------------------------------------------------------
|
* --------------------------------------------------------
|
||||||
* Copyright (C) 2006-2019, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
* Copyright (C) 2006-2020, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
||||||
* Report bugs and download new versions at https://pugixml.org/
|
* Report bugs and download new versions at https://pugixml.org/
|
||||||
*
|
*
|
||||||
* This library is distributed under the MIT License. See notice at the end
|
* This library is distributed under the MIT License. See notice at the end
|
||||||
@@ -40,6 +40,9 @@
|
|||||||
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
|
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
|
||||||
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
|
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
|
||||||
|
|
||||||
|
// Tune this constant to adjust max nesting for XPath queries
|
||||||
|
// #define PUGIXML_XPATH_DEPTH_LIMIT 1024
|
||||||
|
|
||||||
// Uncomment this to switch to header-only version
|
// Uncomment this to switch to header-only version
|
||||||
// #define PUGIXML_HEADER_ONLY
|
// #define PUGIXML_HEADER_ONLY
|
||||||
|
|
||||||
@@ -49,7 +52,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006-2019 Arseny Kapoulkine
|
* Copyright (c) 2006-2020 Arseny Kapoulkine
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
* obtaining a copy of this software and associated documentation
|
* obtaining a copy of this software and associated documentation
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* pugixml parser - version 1.10
|
* pugixml parser - version 1.11
|
||||||
* --------------------------------------------------------
|
* --------------------------------------------------------
|
||||||
* Copyright (C) 2006-2019, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
* Copyright (C) 2006-2020, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
||||||
* Report bugs and download new versions at https://pugixml.org/
|
* Report bugs and download new versions at https://pugixml.org/
|
||||||
*
|
*
|
||||||
* This library is distributed under the MIT License. See notice at the end
|
* This library is distributed under the MIT License. See notice at the end
|
||||||
@@ -4981,7 +4981,12 @@ PUGI__NS_BEGIN
|
|||||||
#if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) || (defined(__MINGW32__) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR)))
|
#if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) || (defined(__MINGW32__) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR)))
|
||||||
PUGI__FN FILE* open_file_wide(const wchar_t* path, const wchar_t* mode)
|
PUGI__FN FILE* open_file_wide(const wchar_t* path, const wchar_t* mode)
|
||||||
{
|
{
|
||||||
|
#if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400
|
||||||
|
FILE* file = 0;
|
||||||
|
return _wfopen_s(&file, path, mode) == 0 ? file : 0;
|
||||||
|
#else
|
||||||
return _wfopen(path, mode);
|
return _wfopen(path, mode);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
PUGI__FN char* convert_path_heap(const wchar_t* str)
|
PUGI__FN char* convert_path_heap(const wchar_t* str)
|
||||||
@@ -5025,6 +5030,16 @@ PUGI__NS_BEGIN
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
PUGI__FN FILE* open_file(const char* path, const char* mode)
|
||||||
|
{
|
||||||
|
#if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400
|
||||||
|
FILE* file = 0;
|
||||||
|
return fopen_s(&file, path, mode) == 0 ? file : 0;
|
||||||
|
#else
|
||||||
|
return fopen(path, mode);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
PUGI__FN bool save_file_impl(const xml_document& doc, FILE* file, const char_t* indent, unsigned int flags, xml_encoding encoding)
|
PUGI__FN bool save_file_impl(const xml_document& doc, FILE* file, const char_t* indent, unsigned int flags, xml_encoding encoding)
|
||||||
{
|
{
|
||||||
if (!file) return false;
|
if (!file) return false;
|
||||||
@@ -6127,13 +6142,13 @@ namespace pugi
|
|||||||
impl::xml_allocator& alloc = impl::get_allocator(_root);
|
impl::xml_allocator& alloc = impl::get_allocator(_root);
|
||||||
if (!alloc.reserve()) return false;
|
if (!alloc.reserve()) return false;
|
||||||
|
|
||||||
for (xml_node_struct* child = _root->first_child; child; )
|
for (xml_node_struct* cur = _root->first_child; cur; )
|
||||||
{
|
{
|
||||||
xml_node_struct* next = child->next_sibling;
|
xml_node_struct* next = cur->next_sibling;
|
||||||
|
|
||||||
impl::destroy_node(child, alloc);
|
impl::destroy_node(cur, alloc);
|
||||||
|
|
||||||
child = next;
|
cur = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
_root->first_child = 0;
|
_root->first_child = 0;
|
||||||
@@ -7187,7 +7202,7 @@ namespace pugi
|
|||||||
reset();
|
reset();
|
||||||
|
|
||||||
using impl::auto_deleter; // MSVC7 workaround
|
using impl::auto_deleter; // MSVC7 workaround
|
||||||
auto_deleter<FILE> file(fopen(path_, "rb"), impl::close_file);
|
auto_deleter<FILE> file(impl::open_file(path_, "rb"), impl::close_file);
|
||||||
|
|
||||||
return impl::load_file_impl(static_cast<impl::xml_document_struct*>(_root), file.data, options, encoding, &_buffer);
|
return impl::load_file_impl(static_cast<impl::xml_document_struct*>(_root), file.data, options, encoding, &_buffer);
|
||||||
}
|
}
|
||||||
@@ -7270,7 +7285,7 @@ namespace pugi
|
|||||||
PUGI__FN bool xml_document::save_file(const char* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const
|
PUGI__FN bool xml_document::save_file(const char* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const
|
||||||
{
|
{
|
||||||
using impl::auto_deleter; // MSVC7 workaround
|
using impl::auto_deleter; // MSVC7 workaround
|
||||||
auto_deleter<FILE> file(fopen(path_, (flags & format_save_file_text) ? "w" : "wb"), impl::close_file);
|
auto_deleter<FILE> file(impl::open_file(path_, (flags & format_save_file_text) ? "w" : "wb"), impl::close_file);
|
||||||
|
|
||||||
return impl::save_file_impl(*this, file.data, indent, flags, encoding);
|
return impl::save_file_impl(*this, file.data, indent, flags, encoding);
|
||||||
}
|
}
|
||||||
@@ -11143,6 +11158,14 @@ PUGI__NS_BEGIN
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const size_t xpath_ast_depth_limit =
|
||||||
|
#ifdef PUGIXML_XPATH_DEPTH_LIMIT
|
||||||
|
PUGIXML_XPATH_DEPTH_LIMIT
|
||||||
|
#else
|
||||||
|
1024
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
struct xpath_parser
|
struct xpath_parser
|
||||||
{
|
{
|
||||||
xpath_allocator* _alloc;
|
xpath_allocator* _alloc;
|
||||||
@@ -11155,6 +11178,8 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
char_t _scratch[32];
|
char_t _scratch[32];
|
||||||
|
|
||||||
|
size_t _depth;
|
||||||
|
|
||||||
xpath_ast_node* error(const char* message)
|
xpath_ast_node* error(const char* message)
|
||||||
{
|
{
|
||||||
_result->error = message;
|
_result->error = message;
|
||||||
@@ -11171,6 +11196,11 @@ PUGI__NS_BEGIN
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xpath_ast_node* error_rec()
|
||||||
|
{
|
||||||
|
return error("Exceeded maximum allowed query depth");
|
||||||
|
}
|
||||||
|
|
||||||
void* alloc_node()
|
void* alloc_node()
|
||||||
{
|
{
|
||||||
return _alloc->allocate(sizeof(xpath_ast_node));
|
return _alloc->allocate(sizeof(xpath_ast_node));
|
||||||
@@ -11526,6 +11556,8 @@ PUGI__NS_BEGIN
|
|||||||
return error("Unrecognized function call");
|
return error("Unrecognized function call");
|
||||||
_lexer.next();
|
_lexer.next();
|
||||||
|
|
||||||
|
size_t old_depth = _depth;
|
||||||
|
|
||||||
while (_lexer.current() != lex_close_brace)
|
while (_lexer.current() != lex_close_brace)
|
||||||
{
|
{
|
||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
@@ -11535,6 +11567,9 @@ PUGI__NS_BEGIN
|
|||||||
_lexer.next();
|
_lexer.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (++_depth > xpath_ast_depth_limit)
|
||||||
|
return error_rec();
|
||||||
|
|
||||||
xpath_ast_node* n = parse_expression();
|
xpath_ast_node* n = parse_expression();
|
||||||
if (!n) return 0;
|
if (!n) return 0;
|
||||||
|
|
||||||
@@ -11547,6 +11582,8 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
_lexer.next();
|
_lexer.next();
|
||||||
|
|
||||||
|
_depth = old_depth;
|
||||||
|
|
||||||
return parse_function(function, argc, args);
|
return parse_function(function, argc, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11563,10 +11600,15 @@ PUGI__NS_BEGIN
|
|||||||
xpath_ast_node* n = parse_primary_expression();
|
xpath_ast_node* n = parse_primary_expression();
|
||||||
if (!n) return 0;
|
if (!n) return 0;
|
||||||
|
|
||||||
|
size_t old_depth = _depth;
|
||||||
|
|
||||||
while (_lexer.current() == lex_open_square_brace)
|
while (_lexer.current() == lex_open_square_brace)
|
||||||
{
|
{
|
||||||
_lexer.next();
|
_lexer.next();
|
||||||
|
|
||||||
|
if (++_depth > xpath_ast_depth_limit)
|
||||||
|
return error_rec();
|
||||||
|
|
||||||
if (n->rettype() != xpath_type_node_set)
|
if (n->rettype() != xpath_type_node_set)
|
||||||
return error("Predicate has to be applied to node set");
|
return error("Predicate has to be applied to node set");
|
||||||
|
|
||||||
@@ -11582,6 +11624,8 @@ PUGI__NS_BEGIN
|
|||||||
_lexer.next();
|
_lexer.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_depth = old_depth;
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11733,12 +11777,17 @@ PUGI__NS_BEGIN
|
|||||||
xpath_ast_node* n = alloc_node(ast_step, set, axis, nt_type, nt_name_copy);
|
xpath_ast_node* n = alloc_node(ast_step, set, axis, nt_type, nt_name_copy);
|
||||||
if (!n) return 0;
|
if (!n) return 0;
|
||||||
|
|
||||||
|
size_t old_depth = _depth;
|
||||||
|
|
||||||
xpath_ast_node* last = 0;
|
xpath_ast_node* last = 0;
|
||||||
|
|
||||||
while (_lexer.current() == lex_open_square_brace)
|
while (_lexer.current() == lex_open_square_brace)
|
||||||
{
|
{
|
||||||
_lexer.next();
|
_lexer.next();
|
||||||
|
|
||||||
|
if (++_depth > xpath_ast_depth_limit)
|
||||||
|
return error_rec();
|
||||||
|
|
||||||
xpath_ast_node* expr = parse_expression();
|
xpath_ast_node* expr = parse_expression();
|
||||||
if (!expr) return 0;
|
if (!expr) return 0;
|
||||||
|
|
||||||
@@ -11755,6 +11804,8 @@ PUGI__NS_BEGIN
|
|||||||
last = pred;
|
last = pred;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_depth = old_depth;
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11764,11 +11815,16 @@ PUGI__NS_BEGIN
|
|||||||
xpath_ast_node* n = parse_step(set);
|
xpath_ast_node* n = parse_step(set);
|
||||||
if (!n) return 0;
|
if (!n) return 0;
|
||||||
|
|
||||||
|
size_t old_depth = _depth;
|
||||||
|
|
||||||
while (_lexer.current() == lex_slash || _lexer.current() == lex_double_slash)
|
while (_lexer.current() == lex_slash || _lexer.current() == lex_double_slash)
|
||||||
{
|
{
|
||||||
lexeme_t l = _lexer.current();
|
lexeme_t l = _lexer.current();
|
||||||
_lexer.next();
|
_lexer.next();
|
||||||
|
|
||||||
|
if (++_depth > xpath_ast_depth_limit)
|
||||||
|
return error_rec();
|
||||||
|
|
||||||
if (l == lex_double_slash)
|
if (l == lex_double_slash)
|
||||||
{
|
{
|
||||||
n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0);
|
n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0);
|
||||||
@@ -11779,6 +11835,8 @@ PUGI__NS_BEGIN
|
|||||||
if (!n) return 0;
|
if (!n) return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_depth = old_depth;
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11964,6 +12022,9 @@ PUGI__NS_BEGIN
|
|||||||
{
|
{
|
||||||
_lexer.next();
|
_lexer.next();
|
||||||
|
|
||||||
|
if (++_depth > xpath_ast_depth_limit)
|
||||||
|
return error_rec();
|
||||||
|
|
||||||
xpath_ast_node* rhs = parse_path_or_unary_expression();
|
xpath_ast_node* rhs = parse_path_or_unary_expression();
|
||||||
if (!rhs) return 0;
|
if (!rhs) return 0;
|
||||||
|
|
||||||
@@ -12009,13 +12070,22 @@ PUGI__NS_BEGIN
|
|||||||
// | MultiplicativeExpr 'mod' UnaryExpr
|
// | MultiplicativeExpr 'mod' UnaryExpr
|
||||||
xpath_ast_node* parse_expression(int limit = 0)
|
xpath_ast_node* parse_expression(int limit = 0)
|
||||||
{
|
{
|
||||||
|
size_t old_depth = _depth;
|
||||||
|
|
||||||
|
if (++_depth > xpath_ast_depth_limit)
|
||||||
|
return error_rec();
|
||||||
|
|
||||||
xpath_ast_node* n = parse_path_or_unary_expression();
|
xpath_ast_node* n = parse_path_or_unary_expression();
|
||||||
if (!n) return 0;
|
if (!n) return 0;
|
||||||
|
|
||||||
return parse_expression_rec(n, limit);
|
n = parse_expression_rec(n, limit);
|
||||||
|
|
||||||
|
_depth = old_depth;
|
||||||
|
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
xpath_parser(const char_t* query, xpath_variable_set* variables, xpath_allocator* alloc, xpath_parse_result* result): _alloc(alloc), _lexer(query), _query(query), _variables(variables), _result(result)
|
xpath_parser(const char_t* query, xpath_variable_set* variables, xpath_allocator* alloc, xpath_parse_result* result): _alloc(alloc), _lexer(query), _query(query), _variables(variables), _result(result), _depth(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12024,6 +12094,8 @@ PUGI__NS_BEGIN
|
|||||||
xpath_ast_node* n = parse_expression();
|
xpath_ast_node* n = parse_expression();
|
||||||
if (!n) return 0;
|
if (!n) return 0;
|
||||||
|
|
||||||
|
assert(_depth == 0);
|
||||||
|
|
||||||
// check if there are unparsed tokens left
|
// check if there are unparsed tokens left
|
||||||
if (_lexer.current() != lex_eof)
|
if (_lexer.current() != lex_eof)
|
||||||
return error("Incorrect query");
|
return error("Incorrect query");
|
||||||
@@ -12923,7 +12995,7 @@ namespace pugi
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006-2019 Arseny Kapoulkine
|
* Copyright (c) 2006-2020 Arseny Kapoulkine
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
* obtaining a copy of this software and associated documentation
|
* obtaining a copy of this software and associated documentation
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* pugixml parser - version 1.10
|
* pugixml parser - version 1.11
|
||||||
* --------------------------------------------------------
|
* --------------------------------------------------------
|
||||||
* Copyright (C) 2006-2019, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
* Copyright (C) 2006-2020, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
||||||
* Report bugs and download new versions at https://pugixml.org/
|
* Report bugs and download new versions at https://pugixml.org/
|
||||||
*
|
*
|
||||||
* This library is distributed under the MIT License. See notice at the end
|
* This library is distributed under the MIT License. See notice at the end
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
#ifndef PUGIXML_VERSION
|
#ifndef PUGIXML_VERSION
|
||||||
// Define version macro; evaluates to major * 1000 + minor * 10 + patch so that it's safe to use in less-than comparisons
|
// Define version macro; evaluates to major * 1000 + minor * 10 + patch so that it's safe to use in less-than comparisons
|
||||||
// Note: pugixml used major * 100 + minor * 10 + patch format up until 1.9 (which had version identifier 190); starting from pugixml 1.10, the minor version number is two digits
|
// Note: pugixml used major * 100 + minor * 10 + patch format up until 1.9 (which had version identifier 190); starting from pugixml 1.10, the minor version number is two digits
|
||||||
# define PUGIXML_VERSION 1100
|
# define PUGIXML_VERSION 1110
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Include user configuration file (this can define various configuration macros)
|
// Include user configuration file (this can define various configuration macros)
|
||||||
@@ -1279,13 +1279,13 @@ namespace pugi
|
|||||||
bool operator!() const;
|
bool operator!() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef PUGIXML_NO_EXCEPTIONS
|
#ifndef PUGIXML_NO_EXCEPTIONS
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
// C4275 can be ignored in Visual C++ if you are deriving
|
// C4275 can be ignored in Visual C++ if you are deriving
|
||||||
// from a type in the Standard C++ Library
|
// from a type in the Standard C++ Library
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable: 4275)
|
#pragma warning(disable: 4275)
|
||||||
#endif
|
#endif
|
||||||
// XPath exception class
|
// XPath exception class
|
||||||
class PUGIXML_CLASS xpath_exception: public std::exception
|
class PUGIXML_CLASS xpath_exception: public std::exception
|
||||||
{
|
{
|
||||||
@@ -1302,10 +1302,10 @@ namespace pugi
|
|||||||
// Get parse result
|
// Get parse result
|
||||||
const xpath_parse_result& result() const;
|
const xpath_parse_result& result() const;
|
||||||
};
|
};
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// XPath node class (either xml_node or xml_attribute)
|
// XPath node class (either xml_node or xml_attribute)
|
||||||
class PUGIXML_CLASS xpath_node
|
class PUGIXML_CLASS xpath_node
|
||||||
@@ -1474,7 +1474,7 @@ namespace std
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006-2019 Arseny Kapoulkine
|
* Copyright (c) 2006-2020 Arseny Kapoulkine
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
* obtaining a copy of this software and associated documentation
|
* obtaining a copy of this software and associated documentation
|
||||||
|
|||||||
Reference in New Issue
Block a user