diff --git a/thirdparty/pugixml/pugixml/src/pugiconfig.hpp b/thirdparty/pugixml/pugixml/src/pugiconfig.hpp index 3dc839da6e..5f1bafdbe9 100644 --- a/thirdparty/pugixml/pugixml/src/pugiconfig.hpp +++ b/thirdparty/pugixml/pugixml/src/pugiconfig.hpp @@ -1,7 +1,7 @@ /** - * pugixml parser - version 1.14 + * pugixml parser - version 1.15 * -------------------------------------------------------- - * Copyright (C) 2006-2023, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) + * Copyright (C) 2006-2025, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) * Report bugs and download new versions at https://pugixml.org/ * * This library is distributed under the MIT License. See notice at the end @@ -46,13 +46,16 @@ // Uncomment this to switch to header-only version // #define PUGIXML_HEADER_ONLY -// Uncomment this to enable long long support +// Uncomment this to enable long long support (usually enabled automatically) // #define PUGIXML_HAS_LONG_LONG +// Uncomment this to enable support for std::string_view (usually enabled automatically) +// #define PUGIXML_HAS_STRING_VIEW + #endif /** - * Copyright (c) 2006-2023 Arseny Kapoulkine + * Copyright (c) 2006-2025 Arseny Kapoulkine * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/thirdparty/pugixml/pugixml/src/pugixml.cpp b/thirdparty/pugixml/pugixml/src/pugixml.cpp index 89123c75d0..53a0526e42 100644 --- a/thirdparty/pugixml/pugixml/src/pugixml.cpp +++ b/thirdparty/pugixml/pugixml/src/pugixml.cpp @@ -1,7 +1,7 @@ /** - * pugixml parser - version 1.14 + * pugixml parser - version 1.15 * -------------------------------------------------------- - * Copyright (C) 2006-2023, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) + * Copyright (C) 2006-2025, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) * Report bugs and download new versions at https://pugixml.org/ * * This library is distributed under the MIT License. See notice at the end @@ -53,6 +53,11 @@ # pragma warning(disable: 4996) // this function or variable may be unsafe #endif +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // NULL as null pointer constant +#endif + #if defined(_MSC_VER) && defined(__c2__) # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdeprecated" // this function or variable may be unsafe @@ -247,6 +252,24 @@ PUGI_IMPL_NS_BEGIN #endif } +#ifdef PUGIXML_HAS_STRING_VIEW + // Check if the null-terminated dst string is equal to the entire contents of srcview + PUGI_IMPL_FN bool stringview_equal(string_view_t srcview, const char_t* dst) + { + // std::basic_string_view::compare(const char*) has the right behavior, but it performs an + // extra traversal of dst to compute its length. + assert(dst); + const char_t* src = srcview.data(); + size_t srclen = srcview.size(); + + while (srclen && *dst && *src == *dst) + { + --srclen; ++dst; ++src; + } + return srclen == 0 && *dst == 0; + } +#endif + // Compare lhs with [rhs_begin, rhs_end) PUGI_IMPL_FN bool strequalrange(const char_t* lhs, const char_t* rhs, size_t count) { @@ -293,7 +316,7 @@ PUGI_IMPL_NS_BEGIN T* release() { T* result = data; - data = 0; + data = NULL; return result; } }; @@ -304,7 +327,7 @@ PUGI_IMPL_NS_BEGIN class compact_hash_table { public: - compact_hash_table(): _items(0), _capacity(0), _count(0) + compact_hash_table(): _items(NULL), _capacity(0), _count(0) { } @@ -313,7 +336,7 @@ PUGI_IMPL_NS_BEGIN if (_items) { xml_memory::deallocate(_items); - _items = 0; + _items = NULL; _capacity = 0; _count = 0; } @@ -321,11 +344,11 @@ PUGI_IMPL_NS_BEGIN void* find(const void* key) { - if (_capacity == 0) return 0; + if (_capacity == 0) return NULL; item_t* item = get_item(key); assert(item); - assert(item->key == key || (item->key == 0 && item->value == 0)); + assert(item->key == key || (item->key == NULL && item->value == NULL)); return item->value; } @@ -337,7 +360,7 @@ PUGI_IMPL_NS_BEGIN item_t* item = get_item(key); assert(item); - if (item->key == 0) + if (item->key == NULL) { _count++; item->key = key; @@ -380,7 +403,7 @@ PUGI_IMPL_NS_BEGIN { item_t& probe_item = _items[bucket]; - if (probe_item.key == key || probe_item.key == 0) + if (probe_item.key == key || probe_item.key == NULL) return &probe_item; // hash collision, quadratic probing @@ -388,7 +411,7 @@ PUGI_IMPL_NS_BEGIN } assert(false && "Hash table is full"); // unreachable - return 0; + return NULL; } static PUGI_IMPL_UNSIGNED_OVERFLOW unsigned int hash(const void* key) @@ -476,16 +499,16 @@ PUGI_IMPL_NS_BEGIN { xml_memory_page* result = static_cast(memory); - result->allocator = 0; - result->prev = 0; - result->next = 0; + result->allocator = NULL; + result->prev = NULL; + result->next = NULL; result->busy_size = 0; result->freed_size = 0; #ifdef PUGIXML_COMPACT - result->compact_string_base = 0; - result->compact_shared_parent = 0; - result->compact_page_marker = 0; + result->compact_string_base = NULL; + result->compact_shared_parent = NULL; + result->compact_page_marker = NULL; #endif return result; @@ -525,7 +548,7 @@ PUGI_IMPL_NS_BEGIN xml_allocator(xml_memory_page* root): _root(root), _busy_size(root->busy_size) { #ifdef PUGIXML_COMPACT - _hash = 0; + _hash = NULL; #endif } @@ -535,7 +558,7 @@ PUGI_IMPL_NS_BEGIN // allocate block with some alignment, leaving memory for worst-case padding void* memory = xml_memory::allocate(size); - if (!memory) return 0; + if (!memory) return NULL; // prepare page structure xml_memory_page* page = xml_memory_page::construct(memory); @@ -572,7 +595,7 @@ PUGI_IMPL_NS_BEGIN void* allocate_object(size_t size, xml_memory_page*& out_page) { void* result = allocate_memory(size + sizeof(uint32_t), out_page); - if (!result) return 0; + if (!result) return NULL; // adjust for marker ptrdiff_t offset = static_cast(result) - reinterpret_cast(out_page->compact_page_marker); @@ -618,7 +641,7 @@ PUGI_IMPL_NS_BEGIN if (page->freed_size == page->busy_size) { - if (page->next == 0) + if (page->next == NULL) { assert(_root == page); @@ -628,9 +651,9 @@ PUGI_IMPL_NS_BEGIN #ifdef PUGIXML_COMPACT // reset compact state to maximize efficiency - page->compact_string_base = 0; - page->compact_shared_parent = 0; - page->compact_page_marker = 0; + page->compact_string_base = NULL; + page->compact_shared_parent = NULL; + page->compact_page_marker = NULL; #endif _busy_size = 0; @@ -665,7 +688,7 @@ PUGI_IMPL_NS_BEGIN xml_memory_page* page; xml_memory_string_header* header = static_cast(allocate_memory(full_size, page)); - if (!header) return 0; + if (!header) return NULL; // setup header ptrdiff_t page_offset = reinterpret_cast(header) - reinterpret_cast(page) - sizeof(xml_memory_page); @@ -727,7 +750,7 @@ PUGI_IMPL_NS_BEGIN xml_memory_page* page = allocate_page(size <= large_allocation_threshold ? xml_memory_page_size : size); out_page = page; - if (!page) return 0; + if (!page) return NULL; if (size <= large_allocation_threshold) { @@ -874,7 +897,7 @@ PUGI_IMPL_NS_BEGIN return compact_get_value(this); } else - return 0; + return NULL; } T* operator->() const @@ -917,7 +940,7 @@ PUGI_IMPL_NS_BEGIN { xml_memory_page* page = compact_get_page(this, header_offset); - if (PUGI_IMPL_UNLIKELY(page->compact_shared_parent == 0)) + if (PUGI_IMPL_UNLIKELY(page->compact_shared_parent == NULL)) page->compact_shared_parent = value; if (page->compact_shared_parent == value) @@ -954,7 +977,7 @@ PUGI_IMPL_NS_BEGIN return compact_get_value(this); } else - return 0; + return NULL; } T* operator->() const @@ -984,7 +1007,7 @@ PUGI_IMPL_NS_BEGIN { xml_memory_page* page = compact_get_page(this, header_offset); - if (PUGI_IMPL_UNLIKELY(page->compact_string_base == 0)) + if (PUGI_IMPL_UNLIKELY(page->compact_string_base == NULL)) page->compact_string_base = value; ptrdiff_t offset = value - page->compact_string_base; @@ -1050,7 +1073,7 @@ PUGI_IMPL_NS_BEGIN } } else - return 0; + return NULL; } private: @@ -1109,7 +1132,7 @@ namespace pugi { struct xml_attribute_struct { - xml_attribute_struct(impl::xml_memory_page* page): name(0), value(0), prev_attribute_c(0), next_attribute(0) + xml_attribute_struct(impl::xml_memory_page* page): name(NULL), value(NULL), prev_attribute_c(NULL), next_attribute(NULL) { header = PUGI_IMPL_GETHEADER_IMPL(this, page, 0); } @@ -1125,7 +1148,7 @@ namespace pugi struct xml_node_struct { - xml_node_struct(impl::xml_memory_page* page, xml_node_type type): name(0), value(0), parent(0), first_child(0), prev_sibling_c(0), next_sibling(0), first_attribute(0) + xml_node_struct(impl::xml_memory_page* page, xml_node_type type): name(NULL), value(NULL), parent(NULL), first_child(NULL), prev_sibling_c(NULL), next_sibling(NULL), first_attribute(NULL) { header = PUGI_IMPL_GETHEADER_IMPL(this, page, type); } @@ -1156,7 +1179,7 @@ PUGI_IMPL_NS_BEGIN struct xml_document_struct: public xml_node_struct, public xml_allocator { - xml_document_struct(xml_memory_page* page): xml_node_struct(page, node_document), xml_allocator(page), buffer(0), extra_buffers(0) + xml_document_struct(xml_memory_page* page): xml_node_struct(page, node_document), xml_allocator(page), buffer(NULL), extra_buffers(NULL) { } @@ -1190,7 +1213,7 @@ PUGI_IMPL_NS_BEGIN { xml_memory_page* page; void* memory = alloc.allocate_object(sizeof(xml_attribute_struct), page); - if (!memory) return 0; + if (!memory) return NULL; return new (memory) xml_attribute_struct(page); } @@ -1199,7 +1222,7 @@ PUGI_IMPL_NS_BEGIN { xml_memory_page* page; void* memory = alloc.allocate_object(sizeof(xml_node_struct), page); - if (!memory) return 0; + if (!memory) return NULL; return new (memory) xml_node_struct(page, type); } @@ -1338,9 +1361,9 @@ PUGI_IMPL_NS_BEGIN else parent->first_child = next; - node->parent = 0; - node->prev_sibling_c = 0; - node->next_sibling = 0; + node->parent = NULL; + node->prev_sibling_c = NULL; + node->next_sibling = NULL; } inline void append_attribute(xml_attribute_struct* attr, xml_node_struct* node) @@ -1421,16 +1444,16 @@ PUGI_IMPL_NS_BEGIN else node->first_attribute = next; - attr->prev_attribute_c = 0; - attr->next_attribute = 0; + attr->prev_attribute_c = NULL; + attr->next_attribute = NULL; } PUGI_IMPL_FN_NO_INLINE xml_node_struct* append_new_node(xml_node_struct* node, xml_allocator& alloc, xml_node_type type = node_element) { - if (!alloc.reserve()) return 0; + if (!alloc.reserve()) return NULL; xml_node_struct* child = allocate_node(alloc, type); - if (!child) return 0; + if (!child) return NULL; append_node(child, node); @@ -1439,10 +1462,10 @@ PUGI_IMPL_NS_BEGIN PUGI_IMPL_FN_NO_INLINE xml_attribute_struct* append_new_attribute(xml_node_struct* node, xml_allocator& alloc) { - if (!alloc.reserve()) return 0; + if (!alloc.reserve()) return NULL; xml_attribute_struct* attr = allocate_attribute(alloc); - if (!attr) return 0; + if (!attr) return NULL; append_attribute(attr, node); @@ -1569,8 +1592,8 @@ PUGI_IMPL_NS_BEGIN static value_type high(value_type result, uint32_t ch) { - uint32_t msh = static_cast(ch - 0x10000) >> 10; - uint32_t lsh = static_cast(ch - 0x10000) & 0x3ff; + uint32_t msh = (ch - 0x10000U) >> 10; + uint32_t lsh = (ch - 0x10000U) & 0x3ff; result[0] = static_cast(0xD800 + msh); result[1] = static_cast(0xDC00 + lsh); @@ -2024,7 +2047,7 @@ PUGI_IMPL_NS_BEGIN if (d0 == 0x3c && d1 == 0) return encoding_utf16_le; // no known BOM detected; parse declaration - const uint8_t* enc = 0; + const uint8_t* enc = NULL; size_t enc_length = 0; if (d0 == 0x3c && d1 == 0x3f && d2 == 0x78 && d3 == 0x6d && parse_declaration_encoding(data, size, enc, enc_length)) @@ -2395,7 +2418,7 @@ PUGI_IMPL_NS_BEGIN if (header & header_mask) alloc->deallocate_string(dest); // mark the string as not allocated - dest = 0; + dest = NULL; header &= ~header_mask; return true; @@ -2438,7 +2461,7 @@ PUGI_IMPL_NS_BEGIN char_t* end; size_t size; - gap(): end(0), size(0) + gap(): end(NULL), size(0) { } @@ -2450,7 +2473,7 @@ PUGI_IMPL_NS_BEGIN { // Move [old_gap_end, new_gap_start) to [old_gap_start, ...) assert(s >= end); - memmove(end - size, end, reinterpret_cast(s) - reinterpret_cast(end)); + memmove(end - size, end, (s - end) * sizeof(char_t)); } s += count; // end of current gap @@ -2467,7 +2490,7 @@ PUGI_IMPL_NS_BEGIN { // Move [old_gap_end, current_pos) to [old_gap_start, ...) assert(s >= end); - memmove(end - size, end, reinterpret_cast(s) - reinterpret_cast(end)); + memmove(end - size, end, (s - end) * sizeof(char_t)); return s - size; } @@ -2625,7 +2648,7 @@ PUGI_IMPL_NS_BEGIN #define PUGI_IMPL_SCANWHILE(X) { while (X) ++s; } #define PUGI_IMPL_SCANWHILE_UNROLL(X) { for (;;) { char_t ss = s[0]; if (PUGI_IMPL_UNLIKELY(!(X))) { break; } ss = s[1]; if (PUGI_IMPL_UNLIKELY(!(X))) { s += 1; break; } ss = s[2]; if (PUGI_IMPL_UNLIKELY(!(X))) { s += 2; break; } ss = s[3]; if (PUGI_IMPL_UNLIKELY(!(X))) { s += 3; break; } s += 4; } } #define PUGI_IMPL_ENDSEG() { ch = *s; *s = 0; ++s; } - #define PUGI_IMPL_THROW_ERROR(err, m) return error_offset = m, error_status = err, static_cast(0) + #define PUGI_IMPL_THROW_ERROR(err, m) return error_offset = m, error_status = err, static_cast(NULL) #define PUGI_IMPL_CHECK_ERROR(err, m) { if (*s == 0) PUGI_IMPL_THROW_ERROR(err, m); } PUGI_IMPL_FN char_t* strconv_comment(char_t* s, char_t endch) @@ -2650,7 +2673,7 @@ PUGI_IMPL_NS_BEGIN } else if (*s == 0) { - return 0; + return NULL; } else ++s; } @@ -2678,7 +2701,7 @@ PUGI_IMPL_NS_BEGIN } else if (*s == 0) { - return 0; + return NULL; } else ++s; } @@ -2751,7 +2774,7 @@ PUGI_IMPL_NS_BEGIN case 5: return strconv_pcdata_impl::parse; case 6: return strconv_pcdata_impl::parse; case 7: return strconv_pcdata_impl::parse; - default: assert(false); return 0; // unreachable + default: assert(false); return NULL; // unreachable } } @@ -2805,7 +2828,7 @@ PUGI_IMPL_NS_BEGIN } else if (!*s) { - return 0; + return NULL; } else ++s; } @@ -2841,7 +2864,7 @@ PUGI_IMPL_NS_BEGIN } else if (!*s) { - return 0; + return NULL; } else ++s; } @@ -2873,7 +2896,7 @@ PUGI_IMPL_NS_BEGIN } else if (!*s) { - return 0; + return NULL; } else ++s; } @@ -2899,7 +2922,7 @@ PUGI_IMPL_NS_BEGIN } else if (!*s) { - return 0; + return NULL; } else ++s; } @@ -2928,7 +2951,7 @@ PUGI_IMPL_NS_BEGIN case 13: return strconv_attribute_impl::parse_wnorm; case 14: return strconv_attribute_impl::parse_wnorm; case 15: return strconv_attribute_impl::parse_wnorm; - default: assert(false); return 0; // unreachable + default: assert(false); return NULL; // unreachable } } @@ -2947,7 +2970,7 @@ PUGI_IMPL_NS_BEGIN char_t* error_offset; xml_parse_status error_status; - xml_parser(xml_allocator* alloc_): alloc(alloc_), error_offset(0), error_status(status_ok) + xml_parser(xml_allocator* alloc_): alloc(alloc_), error_offset(NULL), error_status(status_ok) { } @@ -3559,7 +3582,7 @@ PUGI_IMPL_NS_BEGIN return make_parse_result(PUGI_IMPL_OPTSET(parse_fragment) ? status_ok : status_no_document_element); // get last child of the root before parsing - xml_node_struct* last_root_child = root->first_child ? root->first_child->prev_sibling_c + 0 : 0; + xml_node_struct* last_root_child = root->first_child ? root->first_child->prev_sibling_c + 0 : NULL; // create parser on stack xml_parser parser(static_cast(xmldoc)); @@ -4476,7 +4499,7 @@ PUGI_IMPL_NS_BEGIN PUGI_IMPL_FN void node_copy_tree(xml_node_struct* dn, xml_node_struct* sn) { xml_allocator& alloc = get_allocator(dn); - xml_allocator* shared_alloc = (&alloc == &get_allocator(sn)) ? &alloc : 0; + xml_allocator* shared_alloc = (&alloc == &get_allocator(sn)) ? &alloc : NULL; node_copy_contents(dn, sn, shared_alloc); @@ -4530,7 +4553,7 @@ PUGI_IMPL_NS_BEGIN PUGI_IMPL_FN void node_copy_attribute(xml_attribute_struct* da, xml_attribute_struct* sa) { xml_allocator& alloc = get_allocator(da); - xml_allocator* shared_alloc = (&alloc == &get_allocator(sa)) ? &alloc : 0; + xml_allocator* shared_alloc = (&alloc == &get_allocator(sa)) ? &alloc : NULL; node_copy_string(da->name, da->header, xml_memory_page_name_allocated_mask, sa->name, sa->header, shared_alloc); node_copy_string(da->value, da->header, xml_memory_page_value_allocated_mask, sa->value, sa->header, shared_alloc); @@ -4639,18 +4662,18 @@ PUGI_IMPL_NS_BEGIN PUGI_IMPL_FN double get_value_double(const char_t* value) { #ifdef PUGIXML_WCHAR_MODE - return wcstod(value, 0); + return wcstod(value, NULL); #else - return strtod(value, 0); + return strtod(value, NULL); #endif } PUGI_IMPL_FN float get_value_float(const char_t* value) { #ifdef PUGIXML_WCHAR_MODE - return static_cast(wcstod(value, 0)); + return static_cast(wcstod(value, NULL)); #else - return static_cast(strtod(value, 0)); + return static_cast(strtod(value, NULL)); #endif } @@ -4755,10 +4778,10 @@ PUGI_IMPL_NS_BEGIN xml_encoding buffer_encoding = impl::get_buffer_encoding(encoding, contents, size); // if convert_buffer below throws bad_alloc, we still need to deallocate contents if we own it - auto_deleter contents_guard(own ? contents : 0, xml_memory::deallocate); + auto_deleter contents_guard(own ? contents : NULL, xml_memory::deallocate); // get private buffer - char_t* buffer = 0; + char_t* buffer = NULL; size_t length = 0; // coverity[var_deref_model] @@ -4785,6 +4808,20 @@ PUGI_IMPL_NS_BEGIN return res; } + template PUGI_IMPL_FN xml_parse_status convert_file_size(T length, size_t& out_result) + { + // check for I/O errors + if (length < 0) return status_io_error; + + // check for overflow + size_t result = static_cast(length); + + if (static_cast(result) != length) return status_out_of_memory; + + out_result = result; + return status_ok; + } + // we need to get length of entire file to load it in memory; the only (relatively) sane way to do it is via seek/tell trick PUGI_IMPL_FN xml_parse_status get_file_size(FILE* file, size_t& out_result) { @@ -4796,43 +4833,31 @@ PUGI_IMPL_NS_BEGIN // anything that's not a regular file doesn't have a coherent length if (!S_ISREG(st.st_mode)) return status_io_error; - typedef off_t length_type; - length_type length = st.st_size; + xml_parse_status status = convert_file_size(st.st_size, out_result); #elif defined(PUGI_IMPL_MSVC_CRT_VERSION) && PUGI_IMPL_MSVC_CRT_VERSION >= 1400 // there are 64-bit versions of fseek/ftell, let's use them - typedef __int64 length_type; - _fseeki64(file, 0, SEEK_END); - length_type length = _ftelli64(file); + __int64 length = _ftelli64(file); _fseeki64(file, 0, SEEK_SET); + + xml_parse_status status = convert_file_size(length, out_result); #elif defined(__MINGW32__) && !defined(__NO_MINGW_LFS) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR)) // there are 64-bit versions of fseek/ftell, let's use them - typedef off64_t length_type; - fseeko64(file, 0, SEEK_END); - length_type length = ftello64(file); + off64_t length = ftello64(file); fseeko64(file, 0, SEEK_SET); + + xml_parse_status status = convert_file_size(length, out_result); #else // if this is a 32-bit OS, long is enough; if this is a unix system, long is 64-bit, which is enough; otherwise we can't do anything anyway. - typedef long length_type; - fseek(file, 0, SEEK_END); - length_type length = ftell(file); + long length = ftell(file); fseek(file, 0, SEEK_SET); - #endif - - // check for I/O errors - if (length < 0) return status_io_error; - - // check for overflow - size_t result = static_cast(length); - if (static_cast(result) != length) return status_out_of_memory; - - // finalize - out_result = result; + xml_parse_status status = convert_file_size(length, out_result); + #endif - return status_ok; + return status; } // This function assumes that buffer has extra sizeof(char_t) writable bytes after size @@ -4900,7 +4925,7 @@ PUGI_IMPL_NS_BEGIN static xml_stream_chunk* create() { void* memory = xml_memory::allocate(sizeof(xml_stream_chunk)); - if (!memory) return 0; + if (!memory) return NULL; return new (memory) xml_stream_chunk(); } @@ -4918,7 +4943,7 @@ PUGI_IMPL_NS_BEGIN } } - xml_stream_chunk(): next(0), size(0) + xml_stream_chunk(): next(NULL), size(0) { } @@ -4930,11 +4955,11 @@ PUGI_IMPL_NS_BEGIN template PUGI_IMPL_FN xml_parse_status load_stream_data_noseek(std::basic_istream& stream, void** out_buffer, size_t* out_size) { - auto_deleter > chunks(0, xml_stream_chunk::destroy); + auto_deleter > chunks(NULL, xml_stream_chunk::destroy); // read file to a chunk list size_t total = 0; - xml_stream_chunk* last = 0; + xml_stream_chunk* last = NULL; while (!stream.eof()) { @@ -5020,7 +5045,7 @@ PUGI_IMPL_NS_BEGIN template PUGI_IMPL_FN xml_parse_result load_stream_impl(xml_document_struct* doc, std::basic_istream& stream, unsigned int options, xml_encoding encoding, char_t** out_buffer) { - void* buffer = 0; + void* buffer = NULL; size_t size = 0; xml_parse_status status = status_ok; @@ -5047,9 +5072,17 @@ PUGI_IMPL_NS_BEGIN #if defined(PUGI_IMPL_MSVC_CRT_VERSION) || defined(__BORLANDC__) || (defined(__MINGW32__) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR))) PUGI_IMPL_FN FILE* open_file_wide(const wchar_t* path, const wchar_t* mode) { +#ifdef PUGIXML_NO_STL + // ensure these symbols are consistently referenced to avoid 'unreferenced function' warnings + // note that generally these functions are used in STL builds, but PUGIXML_NO_STL leaves the only usage in convert_path_heap + (void)&as_utf8_begin; + (void)&as_utf8_end; + (void)&strlength_wide; +#endif + #if defined(PUGI_IMPL_MSVC_CRT_VERSION) && PUGI_IMPL_MSVC_CRT_VERSION >= 1400 - FILE* file = 0; - return _wfopen_s(&file, path, mode) == 0 ? file : 0; + FILE* file = NULL; + return _wfopen_s(&file, path, mode) == 0 ? file : NULL; #else return _wfopen(path, mode); #endif @@ -5065,7 +5098,7 @@ PUGI_IMPL_NS_BEGIN // allocate resulting string char* result = static_cast(xml_memory::allocate(size + 1)); - if (!result) return 0; + if (!result) return NULL; // second pass: convert to utf8 as_utf8_end(result, size, str, length); @@ -5080,7 +5113,7 @@ PUGI_IMPL_NS_BEGIN { // there is no standard function to open wide paths, so our best bet is to try utf8 path char* path_utf8 = convert_path_heap(path); - if (!path_utf8) return 0; + if (!path_utf8) return NULL; // convert mode to ASCII (we mirror _wfopen interface) char mode_ascii[4] = {0}; @@ -5099,8 +5132,8 @@ PUGI_IMPL_NS_BEGIN PUGI_IMPL_FN FILE* open_file(const char* path, const char* mode) { #if defined(PUGI_IMPL_MSVC_CRT_VERSION) && PUGI_IMPL_MSVC_CRT_VERSION >= 1400 - FILE* file = 0; - return fopen_s(&file, path, mode) == 0 ? file : 0; + FILE* file = NULL; + return fopen_s(&file, path, mode) == 0 ? file : NULL; #else return fopen(path, mode); #endif @@ -5123,7 +5156,7 @@ PUGI_IMPL_NS_BEGIN name_null_sentry(xml_node_struct* node_): node(node_), name(node_->name) { - node->name = 0; + node->name = NULL; } ~name_null_sentry() @@ -5150,11 +5183,11 @@ namespace pugi } #ifndef PUGIXML_NO_STL - PUGI_IMPL_FN xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(&stream), wide_stream(0) + PUGI_IMPL_FN xml_writer_stream::xml_writer_stream(std::basic_ostream& stream): narrow_stream(&stream), wide_stream(NULL) { } - PUGI_IMPL_FN xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(0), wide_stream(&stream) + PUGI_IMPL_FN xml_writer_stream::xml_writer_stream(std::basic_ostream& stream): narrow_stream(NULL), wide_stream(&stream) { } @@ -5198,7 +5231,7 @@ namespace pugi return true; } - PUGI_IMPL_FN xml_attribute::xml_attribute(): _attr(0) + PUGI_IMPL_FN xml_attribute::xml_attribute(): _attr(NULL) { } @@ -5212,7 +5245,7 @@ namespace pugi PUGI_IMPL_FN xml_attribute::operator xml_attribute::unspecified_bool_type() const { - return _attr ? unspecified_bool_xml_attribute : 0; + return _attr ? unspecified_bool_xml_attribute : NULL; } PUGI_IMPL_FN bool xml_attribute::operator!() const @@ -5342,7 +5375,7 @@ namespace pugi PUGI_IMPL_FN size_t xml_attribute::hash_value() const { - return static_cast(reinterpret_cast(_attr) / sizeof(xml_attribute_struct)); + return reinterpret_cast(_attr) / sizeof(xml_attribute_struct); } PUGI_IMPL_FN xml_attribute_struct* xml_attribute::internal_object() const @@ -5398,6 +5431,14 @@ namespace pugi return *this; } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN xml_attribute& xml_attribute::operator=(string_view_t rhs) + { + set_value(rhs); + return *this; + } +#endif + #ifdef PUGIXML_HAS_LONG_LONG PUGI_IMPL_FN xml_attribute& xml_attribute::operator=(long long rhs) { @@ -5426,6 +5467,15 @@ namespace pugi return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs, size); } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN bool xml_attribute::set_name(string_view_t rhs) + { + if (!_attr) return false; + + return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs.data(), rhs.size()); + } +#endif + PUGI_IMPL_FN bool xml_attribute::set_value(const char_t* rhs) { if (!_attr) return false; @@ -5440,6 +5490,15 @@ namespace pugi return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, size); } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN bool xml_attribute::set_value(string_view_t rhs) + { + if (!_attr) return false; + + return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs.data(), rhs.size()); + } +#endif + PUGI_IMPL_FN bool xml_attribute::set_value(int rhs) { if (!_attr) return false; @@ -5531,7 +5590,7 @@ namespace pugi } #endif - PUGI_IMPL_FN xml_node::xml_node(): _root(0) + PUGI_IMPL_FN xml_node::xml_node(): _root(NULL) { } @@ -5545,7 +5604,7 @@ namespace pugi PUGI_IMPL_FN xml_node::operator xml_node::unspecified_bool_type() const { - return _root ? unspecified_bool_xml_node : 0; + return _root ? unspecified_bool_xml_node : NULL; } PUGI_IMPL_FN bool xml_node::operator!() const @@ -5555,22 +5614,22 @@ namespace pugi PUGI_IMPL_FN xml_node::iterator xml_node::begin() const { - return iterator(_root ? _root->first_child + 0 : 0, _root); + return iterator(_root ? _root->first_child + 0 : NULL, _root); } PUGI_IMPL_FN xml_node::iterator xml_node::end() const { - return iterator(0, _root); + return iterator(NULL, _root); } PUGI_IMPL_FN xml_node::attribute_iterator xml_node::attributes_begin() const { - return attribute_iterator(_root ? _root->first_attribute + 0 : 0, _root); + return attribute_iterator(_root ? _root->first_attribute + 0 : NULL, _root); } PUGI_IMPL_FN xml_node::attribute_iterator xml_node::attributes_end() const { - return attribute_iterator(0, _root); + return attribute_iterator(NULL, _root); } PUGI_IMPL_FN xml_object_range xml_node::children() const @@ -5580,7 +5639,7 @@ namespace pugi PUGI_IMPL_FN xml_object_range xml_node::children(const char_t* name_) const { - return xml_object_range(xml_named_node_iterator(child(name_)._root, _root, name_), xml_named_node_iterator(0, _root, name_)); + return xml_object_range(xml_named_node_iterator(child(name_)._root, _root, name_), xml_named_node_iterator(NULL, _root, name_)); } PUGI_IMPL_FN xml_object_range xml_node::attributes() const @@ -5703,6 +5762,64 @@ namespace pugi return xml_node(); } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN xml_node xml_node::child(string_view_t name_) const + { + if (!_root) return xml_node(); + + for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) + { + const char_t* iname = i->name; + if (iname && impl::stringview_equal(name_, iname)) + return xml_node(i); + } + + return xml_node(); + } + + PUGI_IMPL_FN xml_attribute xml_node::attribute(string_view_t name_) const + { + if (!_root) return xml_attribute(); + + for (xml_attribute_struct* i = _root->first_attribute; i; i = i->next_attribute) + { + const char_t* iname = i->name; + if (iname && impl::stringview_equal(name_, iname)) + return xml_attribute(i); + } + + return xml_attribute(); + } + + PUGI_IMPL_FN xml_node xml_node::next_sibling(string_view_t name_) const + { + if (!_root) return xml_node(); + + for (xml_node_struct* i = _root->next_sibling; i; i = i->next_sibling) + { + const char_t* iname = i->name; + if (iname && impl::stringview_equal(name_, iname)) + return xml_node(i); + } + + return xml_node(); + } + + PUGI_IMPL_FN xml_node xml_node::previous_sibling(string_view_t name_) const + { + if (!_root) return xml_node(); + + for (xml_node_struct* i = _root->prev_sibling_c; i->next_sibling; i = i->prev_sibling_c) + { + const char_t* iname = i->name; + if (iname && impl::stringview_equal(name_, iname)) + return xml_node(i); + } + + return xml_node(); + } +#endif + PUGI_IMPL_FN xml_attribute xml_node::attribute(const char_t* name_, xml_attribute& hint_) const { xml_attribute_struct* hint = hint_._attr; @@ -5742,6 +5859,47 @@ namespace pugi return xml_attribute(); } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN xml_attribute xml_node::attribute(string_view_t name_, xml_attribute& hint_) const + { + xml_attribute_struct* hint = hint_._attr; + + // if hint is not an attribute of node, behavior is not defined + assert(!hint || (_root && impl::is_attribute_of(hint, _root))); + + if (!_root) return xml_attribute(); + + // optimistically search from hint up until the end + for (xml_attribute_struct* i = hint; i; i = i->next_attribute) + { + const char_t* iname = i->name; + if (iname && impl::stringview_equal(name_, iname)) + { + // update hint to maximize efficiency of searching for consecutive attributes + hint_._attr = i->next_attribute; + + return xml_attribute(i); + } + } + + // wrap around and search from the first attribute until the hint + // 'j' null pointer check is technically redundant, but it prevents a crash in case the assertion above fails + for (xml_attribute_struct* j = _root->first_attribute; j && j != hint; j = j->next_attribute) + { + const char_t* jname = j->name; + if (jname && impl::stringview_equal(name_, jname)) + { + // update hint to maximize efficiency of searching for consecutive attributes + hint_._attr = j->next_attribute; + + return xml_attribute(j); + } + } + + return xml_attribute(); + } +#endif + PUGI_IMPL_FN xml_node xml_node::previous_sibling() const { if (!_root) return xml_node(); @@ -5833,6 +5991,18 @@ namespace pugi return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs, size); } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN bool xml_node::set_name(string_view_t rhs) + { + xml_node_type type_ = _root ? PUGI_IMPL_NODETYPE(_root) : node_null; + + if (type_ != node_element && type_ != node_pi && type_ != node_declaration) + return false; + + return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs.data(), rhs.size()); + } +#endif + PUGI_IMPL_FN bool xml_node::set_value(const char_t* rhs) { xml_node_type type_ = _root ? PUGI_IMPL_NODETYPE(_root) : node_null; @@ -5853,6 +6023,18 @@ namespace pugi return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs, size); } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN bool xml_node::set_value(string_view_t rhs) + { + xml_node_type type_ = _root ? PUGI_IMPL_NODETYPE(_root) : node_null; + + if (type_ != node_pcdata && type_ != node_cdata && type_ != node_comment && type_ != node_pi && type_ != node_doctype) + return false; + + return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs.data(), rhs.size()); + } +#endif + PUGI_IMPL_FN xml_attribute xml_node::append_attribute(const char_t* name_) { if (!impl::allow_insert_attribute(type())) return xml_attribute(); @@ -5923,6 +6105,78 @@ namespace pugi return a; } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN xml_attribute xml_node::append_attribute(string_view_t name_) + { + if (!impl::allow_insert_attribute(type())) return xml_attribute(); + + impl::xml_allocator& alloc = impl::get_allocator(_root); + if (!alloc.reserve()) return xml_attribute(); + + xml_attribute a(impl::allocate_attribute(alloc)); + if (!a) return xml_attribute(); + + impl::append_attribute(a._attr, _root); + + a.set_name(name_); + + return a; + } + + PUGI_IMPL_FN xml_attribute xml_node::prepend_attribute(string_view_t name_) + { + if (!impl::allow_insert_attribute(type())) return xml_attribute(); + + impl::xml_allocator& alloc = impl::get_allocator(_root); + if (!alloc.reserve()) return xml_attribute(); + + xml_attribute a(impl::allocate_attribute(alloc)); + if (!a) return xml_attribute(); + + impl::prepend_attribute(a._attr, _root); + + a.set_name(name_); + + return a; + } + + PUGI_IMPL_FN xml_attribute xml_node::insert_attribute_after(string_view_t name_, const xml_attribute& attr) + { + if (!impl::allow_insert_attribute(type())) return xml_attribute(); + if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute(); + + impl::xml_allocator& alloc = impl::get_allocator(_root); + if (!alloc.reserve()) return xml_attribute(); + + xml_attribute a(impl::allocate_attribute(alloc)); + if (!a) return xml_attribute(); + + impl::insert_attribute_after(a._attr, attr._attr, _root); + + a.set_name(name_); + + return a; + } + + PUGI_IMPL_FN xml_attribute xml_node::insert_attribute_before(string_view_t name_, const xml_attribute& attr) + { + if (!impl::allow_insert_attribute(type())) return xml_attribute(); + if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute(); + + impl::xml_allocator& alloc = impl::get_allocator(_root); + if (!alloc.reserve()) return xml_attribute(); + + xml_attribute a(impl::allocate_attribute(alloc)); + if (!a) return xml_attribute(); + + impl::insert_attribute_before(a._attr, attr._attr, _root); + + a.set_name(name_); + + return a; + } +#endif + PUGI_IMPL_FN xml_attribute xml_node::append_copy(const xml_attribute& proto) { if (!proto) return xml_attribute(); @@ -6099,6 +6353,44 @@ namespace pugi return result; } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN xml_node xml_node::append_child(string_view_t name_) + { + xml_node result = append_child(node_element); + + result.set_name(name_); + + return result; + } + + PUGI_IMPL_FN xml_node xml_node::prepend_child(string_view_t name_) + { + xml_node result = prepend_child(node_element); + + result.set_name(name_); + + return result; + } + + PUGI_IMPL_FN xml_node xml_node::insert_child_after(string_view_t name_, const xml_node& node) + { + xml_node result = insert_child_after(node_element, node); + + result.set_name(name_); + + return result; + } + + PUGI_IMPL_FN xml_node xml_node::insert_child_before(string_view_t name_, const xml_node& node) + { + xml_node result = insert_child_before(node_element, node); + + result.set_name(name_); + + return result; + } +#endif + PUGI_IMPL_FN xml_node xml_node::append_copy(const xml_node& proto) { xml_node_type type_ = proto.type(); @@ -6242,6 +6534,13 @@ namespace pugi return remove_attribute(attribute(name_)); } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN bool xml_node::remove_attribute(string_view_t name_) + { + return remove_attribute(attribute(name_)); + } +#endif + PUGI_IMPL_FN bool xml_node::remove_attribute(const xml_attribute& a) { if (!_root || !a._attr) return false; @@ -6272,7 +6571,7 @@ namespace pugi attr = next; } - _root->first_attribute = 0; + _root->first_attribute = NULL; return true; } @@ -6282,6 +6581,13 @@ namespace pugi return remove_child(child(name_)); } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN bool xml_node::remove_child(string_view_t name_) + { + return remove_child(child(name_)); + } +#endif + PUGI_IMPL_FN bool xml_node::remove_child(const xml_node& n) { if (!_root || !n._root || n._root->parent != _root) return false; @@ -6311,7 +6617,7 @@ namespace pugi cur = next; } - _root->first_child = 0; + _root->first_child = NULL; return true; } @@ -6331,7 +6637,7 @@ namespace pugi doc->header |= impl::xml_memory_page_contents_shared_mask; // get extra buffer element (we'll store the document fragment buffer there so that we can deallocate it later) - impl::xml_memory_page* page = 0; + impl::xml_memory_page* page = NULL; impl::xml_extra_buffer* extra = static_cast(doc->allocate_memory(sizeof(impl::xml_extra_buffer) + sizeof(void*), page)); (void)page; @@ -6344,7 +6650,7 @@ namespace pugi #endif // add extra buffer to the list - extra->buffer = 0; + extra->buffer = NULL; extra->next = doc->extra_buffers; doc->extra_buffers = extra; @@ -6484,7 +6790,7 @@ namespace pugi xml_node arg_begin(_root); if (!walker.begin(arg_begin)) return false; - xml_node_struct* cur = _root ? _root->first_child + 0 : 0; + xml_node_struct* cur = _root ? _root->first_child + 0 : NULL; if (cur) { @@ -6526,7 +6832,7 @@ namespace pugi PUGI_IMPL_FN size_t xml_node::hash_value() const { - return static_cast(reinterpret_cast(_root) / sizeof(xml_node_struct)); + return reinterpret_cast(_root) / sizeof(xml_node_struct); } PUGI_IMPL_FN xml_node_struct* xml_node::internal_object() const @@ -6546,14 +6852,14 @@ namespace pugi } #ifndef PUGIXML_NO_STL - PUGI_IMPL_FN void xml_node::print(std::basic_ostream >& stream, const char_t* indent, unsigned int flags, xml_encoding encoding, unsigned int depth) const + PUGI_IMPL_FN void xml_node::print(std::basic_ostream& stream, const char_t* indent, unsigned int flags, xml_encoding encoding, unsigned int depth) const { xml_writer_stream writer(stream); print(writer, indent, flags, encoding, depth); } - PUGI_IMPL_FN void xml_node::print(std::basic_ostream >& stream, const char_t* indent, unsigned int flags, unsigned int depth) const + PUGI_IMPL_FN void xml_node::print(std::basic_ostream& stream, const char_t* indent, unsigned int flags, unsigned int depth) const { xml_writer_stream writer(stream); @@ -6620,7 +6926,7 @@ namespace pugi if (impl::is_text_node(node)) return node; - return 0; + return NULL; } PUGI_IMPL_FN xml_node_struct* xml_text::_data_new() @@ -6631,7 +6937,7 @@ namespace pugi return xml_node(_root).append_child(node_pcdata).internal_object(); } - PUGI_IMPL_FN xml_text::xml_text(): _root(0) + PUGI_IMPL_FN xml_text::xml_text(): _root(NULL) { } @@ -6641,7 +6947,7 @@ namespace pugi PUGI_IMPL_FN xml_text::operator xml_text::unspecified_bool_type() const { - return _data() ? unspecified_bool_xml_text : 0; + return _data() ? unspecified_bool_xml_text : NULL; } PUGI_IMPL_FN bool xml_text::operator!() const @@ -6651,7 +6957,7 @@ namespace pugi PUGI_IMPL_FN bool xml_text::empty() const { - return _data() == 0; + return _data() == NULL; } PUGI_IMPL_FN const char_t* xml_text::get() const @@ -6742,6 +7048,15 @@ namespace pugi return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, size) : false; } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN bool xml_text::set(string_view_t rhs) + { + xml_node_struct* dn = _data_new(); + + return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs.data(), rhs.size()) : false; + } +#endif + PUGI_IMPL_FN bool xml_text::set(int rhs) { xml_node_struct* dn = _data_new(); @@ -6869,6 +7184,14 @@ namespace pugi return *this; } +#ifdef PUGIXML_HAS_STRING_VIEW + PUGI_IMPL_FN xml_text& xml_text::operator=(string_view_t rhs) + { + set(rhs); + return *this; + } +#endif + #ifdef PUGIXML_HAS_LONG_LONG PUGI_IMPL_FN xml_text& xml_text::operator=(long long rhs) { @@ -6931,7 +7254,7 @@ namespace pugi PUGI_IMPL_FN xml_node* xml_node_iterator::operator->() const { assert(_wrap._root); - return const_cast(&_wrap); // BCC5 workaround + return &_wrap; } PUGI_IMPL_FN xml_node_iterator& xml_node_iterator::operator++() @@ -6992,7 +7315,7 @@ namespace pugi PUGI_IMPL_FN xml_attribute* xml_attribute_iterator::operator->() const { assert(_wrap._attr); - return const_cast(&_wrap); // BCC5 workaround + return &_wrap; } PUGI_IMPL_FN xml_attribute_iterator& xml_attribute_iterator::operator++() @@ -7022,7 +7345,7 @@ namespace pugi return temp; } - PUGI_IMPL_FN xml_named_node_iterator::xml_named_node_iterator(): _name(0) + PUGI_IMPL_FN xml_named_node_iterator::xml_named_node_iterator(): _name(NULL) { } @@ -7053,7 +7376,7 @@ namespace pugi PUGI_IMPL_FN xml_node* xml_named_node_iterator::operator->() const { assert(_wrap._root); - return const_cast(&_wrap); // BCC5 workaround + return &_wrap; } PUGI_IMPL_FN xml_named_node_iterator& xml_named_node_iterator::operator++() @@ -7132,7 +7455,7 @@ namespace pugi } } - PUGI_IMPL_FN xml_document::xml_document(): _buffer(0) + PUGI_IMPL_FN xml_document::xml_document(): _buffer(NULL) { _create(); } @@ -7143,7 +7466,7 @@ namespace pugi } #ifdef PUGIXML_HAS_MOVE - PUGI_IMPL_FN xml_document::xml_document(xml_document&& rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT: _buffer(0) + PUGI_IMPL_FN xml_document::xml_document(xml_document&& rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT: _buffer(NULL) { _create(); _move(rhs); @@ -7225,7 +7548,7 @@ namespace pugi if (_buffer) { impl::xml_memory::deallocate(_buffer); - _buffer = 0; + _buffer = NULL; } // destroy extra buffers (note: no need to destroy linked list nodes, they're allocated using document allocator) @@ -7253,7 +7576,7 @@ namespace pugi static_cast(_root)->hash.clear(); #endif - _root = 0; + _root = NULL; } #ifdef PUGIXML_HAS_MOVE @@ -7308,7 +7631,7 @@ namespace pugi doc->_hash = &doc->hash; // make sure we don't access other hash up until the end when we reinitialize other document - other->_hash = 0; + other->_hash = NULL; #endif // move page structure @@ -7326,7 +7649,7 @@ namespace pugi page->prev = doc_page; doc_page->next = page; - other_page->next = 0; + other_page->next = NULL; } // make sure pages point to the correct document state @@ -7363,19 +7686,19 @@ namespace pugi // reset other document new (other) impl::xml_document_struct(PUGI_IMPL_GETPAGE(other)); - rhs._buffer = 0; + rhs._buffer = NULL; } #endif #ifndef PUGIXML_NO_STL - PUGI_IMPL_FN xml_parse_result xml_document::load(std::basic_istream >& stream, unsigned int options, xml_encoding encoding) + PUGI_IMPL_FN xml_parse_result xml_document::load(std::basic_istream& stream, unsigned int options, xml_encoding encoding) { reset(); return impl::load_stream_impl(static_cast(_root), stream, options, encoding, &_buffer); } - PUGI_IMPL_FN xml_parse_result xml_document::load(std::basic_istream >& stream, unsigned int options) + PUGI_IMPL_FN xml_parse_result xml_document::load(std::basic_istream& stream, unsigned int options) { reset(); @@ -7445,7 +7768,7 @@ namespace pugi { impl::xml_buffered_writer buffered_writer(writer, encoding); - if ((flags & format_write_bom) && encoding != encoding_latin1) + if ((flags & format_write_bom) && buffered_writer.encoding != encoding_latin1) { // BOM always represents the codepoint U+FEFF, so just write it in native encoding #ifdef PUGIXML_WCHAR_MODE @@ -7459,7 +7782,7 @@ namespace pugi if (!(flags & format_no_declaration) && !impl::has_declaration(_root)) { buffered_writer.write_string(PUGIXML_TEXT("'); if (!(flags & format_raw)) buffered_writer.write('\n'); } @@ -7470,14 +7793,14 @@ namespace pugi } #ifndef PUGIXML_NO_STL - PUGI_IMPL_FN void xml_document::save(std::basic_ostream >& stream, const char_t* indent, unsigned int flags, xml_encoding encoding) const + PUGI_IMPL_FN void xml_document::save(std::basic_ostream& stream, const char_t* indent, unsigned int flags, xml_encoding encoding) const { xml_writer_stream writer(stream); save(writer, indent, flags, encoding); } - PUGI_IMPL_FN void xml_document::save(std::basic_ostream >& stream, const char_t* indent, unsigned int flags) const + PUGI_IMPL_FN void xml_document::save(std::basic_ostream& stream, const char_t* indent, unsigned int flags) const { xml_writer_stream writer(stream); @@ -7790,7 +8113,7 @@ PUGI_IMPL_NS_BEGIN for (size_t probe = 0; probe <= hashmod; ++probe) { - if (table[bucket] == 0) + if (table[bucket] == NULL) { table[bucket] = key; return true; @@ -7838,7 +8161,7 @@ PUGI_IMPL_NS_BEGIN size_t _root_size; bool* _error; - xpath_allocator(xpath_memory_block* root, bool* error = 0): _root(root), _root_size(0), _error(error) + xpath_allocator(xpath_memory_block* root, bool* error = NULL): _root(root), _root_size(0), _error(error) { } @@ -7866,7 +8189,7 @@ PUGI_IMPL_NS_BEGIN if (!block) { if (_error) *_error = true; - return 0; + return NULL; } block->next = _root; @@ -7886,7 +8209,7 @@ PUGI_IMPL_NS_BEGIN new_size = (new_size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1); // we can only reallocate the last object - assert(ptr == 0 || static_cast(ptr) + old_size == &_root->data[0] + _root_size); + assert(ptr == NULL || static_cast(ptr) + old_size == &_root->data[0] + _root_size); // try to reallocate the object inplace if (ptr && _root_size - old_size + new_size <= _root->capacity) @@ -7897,7 +8220,7 @@ PUGI_IMPL_NS_BEGIN // allocate a new block void* result = allocate(new_size); - if (!result) return 0; + if (!result) return NULL; // we have a new block if (ptr) @@ -7992,7 +8315,7 @@ PUGI_IMPL_NS_BEGIN xpath_stack_data(): result(blocks + 0, &oom), temp(blocks + 1, &oom), oom(false) { - blocks[0].next = blocks[1].next = 0; + blocks[0].next = blocks[1].next = NULL; blocks[0].capacity = blocks[1].capacity = sizeof(blocks[0].data); stack.result = &result; @@ -8018,7 +8341,7 @@ PUGI_IMPL_NS_BEGIN static char_t* duplicate_string(const char_t* string, size_t length, xpath_allocator* alloc) { char_t* result = static_cast(alloc->allocate((length + 1) * sizeof(char_t))); - if (!result) return 0; + if (!result) return NULL; memcpy(result, string, length * sizeof(char_t)); result[length] = 0; @@ -8078,7 +8401,7 @@ PUGI_IMPL_NS_BEGIN size_t result_length = target_length + source_length; // allocate new buffer - char_t* result = static_cast(alloc->reallocate(_uses_heap ? const_cast(_buffer) : 0, (target_length + 1) * sizeof(char_t), (result_length + 1) * sizeof(char_t))); + char_t* result = static_cast(alloc->reallocate(_uses_heap ? const_cast(_buffer) : NULL, (target_length + 1) * sizeof(char_t), (result_length + 1) * sizeof(char_t))); if (!result) return; // append first string to the new buffer in case there was no reallocation @@ -8113,7 +8436,7 @@ PUGI_IMPL_NS_BEGIN size_t length_ = strlength(_buffer); const char_t* data_ = duplicate_string(_buffer, length_, alloc); - if (!data_) return 0; + if (!data_) return NULL; _buffer = data_; _uses_heap = true; @@ -8322,7 +8645,7 @@ PUGI_IMPL_NS_BEGIN if (node->value && (node->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0) return node->value; } - return 0; + return NULL; } xml_attribute_struct* attr = xnode.attribute().internal_object(); @@ -8335,10 +8658,10 @@ PUGI_IMPL_NS_BEGIN if ((attr->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0) return attr->value; } - return 0; + return NULL; } - return 0; + return NULL; } struct document_order_comparator @@ -8451,7 +8774,7 @@ PUGI_IMPL_NS_BEGIN if (v == 0) return PUGIXML_TEXT("0"); if (v != v) return PUGIXML_TEXT("NaN"); if (v * 2 == v) return value > 0 ? PUGIXML_TEXT("Infinity") : PUGIXML_TEXT("-Infinity"); - return 0; + return NULL; #endif } @@ -8616,9 +8939,9 @@ PUGI_IMPL_NS_BEGIN // parse string #ifdef PUGIXML_WCHAR_MODE - return wcstod(string, 0); + return wcstod(string, NULL); #else - return strtod(string, 0); + return strtod(string, NULL); #endif } @@ -8680,7 +9003,7 @@ PUGI_IMPL_NS_BEGIN { const char_t* pos = find_char(name, ':'); - prefix = pos ? name : 0; + prefix = pos ? name : NULL; prefix_length = pos ? static_cast(pos - name) : 0; } @@ -8798,7 +9121,7 @@ PUGI_IMPL_NS_BEGIN unsigned int tc = static_cast(*to); if (fc >= 128 || tc >= 128) - return 0; + return NULL; // code=128 means "skip character" if (!table[fc]) @@ -8813,7 +9136,7 @@ PUGI_IMPL_NS_BEGIN table[i] = static_cast(i); void* result = alloc->allocate(sizeof(table)); - if (!result) return 0; + if (!result) return NULL; memcpy(result, table, sizeof(table)); @@ -8877,7 +9200,7 @@ PUGI_IMPL_NS_BEGIN struct xpath_variable_string: xpath_variable { - xpath_variable_string(): xpath_variable(xpath_type_string), value(0) + xpath_variable_string(): xpath_variable(xpath_type_string), value(NULL) { } @@ -8924,11 +9247,11 @@ PUGI_IMPL_NS_BEGIN template PUGI_IMPL_FN T* new_xpath_variable(const char_t* name) { size_t length = strlength(name); - if (length == 0) return 0; // empty variable names are invalid + if (length == 0) return NULL; // empty variable names are invalid // $$ we can't use offsetof(T, name) because T is non-POD, so we just allocate additional length characters void* memory = xml_memory::allocate(sizeof(T) + length * sizeof(char_t)); - if (!memory) return 0; + if (!memory) return NULL; T* result = new (memory) T(); @@ -8954,7 +9277,7 @@ PUGI_IMPL_NS_BEGIN return new_xpath_variable(name); default: - return 0; + return NULL; } } @@ -9107,7 +9430,7 @@ PUGI_IMPL_NS_BEGIN xpath_node* _eos; public: - xpath_node_set_raw(): _type(xpath_node_set::type_unsorted), _begin(0), _end(0), _eos(0) + xpath_node_set_raw(): _type(xpath_node_set::type_unsorted), _begin(NULL), _end(NULL), _eos(NULL) { } @@ -9299,7 +9622,7 @@ PUGI_IMPL_NS_BEGIN const char_t* begin; const char_t* end; - xpath_lexer_string(): begin(0), end(0) + xpath_lexer_string(): begin(NULL), end(NULL) { } @@ -10487,40 +10810,40 @@ PUGI_IMPL_NS_BEGIN public: xpath_ast_node(ast_type_t type, xpath_value_type rettype_, const char_t* value): - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(NULL), _right(NULL), _next(NULL) { assert(type == ast_string_constant); _data.string = value; } xpath_ast_node(ast_type_t type, xpath_value_type rettype_, double value): - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(NULL), _right(NULL), _next(NULL) { assert(type == ast_number_constant); _data.number = value; } xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_variable* value): - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(NULL), _right(NULL), _next(NULL) { assert(type == ast_variable); _data.variable = value; } - xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_ast_node* left = 0, xpath_ast_node* right = 0): - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(left), _right(right), _next(0) + xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_ast_node* left = NULL, xpath_ast_node* right = NULL): + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(left), _right(right), _next(NULL) { } xpath_ast_node(ast_type_t type, xpath_ast_node* left, axis_t axis, nodetest_t test, const char_t* contents): - _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(static_cast(axis)), _test(static_cast(test)), _left(left), _right(0), _next(0) + _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(static_cast(axis)), _test(static_cast(test)), _left(left), _right(NULL), _next(NULL) { assert(type == ast_step); _data.nodetest = contents; } xpath_ast_node(ast_type_t type, xpath_ast_node* left, xpath_ast_node* right, predicate_t test): - _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(0), _test(static_cast(test)), _left(left), _right(right), _next(0) + _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(0), _test(static_cast(test)), _left(left), _right(right), _next(NULL) { assert(type == ast_filter || type == ast_predicate); } @@ -10580,7 +10903,7 @@ PUGI_IMPL_NS_BEGIN xpath_string lr = _left->eval_string(c, stack); xpath_string rr = _right->eval_string(c, stack); - return find_substring(lr.c_str(), rr.c_str()) != 0; + return find_substring(lr.c_str(), rr.c_str()) != NULL; } case ast_func_boolean: @@ -11389,7 +11712,7 @@ PUGI_IMPL_NS_BEGIN _result->error = message; _result->offset = _lexer.current_pos() - _query; - return 0; + return NULL; } xpath_ast_node* error_oom() @@ -11397,7 +11720,7 @@ PUGI_IMPL_NS_BEGIN assert(_alloc->_error); *_alloc->_error = true; - return 0; + return NULL; } xpath_ast_node* error_rec() @@ -11413,37 +11736,37 @@ PUGI_IMPL_NS_BEGIN xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, const char_t* value) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, rettype, value) : 0; + return memory ? new (memory) xpath_ast_node(type, rettype, value) : NULL; } xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, double value) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, rettype, value) : 0; + return memory ? new (memory) xpath_ast_node(type, rettype, value) : NULL; } xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, xpath_variable* value) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, rettype, value) : 0; + return memory ? new (memory) xpath_ast_node(type, rettype, value) : NULL; } - xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, xpath_ast_node* left = 0, xpath_ast_node* right = 0) + xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, xpath_ast_node* left = NULL, xpath_ast_node* right = NULL) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, rettype, left, right) : 0; + return memory ? new (memory) xpath_ast_node(type, rettype, left, right) : NULL; } xpath_ast_node* alloc_node(ast_type_t type, xpath_ast_node* left, axis_t axis, nodetest_t test, const char_t* contents) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, left, axis, test, contents) : 0; + return memory ? new (memory) xpath_ast_node(type, left, axis, test, contents) : NULL; } xpath_ast_node* alloc_node(ast_type_t type, xpath_ast_node* left, xpath_ast_node* right, predicate_t test) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, left, right, test) : 0; + return memory ? new (memory) xpath_ast_node(type, left, right, test) : NULL; } const char_t* alloc_string(const xpath_lexer_string& value) @@ -11454,7 +11777,7 @@ PUGI_IMPL_NS_BEGIN size_t length = static_cast(value.end - value.begin); char_t* c = static_cast(_alloc->allocate((length + 1) * sizeof(char_t))); - if (!c) return 0; + if (!c) return NULL; memcpy(c, value.begin, length * sizeof(char_t)); c[length] = 0; @@ -11697,7 +12020,7 @@ PUGI_IMPL_NS_BEGIN if (!_variables) return error("Unknown variable: variable set is not provided"); - xpath_variable* var = 0; + xpath_variable* var = NULL; if (!get_variable_scratch(_scratch, _variables, name.begin, name.end, &var)) return error_oom(); @@ -11714,7 +12037,7 @@ PUGI_IMPL_NS_BEGIN _lexer.next(); xpath_ast_node* n = parse_expression(); - if (!n) return 0; + if (!n) return NULL; if (_lexer.current() != lex_close_brace) return error("Expected ')' to match an opening '('"); @@ -11727,7 +12050,7 @@ PUGI_IMPL_NS_BEGIN case lex_quoted_string: { const char_t* value = alloc_string(_lexer.contents()); - if (!value) return 0; + if (!value) return NULL; _lexer.next(); @@ -11748,13 +12071,13 @@ PUGI_IMPL_NS_BEGIN case lex_string: { - xpath_ast_node* args[2] = {0}; + xpath_ast_node* args[2] = {NULL}; size_t argc = 0; xpath_lexer_string function = _lexer.contents(); _lexer.next(); - xpath_ast_node* last_arg = 0; + xpath_ast_node* last_arg = NULL; if (_lexer.current() != lex_open_brace) return error("Unrecognized function call"); @@ -11775,7 +12098,7 @@ PUGI_IMPL_NS_BEGIN return error_rec(); xpath_ast_node* n = parse_expression(); - if (!n) return 0; + if (!n) return NULL; if (argc < 2) args[argc] = n; else last_arg->set_next(n); @@ -11802,7 +12125,7 @@ PUGI_IMPL_NS_BEGIN xpath_ast_node* parse_filter_expression() { xpath_ast_node* n = parse_primary_expression(); - if (!n) return 0; + if (!n) return NULL; size_t old_depth = _depth; @@ -11817,10 +12140,10 @@ PUGI_IMPL_NS_BEGIN return error("Predicate has to be applied to node set"); xpath_ast_node* expr = parse_expression(); - if (!expr) return 0; + if (!expr) return NULL; n = alloc_node(ast_filter, n, expr, predicate_default); - if (!n) return 0; + if (!n) return NULL; if (_lexer.current() != lex_close_square_brace) return error("Expected ']' to match an opening '['"); @@ -11860,7 +12183,7 @@ PUGI_IMPL_NS_BEGIN if (_lexer.current() == lex_open_square_brace) return error("Predicates are not allowed after an abbreviated step"); - return alloc_node(ast_step, set, axis_self, nodetest_type_node, 0); + return alloc_node(ast_step, set, axis_self, nodetest_type_node, NULL); } else if (_lexer.current() == lex_double_dot) { @@ -11869,7 +12192,7 @@ PUGI_IMPL_NS_BEGIN if (_lexer.current() == lex_open_square_brace) return error("Predicates are not allowed after an abbreviated step"); - return alloc_node(ast_step, set, axis_parent, nodetest_type_node, 0); + return alloc_node(ast_step, set, axis_parent, nodetest_type_node, NULL); } nodetest_t nt_type = nodetest_none; @@ -11976,14 +12299,14 @@ PUGI_IMPL_NS_BEGIN } const char_t* nt_name_copy = alloc_string(nt_name); - if (!nt_name_copy) return 0; + if (!nt_name_copy) return NULL; xpath_ast_node* n = alloc_node(ast_step, set, axis, nt_type, nt_name_copy); - if (!n) return 0; + if (!n) return NULL; size_t old_depth = _depth; - xpath_ast_node* last = 0; + xpath_ast_node* last = NULL; while (_lexer.current() == lex_open_square_brace) { @@ -11993,10 +12316,10 @@ PUGI_IMPL_NS_BEGIN return error_rec(); xpath_ast_node* expr = parse_expression(); - if (!expr) return 0; + if (!expr) return NULL; - xpath_ast_node* pred = alloc_node(ast_predicate, 0, expr, predicate_default); - if (!pred) return 0; + xpath_ast_node* pred = alloc_node(ast_predicate, NULL, expr, predicate_default); + if (!pred) return NULL; if (_lexer.current() != lex_close_square_brace) return error("Expected ']' to match an opening '['"); @@ -12017,7 +12340,7 @@ PUGI_IMPL_NS_BEGIN xpath_ast_node* parse_relative_location_path(xpath_ast_node* set) { xpath_ast_node* n = parse_step(set); - if (!n) return 0; + if (!n) return NULL; size_t old_depth = _depth; @@ -12028,8 +12351,8 @@ PUGI_IMPL_NS_BEGIN if (l == lex_double_slash) { - n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); - if (!n) return 0; + n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, NULL); + if (!n) return NULL; ++_depth; } @@ -12038,7 +12361,7 @@ PUGI_IMPL_NS_BEGIN return error_rec(); n = parse_step(n); - if (!n) return 0; + if (!n) return NULL; } _depth = old_depth; @@ -12055,7 +12378,7 @@ PUGI_IMPL_NS_BEGIN _lexer.next(); xpath_ast_node* n = alloc_node(ast_step_root, xpath_type_node_set); - if (!n) return 0; + if (!n) return NULL; // relative location path can start from axis_attribute, dot, double_dot, multiply and string lexemes; any other lexeme means standalone root path lexeme_t l = _lexer.current(); @@ -12070,16 +12393,16 @@ PUGI_IMPL_NS_BEGIN _lexer.next(); xpath_ast_node* n = alloc_node(ast_step_root, xpath_type_node_set); - if (!n) return 0; + if (!n) return NULL; - n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); - if (!n) return 0; + n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, NULL); + if (!n) return NULL; return parse_relative_location_path(n); } // else clause moved outside of if because of bogus warning 'control may reach end of non-void function being inlined' in gcc 4.0.1 - return parse_relative_location_path(0); + return parse_relative_location_path(NULL); } // PathExpr ::= LocationPath @@ -12116,7 +12439,7 @@ PUGI_IMPL_NS_BEGIN } xpath_ast_node* n = parse_filter_expression(); - if (!n) return 0; + if (!n) return NULL; if (_lexer.current() == lex_slash || _lexer.current() == lex_double_slash) { @@ -12128,8 +12451,8 @@ PUGI_IMPL_NS_BEGIN if (n->rettype() != xpath_type_node_set) return error("Step has to be applied to node set"); - n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); - if (!n) return 0; + n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, NULL); + if (!n) return NULL; } // select from location path @@ -12144,7 +12467,7 @@ PUGI_IMPL_NS_BEGIN // precedence 7+ - only parses union expressions xpath_ast_node* n = parse_expression(7); - if (!n) return 0; + if (!n) return NULL; return alloc_node(ast_op_negate, xpath_type_number, n); } @@ -12232,14 +12555,14 @@ PUGI_IMPL_NS_BEGIN return error_rec(); xpath_ast_node* rhs = parse_path_or_unary_expression(); - if (!rhs) return 0; + if (!rhs) return NULL; binary_op_t nextop = binary_op_t::parse(_lexer); while (nextop.asttype != ast_unknown && nextop.precedence > op.precedence) { rhs = parse_expression_rec(rhs, nextop.precedence); - if (!rhs) return 0; + if (!rhs) return NULL; nextop = binary_op_t::parse(_lexer); } @@ -12248,7 +12571,7 @@ PUGI_IMPL_NS_BEGIN return error("Union operator has to be applied to node sets"); lhs = alloc_node(op.asttype, op.rettype, lhs, rhs); - if (!lhs) return 0; + if (!lhs) return NULL; op = binary_op_t::parse(_lexer); } @@ -12282,7 +12605,7 @@ PUGI_IMPL_NS_BEGIN return error_rec(); xpath_ast_node* n = parse_path_or_unary_expression(); - if (!n) return 0; + if (!n) return NULL; n = parse_expression_rec(n, limit); @@ -12298,7 +12621,7 @@ PUGI_IMPL_NS_BEGIN xpath_ast_node* parse() { xpath_ast_node* n = parse_expression(); - if (!n) return 0; + if (!n) return NULL; assert(_depth == 0); @@ -12322,7 +12645,7 @@ PUGI_IMPL_NS_BEGIN static xpath_query_impl* create() { void* memory = xml_memory::allocate(sizeof(xpath_query_impl)); - if (!memory) return 0; + if (!memory) return NULL; return new (memory) xpath_query_impl(); } @@ -12336,9 +12659,9 @@ PUGI_IMPL_NS_BEGIN xml_memory::deallocate(impl); } - xpath_query_impl(): root(0), alloc(&block, &oom), oom(false) + xpath_query_impl(): root(NULL), alloc(&block, &oom), oom(false) { - block.next = 0; + block.next = NULL; block.capacity = sizeof(block.data); } @@ -12350,7 +12673,7 @@ PUGI_IMPL_NS_BEGIN PUGI_IMPL_FN impl::xpath_ast_node* evaluate_node_set_prepare(xpath_query_impl* impl) { - if (!impl) return 0; + if (!impl) return NULL; if (impl->root->rettype() != xpath_type_node_set) { @@ -12376,7 +12699,7 @@ namespace pugi assert(_result.error); } - PUGI_IMPL_FN const char* xpath_exception::what() const throw() + PUGI_IMPL_FN const char* xpath_exception::what() const PUGIXML_NOEXCEPT { return _result.error; } @@ -12420,7 +12743,7 @@ namespace pugi PUGI_IMPL_FN xpath_node::operator xpath_node::unspecified_bool_type() const { - return (_node || _attribute) ? unspecified_bool_xpath_node : 0; + return (_node || _attribute) ? unspecified_bool_xpath_node : NULL; } PUGI_IMPL_FN bool xpath_node::operator!() const @@ -12590,7 +12913,7 @@ namespace pugi PUGI_IMPL_FN xpath_parse_result::operator bool() const { - return error == 0; + return error == NULL; } PUGI_IMPL_FN const char* xpath_parse_result::description() const @@ -12598,7 +12921,7 @@ namespace pugi return error ? error : "No error"; } - PUGI_IMPL_FN xpath_variable::xpath_variable(xpath_value_type type_): _type(type_), _next(0) + PUGI_IMPL_FN xpath_variable::xpath_variable(xpath_value_type type_): _type(type_), _next(NULL) { } @@ -12620,7 +12943,7 @@ namespace pugi default: assert(false && "Invalid variable type"); // unreachable - return 0; + return NULL; } } @@ -12641,7 +12964,7 @@ namespace pugi PUGI_IMPL_FN const char_t* xpath_variable::get_string() const { - const char_t* value = (_type == xpath_type_string) ? static_cast(this)->value : 0; + const char_t* value = (_type == xpath_type_string) ? static_cast(this)->value : NULL; return value ? value : PUGIXML_TEXT(""); } @@ -12698,7 +13021,7 @@ namespace pugi PUGI_IMPL_FN xpath_variable_set::xpath_variable_set() { for (size_t i = 0; i < sizeof(_data) / sizeof(_data[0]); ++i) - _data[i] = 0; + _data[i] = NULL; } PUGI_IMPL_FN xpath_variable_set::~xpath_variable_set() @@ -12710,7 +13033,7 @@ namespace pugi PUGI_IMPL_FN xpath_variable_set::xpath_variable_set(const xpath_variable_set& rhs) { for (size_t i = 0; i < sizeof(_data) / sizeof(_data[0]); ++i) - _data[i] = 0; + _data[i] = NULL; _assign(rhs); } @@ -12730,7 +13053,7 @@ namespace pugi for (size_t i = 0; i < sizeof(_data) / sizeof(_data[0]); ++i) { _data[i] = rhs._data[i]; - rhs._data[i] = 0; + rhs._data[i] = NULL; } } @@ -12741,7 +13064,7 @@ namespace pugi _destroy(_data[i]); _data[i] = rhs._data[i]; - rhs._data[i] = 0; + rhs._data[i] = NULL; } return *this; @@ -12780,12 +13103,12 @@ namespace pugi if (impl::strequal(var->name(), name)) return var; - return 0; + return NULL; } PUGI_IMPL_FN bool xpath_variable_set::_clone(xpath_variable* var, xpath_variable** out_result) { - xpath_variable* last = 0; + xpath_variable* last = NULL; while (var) { @@ -12830,7 +13153,7 @@ namespace pugi // look for existing variable for (xpath_variable* var = _data[hash]; var; var = var->_next) if (impl::strequal(var->name(), name)) - return var->type() == type ? var : 0; + return var->type() == type ? var : NULL; // add new variable xpath_variable* result = impl::new_xpath_variable(type, name); @@ -12879,7 +13202,7 @@ namespace pugi return _find(name); } - PUGI_IMPL_FN xpath_query::xpath_query(const char_t* query, xpath_variable_set* variables): _impl(0) + PUGI_IMPL_FN xpath_query::xpath_query(const char_t* query, xpath_variable_set* variables): _impl(NULL) { impl::xpath_query_impl* qimpl = impl::xpath_query_impl::create(); @@ -12903,7 +13226,7 @@ namespace pugi qimpl->root->optimize(&qimpl->alloc); _impl = impl.release(); - _result.error = 0; + _result.error = NULL; } else { @@ -12917,7 +13240,7 @@ namespace pugi } } - PUGI_IMPL_FN xpath_query::xpath_query(): _impl(0) + PUGI_IMPL_FN xpath_query::xpath_query(): _impl(NULL) { } @@ -12932,7 +13255,7 @@ namespace pugi { _impl = rhs._impl; _result = rhs._result; - rhs._impl = 0; + rhs._impl = NULL; rhs._result = xpath_parse_result(); } @@ -12945,7 +13268,7 @@ namespace pugi _impl = rhs._impl; _result = rhs._result; - rhs._impl = 0; + rhs._impl = NULL; rhs._result = xpath_parse_result(); return *this; @@ -13109,7 +13432,7 @@ namespace pugi PUGI_IMPL_FN xpath_query::operator xpath_query::unspecified_bool_type() const { - return _impl ? unspecified_bool_xpath_query : 0; + return _impl ? unspecified_bool_xpath_query : NULL; } PUGI_IMPL_FN bool xpath_query::operator!() const @@ -13157,16 +13480,20 @@ namespace pugi # pragma option pop #endif +#if defined(_MSC_VER) && defined(__c2__) +# pragma clang diagnostic pop +#endif + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + // Intel C++ does not properly keep warning state for function templates, // so popping warning state at the end of translation unit leads to warnings in the middle. #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) # pragma warning(pop) #endif -#if defined(_MSC_VER) && defined(__c2__) -# pragma clang diagnostic pop -#endif - // Undefine all local macros (makes sure we're not leaking macros in header-only mode) #undef PUGI_IMPL_NO_INLINE #undef PUGI_IMPL_UNLIKELY @@ -13201,7 +13528,7 @@ namespace pugi #endif /** - * Copyright (c) 2006-2023 Arseny Kapoulkine + * Copyright (c) 2006-2025 Arseny Kapoulkine * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/thirdparty/pugixml/pugixml/src/pugixml.hpp b/thirdparty/pugixml/pugixml/src/pugixml.hpp index d17a7e6930..74e884b53e 100644 --- a/thirdparty/pugixml/pugixml/src/pugixml.hpp +++ b/thirdparty/pugixml/pugixml/src/pugixml.hpp @@ -1,7 +1,7 @@ /** - * pugixml parser - version 1.14 + * pugixml parser - version 1.15 * -------------------------------------------------------- - * Copyright (C) 2006-2023, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) + * Copyright (C) 2006-2025, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) * Report bugs and download new versions at https://pugixml.org/ * * This library is distributed under the MIT License. See notice at the end @@ -14,7 +14,7 @@ // 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 #ifndef PUGIXML_VERSION -# define PUGIXML_VERSION 1140 // 1.14 +# define PUGIXML_VERSION 1150 // 1.15 #endif // Include user configuration file (this can define various configuration macros) @@ -38,6 +38,20 @@ # include #endif +// Check if std::string_view is available +#if !defined(PUGIXML_HAS_STRING_VIEW) && !defined(PUGIXML_NO_STL) +# if __cplusplus >= 201703L +# define PUGIXML_HAS_STRING_VIEW +# elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L +# define PUGIXML_HAS_STRING_VIEW +# endif +#endif + +// Include string_view if appropriate +#ifdef PUGIXML_HAS_STRING_VIEW +# include +#endif + // Macro for deprecated features #ifndef PUGIXML_DEPRECATED # if defined(__GNUC__) @@ -82,14 +96,14 @@ # endif #endif -// If C++ is 2011 or higher, add 'noexcept' specifiers +// If C++ is 2011 or higher, use 'noexcept' specifiers #ifndef PUGIXML_NOEXCEPT # if __cplusplus >= 201103 # define PUGIXML_NOEXCEPT noexcept # elif defined(_MSC_VER) && _MSC_VER >= 1900 # define PUGIXML_NOEXCEPT noexcept # else -# define PUGIXML_NOEXCEPT +# define PUGIXML_NOEXCEPT throw() # endif #endif @@ -138,7 +152,12 @@ namespace pugi #ifndef PUGIXML_NO_STL // String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE - typedef std::basic_string, std::allocator > string_t; + typedef std::basic_string string_t; +#endif + +#ifdef PUGIXML_HAS_STRING_VIEW + // String view type used for operations that can work with a length delimited string; depends on PUGIXML_WCHAR_MODE + typedef std::basic_string_view string_view_t; #endif } @@ -212,7 +231,7 @@ namespace pugi // the document; this flag is only recommended for parsing documents with many PCDATA nodes in memory-constrained environments. // This flag is off by default. const unsigned int parse_embed_pcdata = 0x2000; - + // This flag determines whether determines whether the the two pcdata should be merged or not, if no intermediatory data are parsed in the document. // This flag is off by default. const unsigned int parse_merge_pcdata = 0x4000; @@ -353,14 +372,14 @@ namespace pugi { public: // Construct writer from an output stream object - xml_writer_stream(std::basic_ostream >& stream); - xml_writer_stream(std::basic_ostream >& stream); + xml_writer_stream(std::basic_ostream& stream); + xml_writer_stream(std::basic_ostream& stream); virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE; private: - std::basic_ostream >* narrow_stream; - std::basic_ostream >* wide_stream; + std::basic_ostream* narrow_stream; + std::basic_ostream* wide_stream; }; #endif @@ -396,7 +415,7 @@ namespace pugi bool operator<=(const xml_attribute& r) const; bool operator>=(const xml_attribute& r) const; - // Check if attribute is empty + // Check if attribute is empty (null) bool empty() const; // Get attribute name/value, or "" if attribute is empty @@ -423,8 +442,14 @@ namespace pugi // Set attribute name/value (returns false if attribute is empty or there is not enough memory) bool set_name(const char_t* rhs); bool set_name(const char_t* rhs, size_t size); + #ifdef PUGIXML_HAS_STRING_VIEW + bool set_name(string_view_t rhs); + #endif bool set_value(const char_t* rhs); bool set_value(const char_t* rhs, size_t size); + #ifdef PUGIXML_HAS_STRING_VIEW + bool set_value(string_view_t rhs); + #endif // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") bool set_value(int rhs); @@ -452,6 +477,10 @@ namespace pugi xml_attribute& operator=(float rhs); xml_attribute& operator=(bool rhs); + #ifdef PUGIXML_HAS_STRING_VIEW + xml_attribute& operator=(string_view_t rhs); + #endif + #ifdef PUGIXML_HAS_LONG_LONG xml_attribute& operator=(long long rhs); xml_attribute& operator=(unsigned long long rhs); @@ -507,7 +536,7 @@ namespace pugi bool operator<=(const xml_node& r) const; bool operator>=(const xml_node& r) const; - // Check if node is empty. + // Check if node is empty (null) bool empty() const; // Get node type @@ -546,9 +575,18 @@ namespace pugi xml_attribute attribute(const char_t* name) const; xml_node next_sibling(const char_t* name) const; xml_node previous_sibling(const char_t* name) const; + #ifdef PUGIXML_HAS_STRING_VIEW + xml_node child(string_view_t name) const; + xml_attribute attribute(string_view_t name) const; + xml_node next_sibling(string_view_t name) const; + xml_node previous_sibling(string_view_t name) const; + #endif // Get attribute, starting the search from a hint (and updating hint so that searching for a sequence of attributes is fast) xml_attribute attribute(const char_t* name, xml_attribute& hint) const; + #ifdef PUGIXML_HAS_STRING_VIEW + xml_attribute attribute(string_view_t name, xml_attribute& hint) const; + #endif // Get child value of current node; that is, value of the first child node of type PCDATA/CDATA const char_t* child_value() const; @@ -559,14 +597,26 @@ namespace pugi // 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(const char_t* rhs); bool set_name(const char_t* rhs, size_t size); + #ifdef PUGIXML_HAS_STRING_VIEW + bool set_name(string_view_t rhs); + #endif bool set_value(const char_t* rhs); bool set_value(const char_t* rhs, size_t size); + #ifdef PUGIXML_HAS_STRING_VIEW + bool set_value(string_view_t rhs); + #endif // Add attribute with specified name. Returns added attribute, or empty attribute on errors. xml_attribute append_attribute(const char_t* name); xml_attribute prepend_attribute(const char_t* name); xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr); xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr); + #ifdef PUGIXML_HAS_STRING_VIEW + xml_attribute append_attribute(string_view_t name); + xml_attribute prepend_attribute(string_view_t name); + xml_attribute insert_attribute_after(string_view_t name, const xml_attribute& attr); + xml_attribute insert_attribute_before(string_view_t name, const xml_attribute& attr); + #endif // Add a copy of the specified attribute. Returns added attribute, or empty attribute on errors. xml_attribute append_copy(const xml_attribute& proto); @@ -585,6 +635,12 @@ namespace pugi xml_node prepend_child(const char_t* name); xml_node insert_child_after(const char_t* name, const xml_node& node); xml_node insert_child_before(const char_t* name, const xml_node& node); + #ifdef PUGIXML_HAS_STRING_VIEW + xml_node append_child(string_view_t name); + xml_node prepend_child(string_view_t name); + xml_node insert_child_after(string_view_t, const xml_node& node); + xml_node insert_child_before(string_view_t name, const xml_node& node); + #endif // 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); @@ -601,6 +657,9 @@ namespace pugi // Remove specified attribute bool remove_attribute(const xml_attribute& a); bool remove_attribute(const char_t* name); + #ifdef PUGIXML_HAS_STRING_VIEW + bool remove_attribute(string_view_t name); + #endif // Remove all attributes bool remove_attributes(); @@ -608,6 +667,9 @@ namespace pugi // Remove specified child bool remove_child(const xml_node& n); bool remove_child(const char_t* name); + #ifdef PUGIXML_HAS_STRING_VIEW + bool remove_child(string_view_t name); + #endif // Remove all children bool remove_children(); @@ -700,8 +762,8 @@ namespace pugi #ifndef PUGIXML_NO_STL // Print subtree to stream - void print(std::basic_ostream >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const; - void print(std::basic_ostream >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const; + void print(std::basic_ostream& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const; + void print(std::basic_ostream& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const; #endif // Child nodes iterators @@ -764,7 +826,7 @@ namespace pugi // Borland C++ workaround bool operator!() const; - // Check if text object is empty + // Check if text object is empty (null) bool empty() const; // Get text, or "" if object is empty @@ -790,6 +852,9 @@ namespace pugi // Set text (returns false if object is empty or there is not enough memory) bool set(const char_t* rhs); bool set(const char_t* rhs, size_t size); + #ifdef PUGIXML_HAS_STRING_VIEW + bool set(string_view_t rhs); + #endif // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") bool set(int rhs); @@ -817,6 +882,10 @@ namespace pugi xml_text& operator=(float rhs); xml_text& operator=(bool rhs); + #ifdef PUGIXML_HAS_STRING_VIEW + xml_text& operator=(string_view_t rhs); + #endif + #ifdef PUGIXML_HAS_LONG_LONG xml_text& operator=(long long rhs); xml_text& operator=(unsigned long long rhs); @@ -1072,8 +1141,8 @@ namespace pugi #ifndef PUGIXML_NO_STL // Load document from stream. - xml_parse_result load(std::basic_istream >& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); - xml_parse_result load(std::basic_istream >& stream, unsigned int options = parse_default); + xml_parse_result load(std::basic_istream& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); + xml_parse_result load(std::basic_istream& stream, unsigned int options = parse_default); #endif // (deprecated: use load_string instead) Load document from zero-terminated string. No encoding conversions are applied. @@ -1102,8 +1171,8 @@ namespace pugi #ifndef PUGIXML_NO_STL // Save XML document to stream (semantics is slightly different from xml_node::print, see documentation for details). - void save(std::basic_ostream >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const; - void save(std::basic_ostream >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const; + void save(std::basic_ostream& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const; + void save(std::basic_ostream& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const; #endif // Save XML to file @@ -1314,7 +1383,7 @@ namespace pugi explicit xpath_exception(const xpath_parse_result& result); // Get error message - virtual const char* what() const throw() PUGIXML_OVERRIDE; + virtual const char* what() const PUGIXML_NOEXCEPT PUGIXML_OVERRIDE; // Get parse result const xpath_parse_result& result() const; @@ -1439,12 +1508,12 @@ namespace pugi #ifndef PUGIXML_NO_STL // Convert wide string to UTF8 - std::basic_string, std::allocator > PUGIXML_FUNCTION as_utf8(const wchar_t* str); - std::basic_string, std::allocator > PUGIXML_FUNCTION as_utf8(const std::basic_string, std::allocator >& str); + std::basic_string PUGIXML_FUNCTION as_utf8(const wchar_t* str); + std::basic_string PUGIXML_FUNCTION as_utf8(const std::basic_string& str); // Convert UTF8 to wide string - std::basic_string, std::allocator > PUGIXML_FUNCTION as_wide(const char* str); - std::basic_string, std::allocator > PUGIXML_FUNCTION as_wide(const std::basic_string, std::allocator >& str); + std::basic_string PUGIXML_FUNCTION as_wide(const char* str); + std::basic_string PUGIXML_FUNCTION as_wide(const std::basic_string& str); #endif // Memory allocation function interface; returns pointer to allocated memory or NULL on failure @@ -1491,7 +1560,7 @@ namespace std #endif /** - * Copyright (c) 2006-2023 Arseny Kapoulkine + * Copyright (c) 2006-2025 Arseny Kapoulkine * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/thirdparty/pugixml/update.sh b/thirdparty/pugixml/update.sh index 8af1c462e2..b6c68be87f 100755 --- a/thirdparty/pugixml/update.sh +++ b/thirdparty/pugixml/update.sh @@ -8,7 +8,7 @@ readonly name="pugixml" readonly ownership="pugixml Upstream " readonly subtree="thirdparty/pugixml/pugixml" readonly repo="https://github.com/zeux/pugixml.git" -readonly tag="v1.14" +readonly tag="v1.15" readonly shortlog="true" readonly paths=" src/pugiconfig.hpp