From 2f6baa1005bdd5f94d22ce7270237d5f45120f71 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine@gmail.com" Date: Wed, 14 Mar 2012 03:08:01 +0000 Subject: Implemented optional header-only mode (still need to do a couple of fixes for rare compilers, but it seems to work on the majority of configurations). Tests work in header-only mode, but testing is not enabled yet (still a bit more work to be done, and compiling header-only tests is up to 4 times slower, so we can't test more than one-two configurations per toolset) git-svn-id: http://pugixml.googlecode.com/svn/trunk@855 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugiconfig.hpp | 4 + src/pugixml.cpp | 1555 +++++++++++++++++++++++++++------------------------- src/pugixml.hpp | 10 +- 3 files changed, 820 insertions(+), 749 deletions(-) (limited to 'src') diff --git a/src/pugiconfig.hpp b/src/pugiconfig.hpp index de60816..a5e96a3 100644 --- a/src/pugiconfig.hpp +++ b/src/pugiconfig.hpp @@ -32,6 +32,10 @@ // #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall // In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead +// Header-only version +// #define PUGIXML_HEADER_ONLY +// #include "pugixml.cpp" + #endif /** diff --git a/src/pugixml.cpp b/src/pugixml.cpp index bcfbbdd..de8af95 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -11,6 +11,9 @@ * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) */ +#ifndef SOURCE_PUGIXML_CPP +#define SOURCE_PUGIXML_CPP + #include "pugixml.hpp" #include @@ -37,6 +40,7 @@ #include #ifdef _MSC_VER +# pragma warning(push) # pragma warning(disable: 4127) // conditional expression is constant # pragma warning(disable: 4324) // structure was padded due to __declspec(align()) # pragma warning(disable: 4611) // interaction between '_setjmp' and C++ object destruction is non-portable @@ -46,6 +50,7 @@ #endif #ifdef __INTEL_COMPILER +# pragma warning(push) # pragma warning(disable: 177) // function was declared but never referenced # pragma warning(disable: 279) // controlling expression is constant # pragma warning(disable: 1478 1786) // function was declared "deprecated" @@ -53,78 +58,103 @@ #endif #ifdef __BORLANDC__ +# pragma option push # pragma warn -8008 // condition is always false # pragma warn -8066 // unreachable code #endif #ifdef __SNC__ +# pragma diag_push # pragma diag_suppress=178 // function was declared but never referenced # pragma diag_suppress=237 // controlling expression is constant #endif -// uintptr_t -#if !defined(_MSC_VER) || _MSC_VER >= 1600 -# include -#else -# ifndef _UINTPTR_T_DEFINED -// No native uintptr_t in MSVC6 and in some WinCE versions -typedef size_t uintptr_t; -#define _UINTPTR_T_DEFINED -# endif -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -typedef __int32 int32_t; -#endif - // Inlining controls #if defined(_MSC_VER) && _MSC_VER >= 1300 -# define PUGIXML_NO_INLINE __declspec(noinline) +# define PUGI__NO_INLINE __declspec(noinline) #elif defined(__GNUC__) -# define PUGIXML_NO_INLINE __attribute__((noinline)) +# define PUGI__NO_INLINE __attribute__((noinline)) #else -# define PUGIXML_NO_INLINE +# define PUGI__NO_INLINE #endif // Simple static assertion -#define STATIC_ASSERT(cond) { static const char condition_failed[(cond) ? 1 : -1] = {0}; (void)condition_failed[0]; } +#define PUGI__STATIC_ASSERT(cond) { static const char condition_failed[(cond) ? 1 : -1] = {0}; (void)condition_failed[0]; } // Digital Mars C++ bug workaround for passing char loaded from memory via stack #ifdef __DMC__ -# define DMC_VOLATILE volatile +# define PUGI__DMC_VOLATILE volatile #else -# define DMC_VOLATILE +# define PUGI__DMC_VOLATILE #endif // In some environments MSVC is a compiler but the CRT lacks certain MSVC-specific features #if defined(_MSC_VER) && !defined(__S3E__) -# define MSVC_CRT_VERSION _MSC_VER +# define PUGI__MSVC_CRT_VERSION _MSC_VER #endif -using namespace pugi; +#ifdef PUGIXML_HEADER_ONLY +# define PUGI__NS_BEGIN namespace pugi { namespace impl { +# define PUGI__NS_END } } +# define PUGI__FN inline +# define PUGI__FN_NO_INLINE inline +#else +# if defined(_MSC_VER) && _MSC_VER < 1300 // MSVC6 seems to have an amusing bug with anonymous namespaces inside namespaces +# define PUGI__NS_BEGIN namespace pugi { namespace impl { +# define PUGI__NS_END } } +# else +# define PUGI__NS_BEGIN namespace pugi { namespace impl { namespace { +# define PUGI__NS_END } } } +# endif +# define PUGI__FN +# define PUGI__FN_NO_INLINE PUGI__NO_INLINE +#endif + +// uintptr_t +#if !defined(_MSC_VER) || _MSC_VER >= 1600 +# include +#else +# ifndef _UINTPTR_T_DEFINED +// No native uintptr_t in MSVC6 and in some WinCE versions +typedef size_t uintptr_t; +#define _UINTPTR_T_DEFINED +# endif +PUGI__NS_BEGIN + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; +PUGI__NS_END +#endif // Memory allocation -namespace -{ - void* default_allocate(size_t size) +PUGI__NS_BEGIN + PUGI__FN void* default_allocate(size_t size) { return malloc(size); } - void default_deallocate(void* ptr) + PUGI__FN void default_deallocate(void* ptr) { free(ptr); } - allocation_function global_allocate = default_allocate; - deallocation_function global_deallocate = default_deallocate; -} + template + struct xml_memory_management_function_storage + { + static allocation_function allocate; + static deallocation_function deallocate; + }; + + template allocation_function xml_memory_management_function_storage::allocate = default_allocate; + template deallocation_function xml_memory_management_function_storage::deallocate = default_deallocate; + + typedef xml_memory_management_function_storage xml_memory; +PUGI__NS_END // String utilities -namespace -{ +PUGI__NS_BEGIN // Get string length - size_t strlength(const char_t* s) + PUGI__FN size_t strlength(const char_t* s) { assert(s); @@ -136,7 +166,7 @@ namespace } // Compare two strings - bool strequal(const char_t* src, const char_t* dst) + PUGI__FN bool strequal(const char_t* src, const char_t* dst) { assert(src && dst); @@ -148,7 +178,7 @@ namespace } // Compare lhs with [rhs_begin, rhs_end) - bool strequalrange(const char_t* lhs, const char_t* rhs, size_t count) + PUGI__FN bool strequalrange(const char_t* lhs, const char_t* rhs, size_t count) { for (size_t i = 0; i < count; ++i) if (lhs[i] != rhs[i]) @@ -159,18 +189,17 @@ namespace #ifdef PUGIXML_WCHAR_MODE // Convert string to wide string, assuming all symbols are ASCII - void widen_ascii(wchar_t* dest, const char* source) + PUGI__FN void widen_ascii(wchar_t* dest, const char* source) { for (const char* i = source; *i; ++i) *dest++ = *i; *dest = 0; } #endif -} +PUGI__NS_END #if !defined(PUGIXML_NO_STL) || !defined(PUGIXML_NO_XPATH) // auto_ptr-like buffer holder for exception recovery -namespace -{ +PUGI__NS_BEGIN struct buffer_holder { void* data; @@ -192,11 +221,10 @@ namespace return result; } }; -} +PUGI__NS_END #endif -namespace -{ +PUGI__NS_BEGIN static const size_t xml_memory_page_size = 32768; static const uintptr_t xml_memory_page_alignment = 32; @@ -255,7 +283,7 @@ namespace size_t size = offsetof(xml_memory_page, data) + data_size; // allocate block with some alignment, leaving memory for worst-case padding - void* memory = global_allocate(size + xml_memory_page_alignment); + void* memory = xml_memory::allocate(size + xml_memory_page_alignment); if (!memory) return 0; // align upwards to page boundary @@ -272,7 +300,7 @@ namespace static void deallocate_page(xml_memory_page* page) { - global_deallocate(page->memory); + xml_memory::deallocate(page->memory); } void* allocate_memory_oob(size_t size, xml_memory_page*& out_page); @@ -375,11 +403,13 @@ namespace size_t _busy_size; }; - PUGIXML_NO_INLINE void* xml_allocator::allocate_memory_oob(size_t size, xml_memory_page*& out_page) + PUGI__FN_NO_INLINE void* xml_allocator::allocate_memory_oob(size_t size, xml_memory_page*& out_page) { const size_t large_allocation_threshold = xml_memory_page_size / 4; xml_memory_page* page = allocate_page(size <= large_allocation_threshold ? xml_memory_page_size : size); + out_page = page; + if (!page) return 0; if (size <= large_allocation_threshold) @@ -409,10 +439,9 @@ namespace // allocate inside page page->busy_size = size; - out_page = page; return page->data; } -} +PUGI__NS_END namespace pugi { @@ -420,7 +449,7 @@ namespace pugi struct xml_attribute_struct { /// Default ctor - xml_attribute_struct(xml_memory_page* page): header(reinterpret_cast(page)), name(0), value(0), prev_attribute_c(0), next_attribute(0) + xml_attribute_struct(impl::xml_memory_page* page): header(reinterpret_cast(page)), name(0), value(0), prev_attribute_c(0), next_attribute(0) { } @@ -438,7 +467,7 @@ namespace pugi { /// Default ctor /// \param type - node type - xml_node_struct(xml_memory_page* page, xml_node_type type): header(reinterpret_cast(page) | (type - 1)), parent(0), name(0), value(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): header(reinterpret_cast(page) | (type - 1)), parent(0), name(0), value(0), first_child(0), prev_sibling_c(0), next_sibling(0), first_attribute(0) { } @@ -458,8 +487,7 @@ namespace pugi }; } -namespace -{ +PUGI__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) @@ -469,17 +497,16 @@ namespace const char_t* buffer; }; - static inline xml_allocator& get_allocator(const xml_node_struct* node) + inline xml_allocator& get_allocator(const xml_node_struct* node) { assert(node); return *reinterpret_cast(node->header & xml_memory_page_pointer_mask)->allocator; } -} +PUGI__NS_END // Low-level DOM operations -namespace -{ +PUGI__NS_BEGIN inline xml_attribute_struct* allocate_attribute(xml_allocator& alloc) { xml_memory_page* page; @@ -500,8 +527,8 @@ namespace { uintptr_t header = a->header; - if (header & xml_memory_page_name_allocated_mask) alloc.deallocate_string(a->name); - if (header & xml_memory_page_value_allocated_mask) alloc.deallocate_string(a->value); + if (header & impl::xml_memory_page_name_allocated_mask) alloc.deallocate_string(a->name); + if (header & impl::xml_memory_page_value_allocated_mask) alloc.deallocate_string(a->value); alloc.deallocate_memory(a, sizeof(xml_attribute_struct), reinterpret_cast(header & xml_memory_page_pointer_mask)); } @@ -510,8 +537,8 @@ namespace { uintptr_t header = n->header; - if (header & xml_memory_page_name_allocated_mask) alloc.deallocate_string(n->name); - if (header & xml_memory_page_value_allocated_mask) alloc.deallocate_string(n->value); + if (header & impl::xml_memory_page_name_allocated_mask) alloc.deallocate_string(n->name); + if (header & impl::xml_memory_page_value_allocated_mask) alloc.deallocate_string(n->value); for (xml_attribute_struct* attr = n->first_attribute; attr; ) { @@ -534,7 +561,7 @@ namespace alloc.deallocate_memory(n, sizeof(xml_node_struct), reinterpret_cast(header & xml_memory_page_pointer_mask)); } - PUGIXML_NO_INLINE xml_node_struct* append_node(xml_node_struct* node, xml_allocator& alloc, xml_node_type type = node_element) + PUGI__FN_NO_INLINE xml_node_struct* append_node(xml_node_struct* node, xml_allocator& alloc, xml_node_type type = node_element) { xml_node_struct* child = allocate_node(alloc, type); if (!child) return 0; @@ -560,7 +587,7 @@ namespace return child; } - PUGIXML_NO_INLINE xml_attribute_struct* append_attribute_ll(xml_node_struct* node, xml_allocator& alloc) + PUGI__FN_NO_INLINE xml_attribute_struct* append_attribute_ll(xml_node_struct* node, xml_allocator& alloc) { xml_attribute_struct* a = allocate_attribute(alloc); if (!a) return 0; @@ -583,11 +610,10 @@ namespace return a; } -} +PUGI__NS_END // Helper classes for code generation -namespace -{ +PUGI__NS_BEGIN struct opt_false { enum { value = 0 }; @@ -597,11 +623,10 @@ namespace { enum { value = 1 }; }; -} +PUGI__NS_END // Unicode utilities -namespace -{ +PUGI__NS_BEGIN inline uint16_t endian_swap(uint16_t value) { return static_cast(((value & 0xff) << 8) | (value >> 8)); @@ -961,21 +986,20 @@ namespace } }; - template inline void convert_utf_endian_swap(T* result, const T* data, size_t length) + template PUGI__FN void convert_utf_endian_swap(T* result, const T* data, size_t length) { for (size_t i = 0; i < length; ++i) result[i] = endian_swap(data[i]); } #ifdef PUGIXML_WCHAR_MODE - inline void convert_wchar_endian_swap(wchar_t* result, const wchar_t* data, size_t length) + PUGI__FN void convert_wchar_endian_swap(wchar_t* result, const wchar_t* data, size_t length) { for (size_t i = 0; i < length; ++i) result[i] = static_cast(endian_swap(static_cast::type>(data[i]))); } #endif -} +PUGI__NS_END -namespace -{ +PUGI__NS_BEGIN enum chartype_t { ct_parse_pcdata = 1, // \0, &, \r, < @@ -988,7 +1012,7 @@ namespace ct_start_symbol = 128 // Any symbol > 127, a-z, A-Z, _, : }; - const unsigned char chartype_table[256] = + static const unsigned char chartype_table[256] = { 55, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 0, 0, 63, 0, 0, // 0-15 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31 @@ -1018,7 +1042,7 @@ namespace ctx_symbol = 16 // Any symbol > 127, a-z, A-Z, 0-9, _, -, . }; - const unsigned char chartypex_table[256] = + static const unsigned char chartypex_table[256] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 2, 3, 3, 2, 3, 3, // 0-15 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 16-31 @@ -1041,24 +1065,24 @@ namespace }; #ifdef PUGIXML_WCHAR_MODE - #define IS_CHARTYPE_IMPL(c, ct, table) ((static_cast(c) < 128 ? table[static_cast(c)] : table[128]) & (ct)) + #define PUGI__IS_CHARTYPE_IMPL(c, ct, table) ((static_cast(c) < 128 ? table[static_cast(c)] : table[128]) & (ct)) #else - #define IS_CHARTYPE_IMPL(c, ct, table) (table[static_cast(c)] & (ct)) + #define PUGI__IS_CHARTYPE_IMPL(c, ct, table) (table[static_cast(c)] & (ct)) #endif - #define IS_CHARTYPE(c, ct) IS_CHARTYPE_IMPL(c, ct, chartype_table) - #define IS_CHARTYPEX(c, ct) IS_CHARTYPE_IMPL(c, ct, chartypex_table) + #define PUGI__IS_CHARTYPE(c, ct) PUGI__IS_CHARTYPE_IMPL(c, ct, chartype_table) + #define PUGI__IS_CHARTYPEX(c, ct) PUGI__IS_CHARTYPE_IMPL(c, ct, chartypex_table) - bool is_little_endian() + PUGI__FN bool is_little_endian() { unsigned int ui = 1; return *reinterpret_cast(&ui) == 1; } - xml_encoding get_wchar_encoding() + PUGI__FN xml_encoding get_wchar_encoding() { - STATIC_ASSERT(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4); + PUGI__STATIC_ASSERT(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4); if (sizeof(wchar_t) == 2) return is_little_endian() ? encoding_utf16_le : encoding_utf16_be; @@ -1066,7 +1090,7 @@ namespace return is_little_endian() ? encoding_utf32_le : encoding_utf32_be; } - xml_encoding guess_buffer_encoding(uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) + PUGI__FN xml_encoding guess_buffer_encoding(uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) { // look for BOM in first few bytes if (d0 == 0 && d1 == 0 && d2 == 0xfe && d3 == 0xff) return encoding_utf32_be; @@ -1090,7 +1114,7 @@ namespace return encoding_utf8; } - xml_encoding get_buffer_encoding(xml_encoding encoding, const void* contents, size_t size) + PUGI__FN xml_encoding get_buffer_encoding(xml_encoding encoding, const void* contents, size_t size) { // replace wchar encoding with utf implementation if (encoding == encoding_wchar) return get_wchar_encoding(); @@ -1110,12 +1134,12 @@ namespace // try to guess encoding (based on XML specification, Appendix F.1) const uint8_t* data = static_cast(contents); - DMC_VOLATILE uint8_t d0 = data[0], d1 = data[1], d2 = data[2], d3 = data[3]; + PUGI__DMC_VOLATILE uint8_t d0 = data[0], d1 = data[1], d2 = data[2], d3 = data[3]; return guess_buffer_encoding(d0, d1, d2, d3); } - bool get_mutable_buffer(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) + PUGI__FN bool get_mutable_buffer(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) { if (is_mutable) { @@ -1123,7 +1147,7 @@ namespace } else { - void* buffer = global_allocate(size > 0 ? size : 1); + void* buffer = xml_memory::allocate(size > 0 ? size : 1); if (!buffer) return false; memcpy(buffer, contents, size); @@ -1137,13 +1161,13 @@ namespace } #ifdef PUGIXML_WCHAR_MODE - inline bool need_endian_swap_utf(xml_encoding le, xml_encoding re) + PUGI__FN bool need_endian_swap_utf(xml_encoding le, xml_encoding re) { return (le == encoding_utf16_be && re == encoding_utf16_le) || (le == encoding_utf16_le && re == encoding_utf16_be) || (le == encoding_utf32_be && re == encoding_utf32_le) || (le == encoding_utf32_le && re == encoding_utf32_be); } - bool convert_buffer_endian_swap(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) + PUGI__FN bool convert_buffer_endian_swap(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) { const char_t* data = static_cast(contents); @@ -1153,7 +1177,7 @@ namespace } else { - out_buffer = static_cast(global_allocate(size > 0 ? size : 1)); + out_buffer = static_cast(xml_memory::allocate(size > 0 ? size : 1)); if (!out_buffer) return false; } @@ -1164,7 +1188,7 @@ namespace return true; } - bool convert_buffer_utf8(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size) + PUGI__FN bool convert_buffer_utf8(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size) { const uint8_t* data = static_cast(contents); @@ -1172,7 +1196,7 @@ namespace out_length = utf_decoder::decode_utf8_block(data, size, 0); // allocate buffer of suitable length - out_buffer = static_cast(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); + out_buffer = static_cast(xml_memory::allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); if (!out_buffer) return false; // second pass: convert utf8 input to wchar_t @@ -1185,7 +1209,7 @@ namespace return true; } - template bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) + template PUGI__FN bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) { const uint16_t* data = static_cast(contents); size_t length = size / sizeof(uint16_t); @@ -1194,7 +1218,7 @@ namespace out_length = utf_decoder::decode_utf16_block(data, length, 0); // allocate buffer of suitable length - out_buffer = static_cast(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); + out_buffer = static_cast(xml_memory::allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); if (!out_buffer) return false; // second pass: convert utf16 input to wchar_t @@ -1207,7 +1231,7 @@ namespace return true; } - template bool convert_buffer_utf32(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) + template PUGI__FN bool convert_buffer_utf32(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) { const uint32_t* data = static_cast(contents); size_t length = size / sizeof(uint32_t); @@ -1216,7 +1240,7 @@ namespace out_length = utf_decoder::decode_utf32_block(data, length, 0); // allocate buffer of suitable length - out_buffer = static_cast(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); + out_buffer = static_cast(xml_memory::allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); if (!out_buffer) return false; // second pass: convert utf32 input to wchar_t @@ -1229,7 +1253,7 @@ namespace return true; } - bool convert_buffer_latin1(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size) + PUGI__FN bool convert_buffer_latin1(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size) { const uint8_t* data = static_cast(contents); @@ -1237,7 +1261,7 @@ namespace out_length = size; // allocate buffer of suitable length - out_buffer = static_cast(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); + out_buffer = static_cast(xml_memory::allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); if (!out_buffer) return false; // convert latin1 input to wchar_t @@ -1250,7 +1274,7 @@ namespace return true; } - bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) + PUGI__FN bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) { // get native encoding xml_encoding wchar_encoding = get_wchar_encoding(); @@ -1291,7 +1315,7 @@ namespace return false; } #else - template bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) + template PUGI__FN bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) { const uint16_t* data = static_cast(contents); size_t length = size / sizeof(uint16_t); @@ -1300,7 +1324,7 @@ namespace out_length = utf_decoder::decode_utf16_block(data, length, 0); // allocate buffer of suitable length - out_buffer = static_cast(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); + out_buffer = static_cast(xml_memory::allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); if (!out_buffer) return false; // second pass: convert utf16 input to utf8 @@ -1313,7 +1337,7 @@ namespace return true; } - template bool convert_buffer_utf32(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) + template PUGI__FN bool convert_buffer_utf32(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) { const uint32_t* data = static_cast(contents); size_t length = size / sizeof(uint32_t); @@ -1322,7 +1346,7 @@ namespace out_length = utf_decoder::decode_utf32_block(data, length, 0); // allocate buffer of suitable length - out_buffer = static_cast(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); + out_buffer = static_cast(xml_memory::allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); if (!out_buffer) return false; // second pass: convert utf32 input to utf8 @@ -1335,7 +1359,7 @@ namespace return true; } - size_t get_latin1_7bit_prefix_length(const uint8_t* data, size_t size) + PUGI__FN size_t get_latin1_7bit_prefix_length(const uint8_t* data, size_t size) { for (size_t i = 0; i < size; ++i) if (data[i] > 127) @@ -1344,7 +1368,7 @@ namespace return size; } - bool convert_buffer_latin1(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) + PUGI__FN bool convert_buffer_latin1(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) { const uint8_t* data = static_cast(contents); @@ -1362,7 +1386,7 @@ namespace out_length = prefix_length + utf_decoder::decode_latin1_block(postfix, postfix_length, 0); // allocate buffer of suitable length - out_buffer = static_cast(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); + out_buffer = static_cast(xml_memory::allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); if (!out_buffer) return false; // second pass: convert latin1 input to utf8 @@ -1377,7 +1401,7 @@ namespace return true; } - bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) + PUGI__FN bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) { // fast path: no conversion required if (encoding == encoding_utf8) return get_mutable_buffer(out_buffer, out_length, contents, size, is_mutable); @@ -1410,13 +1434,13 @@ namespace } #endif - size_t as_utf8_begin(const wchar_t* str, size_t length) + PUGI__FN size_t as_utf8_begin(const wchar_t* str, size_t length) { // get length in utf8 characters return utf_decoder::decode_wchar_block(str, length, 0); } - void as_utf8_end(char* buffer, size_t size, const wchar_t* str, size_t length) + PUGI__FN void as_utf8_end(char* buffer, size_t size, const wchar_t* str, size_t length) { // convert to utf8 uint8_t* begin = reinterpret_cast(buffer); @@ -1430,7 +1454,7 @@ namespace } #ifndef PUGIXML_NO_STL - std::string as_utf8_impl(const wchar_t* str, size_t length) + PUGI__FN std::string as_utf8_impl(const wchar_t* str, size_t length) { // first pass: get length in utf8 characters size_t size = as_utf8_begin(str, length); @@ -1445,7 +1469,7 @@ namespace return result; } - std::basic_string as_wide_impl(const char* str, size_t size) + PUGI__FN std::basic_string as_wide_impl(const char* str, size_t size) { const uint8_t* data = reinterpret_cast(str); @@ -1484,7 +1508,7 @@ namespace return target_length >= length && (target_length < reuse_threshold || target_length - length < target_length / 2); } - bool strcpy_insitu(char_t*& dest, uintptr_t& header, uintptr_t header_mask, const char_t* source) + PUGI__FN bool strcpy_insitu(char_t*& dest, uintptr_t& header, uintptr_t header_mask, const char_t* source) { size_t source_length = strlength(source); @@ -1572,7 +1596,7 @@ namespace } }; - char_t* strconv_escape(char_t* s, gap& g) + PUGI__FN char_t* strconv_escape(char_t* s, gap& g) { char_t* stre = s + 1; @@ -1715,13 +1739,13 @@ namespace // Utility macro for last character handling #define ENDSWITH(c, e) ((c) == (e) || ((c) == 0 && endch == (e))) - char_t* strconv_comment(char_t* s, char_t endch) + PUGI__FN char_t* strconv_comment(char_t* s, char_t endch) { gap g; while (true) { - while (!IS_CHARTYPE(*s, ct_parse_comment)) ++s; + while (!PUGI__IS_CHARTYPE(*s, ct_parse_comment)) ++s; if (*s == '\r') // Either a single 0x0d or 0x0d 0x0a pair { @@ -1743,13 +1767,13 @@ namespace } } - char_t* strconv_cdata(char_t* s, char_t endch) + PUGI__FN char_t* strconv_cdata(char_t* s, char_t endch) { gap g; while (true) { - while (!IS_CHARTYPE(*s, ct_parse_cdata)) ++s; + while (!PUGI__IS_CHARTYPE(*s, ct_parse_cdata)) ++s; if (*s == '\r') // Either a single 0x0d or 0x0d 0x0a pair { @@ -1781,7 +1805,7 @@ namespace while (true) { - while (!IS_CHARTYPE(*s, ct_parse_pcdata)) ++s; + while (!PUGI__IS_CHARTYPE(*s, ct_parse_pcdata)) ++s; if (*s == '<') // PCDATA ends here { @@ -1808,9 +1832,9 @@ namespace } }; - strconv_pcdata_t get_strconv_pcdata(unsigned int optmask) + PUGI__FN strconv_pcdata_t get_strconv_pcdata(unsigned int optmask) { - STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20); + PUGI__STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20); switch ((optmask >> 4) & 3) // get bitmask for flags (eol escapes) { @@ -1831,37 +1855,37 @@ namespace gap g; // trim leading whitespaces - if (IS_CHARTYPE(*s, ct_space)) + if (PUGI__IS_CHARTYPE(*s, ct_space)) { char_t* str = s; do ++str; - while (IS_CHARTYPE(*str, ct_space)); + while (PUGI__IS_CHARTYPE(*str, ct_space)); g.push(s, str - s); } while (true) { - while (!IS_CHARTYPE(*s, ct_parse_attr_ws | ct_space)) ++s; + while (!PUGI__IS_CHARTYPE(*s, ct_parse_attr_ws | ct_space)) ++s; if (*s == end_quote) { char_t* str = g.flush(s); do *str-- = 0; - while (IS_CHARTYPE(*str, ct_space)); + while (PUGI__IS_CHARTYPE(*str, ct_space)); return s + 1; } - else if (IS_CHARTYPE(*s, ct_space)) + else if (PUGI__IS_CHARTYPE(*s, ct_space)) { *s++ = ' '; - if (IS_CHARTYPE(*s, ct_space)) + if (PUGI__IS_CHARTYPE(*s, ct_space)) { char_t* str = s + 1; - while (IS_CHARTYPE(*str, ct_space)) ++str; + while (PUGI__IS_CHARTYPE(*str, ct_space)) ++str; g.push(s, str - s); } @@ -1884,7 +1908,7 @@ namespace while (true) { - while (!IS_CHARTYPE(*s, ct_parse_attr_ws)) ++s; + while (!PUGI__IS_CHARTYPE(*s, ct_parse_attr_ws)) ++s; if (*s == end_quote) { @@ -1892,7 +1916,7 @@ namespace return s + 1; } - else if (IS_CHARTYPE(*s, ct_space)) + else if (PUGI__IS_CHARTYPE(*s, ct_space)) { if (*s == '\r') { @@ -1920,7 +1944,7 @@ namespace while (true) { - while (!IS_CHARTYPE(*s, ct_parse_attr)) ++s; + while (!PUGI__IS_CHARTYPE(*s, ct_parse_attr)) ++s; if (*s == end_quote) { @@ -1952,7 +1976,7 @@ namespace while (true) { - while (!IS_CHARTYPE(*s, ct_parse_attr)) ++s; + while (!PUGI__IS_CHARTYPE(*s, ct_parse_attr)) ++s; if (*s == end_quote) { @@ -1973,9 +1997,9 @@ namespace } }; - strconv_attribute_t get_strconv_attribute(unsigned int optmask) + PUGI__FN strconv_attribute_t get_strconv_attribute(unsigned int optmask) { - STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20 && parse_wconv_attribute == 0x40 && parse_wnorm_attribute == 0x80); + PUGI__STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20 && parse_wconv_attribute == 0x40 && parse_wnorm_attribute == 0x80); switch ((optmask >> 4) & 15) // get bitmask for flags (wconv wnorm eol escapes) { @@ -2015,15 +2039,15 @@ namespace xml_parse_status error_status; // Parser utilities. - #define SKIPWS() { while (IS_CHARTYPE(*s, ct_space)) ++s; } - #define OPTSET(OPT) ( optmsk & (OPT) ) - #define PUSHNODE(TYPE) { cursor = append_node(cursor, alloc, TYPE); if (!cursor) THROW_ERROR(status_out_of_memory, s); } - #define POPNODE() { cursor = cursor->parent; } - #define SCANFOR(X) { while (*s != 0 && !(X)) ++s; } - #define SCANWHILE(X) { while ((X)) ++s; } - #define ENDSEG() { ch = *s; *s = 0; ++s; } - #define THROW_ERROR(err, m) return error_offset = m, error_status = err, static_cast(0) - #define CHECK_ERROR(err, m) { if (*s == 0) THROW_ERROR(err, m); } + #define PUGI__SKIPWS() { while (PUGI__IS_CHARTYPE(*s, ct_space)) ++s; } + #define PUGI__OPTSET(OPT) ( optmsk & (OPT) ) + #define PUGI__PUSHNODE(TYPE) { cursor = append_node(cursor, alloc, TYPE); if (!cursor) PUGI__THROW_ERROR(status_out_of_memory, s); } + #define PUGI__POPNODE() { cursor = cursor->parent; } + #define PUGI__SCANFOR(X) { while (*s != 0 && !(X)) ++s; } + #define PUGI__SCANWHILE(X) { while ((X)) ++s; } + #define PUGI__ENDSEG() { ch = *s; *s = 0; ++s; } + #define PUGI__THROW_ERROR(err, m) return error_offset = m, error_status = err, static_cast(0) + #define PUGI__CHECK_ERROR(err, m) { if (*s == 0) PUGI__THROW_ERROR(err, m); } xml_parser(const xml_allocator& alloc_): alloc(alloc_), error_offset(0), error_status(status_ok) { @@ -2042,8 +2066,8 @@ namespace { // quoted string char_t ch = *s++; - SCANFOR(*s == ch); - if (!*s) THROW_ERROR(status_bad_doctype, s); + PUGI__SCANFOR(*s == ch); + if (!*s) PUGI__THROW_ERROR(status_bad_doctype, s); s++; } @@ -2051,20 +2075,20 @@ namespace { // s += 2; - SCANFOR(s[0] == '?' && s[1] == '>'); // no need for ENDSWITH because ?> can't terminate proper doctype - if (!*s) THROW_ERROR(status_bad_doctype, s); + PUGI__SCANFOR(s[0] == '?' && s[1] == '>'); // no need for ENDSWITH because ?> can't terminate proper doctype + if (!*s) PUGI__THROW_ERROR(status_bad_doctype, s); s += 2; } else if (s[0] == '<' && s[1] == '!' && s[2] == '-' && s[3] == '-') { s += 4; - SCANFOR(s[0] == '-' && s[1] == '-' && s[2] == '>'); // no need for ENDSWITH because --> can't terminate proper doctype - if (!*s) THROW_ERROR(status_bad_doctype, s); + PUGI__SCANFOR(s[0] == '-' && s[1] == '-' && s[2] == '>'); // no need for ENDSWITH because --> can't terminate proper doctype + if (!*s) PUGI__THROW_ERROR(status_bad_doctype, s); s += 4; } - else THROW_ERROR(status_bad_doctype, s); + else PUGI__THROW_ERROR(status_bad_doctype, s); return s; } @@ -2092,7 +2116,7 @@ namespace else s++; } - THROW_ERROR(status_bad_doctype, s); + PUGI__THROW_ERROR(status_bad_doctype, s); } char_t* parse_doctype_group(char_t* s, char_t endch, bool toplevel) @@ -2132,7 +2156,7 @@ namespace else s++; } - if (!toplevel || endch != '>') THROW_ERROR(status_bad_doctype, s); + if (!toplevel || endch != '>') PUGI__THROW_ERROR(status_bad_doctype, s); return s; } @@ -2150,31 +2174,31 @@ namespace { ++s; - if (OPTSET(parse_comments)) + if (PUGI__OPTSET(parse_comments)) { - PUSHNODE(node_comment); // Append a new node on the tree. + PUGI__PUSHNODE(node_comment); // Append a new node on the tree. cursor->value = s; // Save the offset. } - if (OPTSET(parse_eol) && OPTSET(parse_comments)) + if (PUGI__OPTSET(parse_eol) && PUGI__OPTSET(parse_comments)) { s = strconv_comment(s, endch); - if (!s) THROW_ERROR(status_bad_comment, cursor->value); + if (!s) PUGI__THROW_ERROR(status_bad_comment, cursor->value); } else { // Scan for terminating '-->'. - SCANFOR(s[0] == '-' && s[1] == '-' && ENDSWITH(s[2], '>')); - CHECK_ERROR(status_bad_comment, s); + PUGI__SCANFOR(s[0] == '-' && s[1] == '-' && ENDSWITH(s[2], '>')); + PUGI__CHECK_ERROR(status_bad_comment, s); - if (OPTSET(parse_comments)) + if (PUGI__OPTSET(parse_comments)) *s = 0; // Zero-terminate this segment at the first terminating '-'. s += (s[2] == '>' ? 3 : 2); // Step over the '\0->'. } } - else THROW_ERROR(status_bad_comment, s); + else PUGI__THROW_ERROR(status_bad_comment, s); } else if (*s == '[') { @@ -2183,22 +2207,22 @@ namespace { ++s; - if (OPTSET(parse_cdata)) + if (PUGI__OPTSET(parse_cdata)) { - PUSHNODE(node_cdata); // Append a new node on the tree. + PUGI__PUSHNODE(node_cdata); // Append a new node on the tree. cursor->value = s; // Save the offset. - if (OPTSET(parse_eol)) + if (PUGI__OPTSET(parse_eol)) { s = strconv_cdata(s, endch); - if (!s) THROW_ERROR(status_bad_cdata, cursor->value); + if (!s) PUGI__THROW_ERROR(status_bad_cdata, cursor->value); } else { // Scan for terminating ']]>'. - SCANFOR(s[0] == ']' && s[1] == ']' && ENDSWITH(s[2], '>')); - CHECK_ERROR(status_bad_cdata, s); + PUGI__SCANFOR(s[0] == ']' && s[1] == ']' && ENDSWITH(s[2], '>')); + PUGI__CHECK_ERROR(status_bad_cdata, s); *s++ = 0; // Zero-terminate this segment. } @@ -2206,44 +2230,44 @@ namespace else // Flagged for discard, but we still have to scan for the terminator. { // Scan for terminating ']]>'. - SCANFOR(s[0] == ']' && s[1] == ']' && ENDSWITH(s[2], '>')); - CHECK_ERROR(status_bad_cdata, s); + PUGI__SCANFOR(s[0] == ']' && s[1] == ']' && ENDSWITH(s[2], '>')); + PUGI__CHECK_ERROR(status_bad_cdata, s); ++s; } s += (s[1] == '>' ? 2 : 1); // Step over the last ']>'. } - else THROW_ERROR(status_bad_cdata, s); + else PUGI__THROW_ERROR(status_bad_cdata, s); } else if (s[0] == 'D' && s[1] == 'O' && s[2] == 'C' && s[3] == 'T' && s[4] == 'Y' && s[5] == 'P' && ENDSWITH(s[6], 'E')) { s -= 2; - if (cursor->parent) THROW_ERROR(status_bad_doctype, s); + if (cursor->parent) PUGI__THROW_ERROR(status_bad_doctype, s); char_t* mark = s + 9; s = parse_doctype_group(s, endch, true); if (!s) return s; - if (OPTSET(parse_doctype)) + if (PUGI__OPTSET(parse_doctype)) { - while (IS_CHARTYPE(*mark, ct_space)) ++mark; + while (PUGI__IS_CHARTYPE(*mark, ct_space)) ++mark; - PUSHNODE(node_doctype); + PUGI__PUSHNODE(node_doctype); cursor->value = mark; assert((s[0] == 0 && endch == '>') || s[-1] == '>'); s[*s == 0 ? 0 : -1] = 0; - POPNODE(); + PUGI__POPNODE(); } } - else if (*s == 0 && endch == '-') THROW_ERROR(status_bad_comment, s); - else if (*s == 0 && endch == '[') THROW_ERROR(status_bad_cdata, s); - else THROW_ERROR(status_unrecognized_tag, s); + else if (*s == 0 && endch == '-') PUGI__THROW_ERROR(status_bad_comment, s); + else if (*s == 0 && endch == '[') PUGI__THROW_ERROR(status_bad_cdata, s); + else PUGI__THROW_ERROR(status_unrecognized_tag, s); return s; } @@ -2260,50 +2284,50 @@ namespace // read PI target char_t* target = s; - if (!IS_CHARTYPE(*s, ct_start_symbol)) THROW_ERROR(status_bad_pi, s); + if (!PUGI__IS_CHARTYPE(*s, ct_start_symbol)) PUGI__THROW_ERROR(status_bad_pi, s); - SCANWHILE(IS_CHARTYPE(*s, ct_symbol)); - CHECK_ERROR(status_bad_pi, s); + PUGI__SCANWHILE(PUGI__IS_CHARTYPE(*s, ct_symbol)); + PUGI__CHECK_ERROR(status_bad_pi, s); // determine node type; stricmp / strcasecmp is not portable bool declaration = (target[0] | ' ') == 'x' && (target[1] | ' ') == 'm' && (target[2] | ' ') == 'l' && target + 3 == s; - if (declaration ? OPTSET(parse_declaration) : OPTSET(parse_pi)) + if (declaration ? PUGI__OPTSET(parse_declaration) : PUGI__OPTSET(parse_pi)) { if (declaration) { // disallow non top-level declarations - if (cursor->parent) THROW_ERROR(status_bad_pi, s); + if (cursor->parent) PUGI__THROW_ERROR(status_bad_pi, s); - PUSHNODE(node_declaration); + PUGI__PUSHNODE(node_declaration); } else { - PUSHNODE(node_pi); + PUGI__PUSHNODE(node_pi); } cursor->name = target; - ENDSEG(); + PUGI__ENDSEG(); // parse value/attributes if (ch == '?') { // empty node - if (!ENDSWITH(*s, '>')) THROW_ERROR(status_bad_pi, s); + if (!ENDSWITH(*s, '>')) PUGI__THROW_ERROR(status_bad_pi, s); s += (*s == '>'); - POPNODE(); + PUGI__POPNODE(); } - else if (IS_CHARTYPE(ch, ct_space)) + else if (PUGI__IS_CHARTYPE(ch, ct_space)) { - SKIPWS(); + PUGI__SKIPWS(); // scan for tag end char_t* value = s; - SCANFOR(s[0] == '?' && ENDSWITH(s[1], '>')); - CHECK_ERROR(status_bad_pi, s); + PUGI__SCANFOR(s[0] == '?' && ENDSWITH(s[1], '>')); + PUGI__CHECK_ERROR(status_bad_pi, s); if (declaration) { @@ -2317,20 +2341,20 @@ namespace { // store value and step over > cursor->value = value; - POPNODE(); + PUGI__POPNODE(); - ENDSEG(); + PUGI__ENDSEG(); s += (*s == '>'); } } - else THROW_ERROR(status_bad_pi, s); + else PUGI__THROW_ERROR(status_bad_pi, s); } else { // scan for tag end - SCANFOR(s[0] == '?' && ENDSWITH(s[1], '>')); - CHECK_ERROR(status_bad_pi, s); + PUGI__SCANFOR(s[0] == '?' && ENDSWITH(s[1], '>')); + PUGI__CHECK_ERROR(status_bad_pi, s); s += (s[1] == '>' ? 2 : 1); } @@ -2357,43 +2381,43 @@ namespace ++s; LOC_TAG: - if (IS_CHARTYPE(*s, ct_start_symbol)) // '<#...' + if (PUGI__IS_CHARTYPE(*s, ct_start_symbol)) // '<#...' { - PUSHNODE(node_element); // Append a new node to the tree. + PUGI__PUSHNODE(node_element); // Append a new node to the tree. cursor->name = s; - SCANWHILE(IS_CHARTYPE(*s, ct_symbol)); // Scan for a terminator. - ENDSEG(); // Save char in 'ch', terminate & step over. + PUGI__SCANWHILE(PUGI__IS_CHARTYPE(*s, ct_symbol)); // Scan for a terminator. + PUGI__ENDSEG(); // Save char in 'ch', terminate & step over. if (ch == '>') { // end of tag } - else if (IS_CHARTYPE(ch, ct_space)) + else if (PUGI__IS_CHARTYPE(ch, ct_space)) { LOC_ATTRIBUTES: while (true) { - SKIPWS(); // Eat any whitespace. + PUGI__SKIPWS(); // Eat any whitespace. - if (IS_CHARTYPE(*s, ct_start_symbol)) // <... #... + if (PUGI__IS_CHARTYPE(*s, ct_start_symbol)) // <... #... { xml_attribute_struct* a = append_attribute_ll(cursor, alloc); // Make space for this attribute. - if (!a) THROW_ERROR(status_out_of_memory, s); + if (!a) PUGI__THROW_ERROR(status_out_of_memory, s); a->name = s; // Save the offset. - SCANWHILE(IS_CHARTYPE(*s, ct_symbol)); // Scan for a terminator. - CHECK_ERROR(status_bad_attribute, s); //$ redundant, left for performance + PUGI__SCANWHILE(PUGI__IS_CHARTYPE(*s, ct_symbol)); // Scan for a terminator. + PUGI__CHECK_ERROR(status_bad_attribute, s); //$ redundant, left for performance - ENDSEG(); // Save char in 'ch', terminate & step over. - CHECK_ERROR(status_bad_attribute, s); //$ redundant, left for performance + PUGI__ENDSEG(); // Save char in 'ch', terminate & step over. + PUGI__CHECK_ERROR(status_bad_attribute, s); //$ redundant, left for performance - if (IS_CHARTYPE(ch, ct_space)) + if (PUGI__IS_CHARTYPE(ch, ct_space)) { - SKIPWS(); // Eat any whitespace. - CHECK_ERROR(status_bad_attribute, s); //$ redundant, left for performance + PUGI__SKIPWS(); // Eat any whitespace. + PUGI__CHECK_ERROR(status_bad_attribute, s); //$ redundant, left for performance ch = *s; ++s; @@ -2401,7 +2425,7 @@ namespace if (ch == '=') // '<... #=...' { - SKIPWS(); // Eat any whitespace. + PUGI__SKIPWS(); // Eat any whitespace. if (*s == '"' || *s == '\'') // '<... #="...' { @@ -2411,16 +2435,16 @@ namespace s = strconv_attribute(s, ch); - if (!s) THROW_ERROR(status_bad_attribute, a->value); + if (!s) PUGI__THROW_ERROR(status_bad_attribute, a->value); // After this line the loop continues from the start; // Whitespaces, / and > are ok, symbols and EOF are wrong, // everything else will be detected - if (IS_CHARTYPE(*s, ct_start_symbol)) THROW_ERROR(status_bad_attribute, s); + if (PUGI__IS_CHARTYPE(*s, ct_start_symbol)) PUGI__THROW_ERROR(status_bad_attribute, s); } - else THROW_ERROR(status_bad_attribute, s); + else PUGI__THROW_ERROR(status_bad_attribute, s); } - else THROW_ERROR(status_bad_attribute, s); + else PUGI__THROW_ERROR(status_bad_attribute, s); } else if (*s == '/') { @@ -2428,16 +2452,16 @@ namespace if (*s == '>') { - POPNODE(); + PUGI__POPNODE(); s++; break; } else if (*s == 0 && endch == '>') { - POPNODE(); + PUGI__POPNODE(); break; } - else THROW_ERROR(status_bad_start_element, s); + else PUGI__THROW_ERROR(status_bad_start_element, s); } else if (*s == '>') { @@ -2449,16 +2473,16 @@ namespace { break; } - else THROW_ERROR(status_bad_start_element, s); + else PUGI__THROW_ERROR(status_bad_start_element, s); } // !!! } else if (ch == '/') // '<#.../' { - if (!ENDSWITH(*s, '>')) THROW_ERROR(status_bad_start_element, s); + if (!ENDSWITH(*s, '>')) PUGI__THROW_ERROR(status_bad_start_element, s); - POPNODE(); // Pop. + PUGI__POPNODE(); // Pop. s += (*s == '>'); } @@ -2467,39 +2491,39 @@ namespace // we stepped over null terminator, backtrack & handle closing tag --s; - if (endch != '>') THROW_ERROR(status_bad_start_element, s); + if (endch != '>') PUGI__THROW_ERROR(status_bad_start_element, s); } - else THROW_ERROR(status_bad_start_element, s); + else PUGI__THROW_ERROR(status_bad_start_element, s); } else if (*s == '/') { ++s; char_t* name = cursor->name; - if (!name) THROW_ERROR(status_end_element_mismatch, s); + if (!name) PUGI__THROW_ERROR(status_end_element_mismatch, s); - while (IS_CHARTYPE(*s, ct_symbol)) + while (PUGI__IS_CHARTYPE(*s, ct_symbol)) { - if (*s++ != *name++) THROW_ERROR(status_end_element_mismatch, s); + if (*s++ != *name++) PUGI__THROW_ERROR(status_end_element_mismatch, s); } if (*name) { - if (*s == 0 && name[0] == endch && name[1] == 0) THROW_ERROR(status_bad_end_element, s); - else THROW_ERROR(status_end_element_mismatch, s); + if (*s == 0 && name[0] == endch && name[1] == 0) PUGI__THROW_ERROR(status_bad_end_element, s); + else PUGI__THROW_ERROR(status_end_element_mismatch, s); } - POPNODE(); // Pop. + PUGI__POPNODE(); // Pop. - SKIPWS(); + PUGI__SKIPWS(); if (*s == 0) { - if (endch != '>') THROW_ERROR(status_bad_end_element, s); + if (endch != '>') PUGI__THROW_ERROR(status_bad_end_element, s); } else { - if (*s != '>') THROW_ERROR(status_bad_end_element, s); + if (*s != '>') PUGI__THROW_ERROR(status_bad_end_element, s); ++s; } } @@ -2516,25 +2540,25 @@ namespace s = parse_exclamation(s, cursor, optmsk, endch); if (!s) return s; } - else if (*s == 0 && endch == '?') THROW_ERROR(status_bad_pi, s); - else THROW_ERROR(status_unrecognized_tag, s); + else if (*s == 0 && endch == '?') PUGI__THROW_ERROR(status_bad_pi, s); + else PUGI__THROW_ERROR(status_unrecognized_tag, s); } else { mark = s; // Save this offset while searching for a terminator. - SKIPWS(); // Eat whitespace if no genuine PCDATA here. + PUGI__SKIPWS(); // Eat whitespace if no genuine PCDATA here. if (*s == '<') { // We skipped some whitespace characters because otherwise we would take the tag branch instead of PCDATA one assert(mark != s); - if (!OPTSET(parse_ws_pcdata | parse_ws_pcdata_single)) + if (!PUGI__OPTSET(parse_ws_pcdata | parse_ws_pcdata_single)) { continue; } - else if (OPTSET(parse_ws_pcdata_single)) + else if (PUGI__OPTSET(parse_ws_pcdata_single)) { if (s[1] != '/' || cursor->first_child) continue; } @@ -2544,18 +2568,18 @@ namespace if (cursor->parent) { - PUSHNODE(node_pcdata); // Append a new node on the tree. + PUGI__PUSHNODE(node_pcdata); // Append a new node on the tree. cursor->value = s; // Save the offset. s = strconv_pcdata(s); - POPNODE(); // Pop since this is a standalone. + PUGI__POPNODE(); // Pop since this is a standalone. if (!*s) break; } else { - SCANFOR(*s == '<'); // '...<' + PUGI__SCANFOR(*s == '<'); // '...<' if (!*s) break; ++s; @@ -2567,7 +2591,7 @@ namespace } // check that last tag is closed - if (cursor != xmldoc) THROW_ERROR(status_end_element_mismatch, s); + if (cursor != xmldoc) PUGI__THROW_ERROR(status_end_element_mismatch, s); return s; } @@ -2610,7 +2634,7 @@ namespace }; // Output facilities - xml_encoding get_write_native_encoding() + PUGI__FN xml_encoding get_write_native_encoding() { #ifdef PUGIXML_WCHAR_MODE return get_wchar_encoding(); @@ -2619,7 +2643,7 @@ namespace #endif } - xml_encoding get_write_encoding(xml_encoding encoding) + PUGI__FN xml_encoding get_write_encoding(xml_encoding encoding) { // replace wchar encoding with utf implementation if (encoding == encoding_wchar) return get_wchar_encoding(); @@ -2638,7 +2662,7 @@ namespace } #ifdef PUGIXML_WCHAR_MODE - size_t get_valid_length(const char_t* data, size_t length) + PUGI__FN size_t get_valid_length(const char_t* data, size_t length) { assert(length > 0); @@ -2646,7 +2670,7 @@ namespace return (sizeof(wchar_t) == 2 && static_cast(static_cast(data[length - 1]) - 0xD800) < 0x400) ? length - 1 : length; } - size_t convert_buffer(void* result, const char_t* data, size_t length, xml_encoding encoding) + PUGI__FN size_t convert_buffer(void* result, const char_t* data, size_t length, xml_encoding encoding) { // only endian-swapping is required if (need_endian_swap_utf(encoding, get_wchar_encoding())) @@ -2710,7 +2734,7 @@ namespace return 0; } #else - size_t get_valid_length(const char_t* data, size_t length) + PUGI__FN size_t get_valid_length(const char_t* data, size_t length) { assert(length > 4); @@ -2726,7 +2750,7 @@ namespace return length; } - size_t convert_buffer(void* result, const char_t* data, size_t length, xml_encoding encoding) + PUGI__FN size_t convert_buffer(void* result, const char_t* data, size_t length, xml_encoding encoding) { if (encoding == encoding_utf16_be || encoding == encoding_utf16_le) { @@ -2932,7 +2956,7 @@ namespace xml_encoding encoding; }; - void write_bom(xml_writer& writer, xml_encoding encoding) + PUGI__FN void write_bom(xml_writer& writer, xml_encoding encoding) { switch (encoding) { @@ -2964,14 +2988,14 @@ namespace } } - void text_output_escaped(xml_buffered_writer& writer, const char_t* s, chartypex_t type) + PUGI__FN void text_output_escaped(xml_buffered_writer& writer, const char_t* s, chartypex_t type) { while (*s) { const char_t* prev = s; // While *s is a usual symbol - while (!IS_CHARTYPEX(*s, type)) ++s; + while (!PUGI__IS_CHARTYPEX(*s, type)) ++s; writer.write(prev, static_cast(s - prev)); @@ -3005,7 +3029,7 @@ namespace } } - void text_output(xml_buffered_writer& writer, const char_t* s, chartypex_t type, unsigned int flags) + PUGI__FN void text_output(xml_buffered_writer& writer, const char_t* s, chartypex_t type, unsigned int flags) { if (flags & format_no_escapes) writer.write(s); @@ -3013,7 +3037,7 @@ namespace text_output_escaped(writer, s, type); } - void text_output_cdata(xml_buffered_writer& writer, const char_t* s) + PUGI__FN void text_output_cdata(xml_buffered_writer& writer, const char_t* s) { do { @@ -3035,7 +3059,7 @@ namespace while (*s); } - void node_output_attributes(xml_buffered_writer& writer, const xml_node& node, unsigned int flags) + PUGI__FN void node_output_attributes(xml_buffered_writer& writer, const xml_node& node, unsigned int flags) { const char_t* default_name = PUGIXML_TEXT(":anonymous"); @@ -3051,7 +3075,7 @@ namespace } } - void node_output(xml_buffered_writer& writer, const xml_node& node, const char_t* indent, unsigned int flags, unsigned int depth) + PUGI__FN void node_output(xml_buffered_writer& writer, const xml_node& node, const char_t* indent, unsigned int flags, unsigned int depth) { const char_t* default_name = PUGIXML_TEXT(":anonymous"); @@ -3202,7 +3226,7 @@ namespace return true; } - void recursive_copy_skip(xml_node& dest, const xml_node& source, const xml_node& skip) + PUGI__FN void recursive_copy_skip(xml_node& dest, const xml_node& source, const xml_node& skip) { assert(dest.type() == source.type()); @@ -3256,9 +3280,9 @@ namespace } // 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 - xml_parse_status get_file_size(FILE* file, size_t& out_result) + PUGI__FN xml_parse_status get_file_size(FILE* file, size_t& out_result) { - #if defined(MSVC_CRT_VERSION) && MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE) + #if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE) // there are 64-bit versions of fseek/ftell, let's use them typedef __int64 length_type; @@ -3295,7 +3319,7 @@ namespace return status_ok; } - xml_parse_result load_file_impl(xml_document& doc, FILE* file, unsigned int options, xml_encoding encoding) + PUGI__FN xml_parse_result load_file_impl(xml_document& doc, FILE* file, unsigned int options, xml_encoding encoding) { if (!file) return make_parse_result(status_file_not_found); @@ -3310,7 +3334,7 @@ namespace } // allocate buffer for the whole file - char* contents = static_cast(global_allocate(size > 0 ? size : 1)); + char* contents = static_cast(xml_memory::allocate(size > 0 ? size : 1)); if (!contents) { @@ -3324,7 +3348,7 @@ namespace if (read_size != size) { - global_deallocate(contents); + xml_memory::deallocate(contents); return make_parse_result(status_io_error); } @@ -3336,7 +3360,7 @@ namespace { static xml_stream_chunk* create() { - void* memory = global_allocate(sizeof(xml_stream_chunk)); + void* memory = xml_memory::allocate(sizeof(xml_stream_chunk)); return new (memory) xml_stream_chunk(); } @@ -3349,7 +3373,7 @@ namespace while (chunk) { xml_stream_chunk* next = chunk->next; - global_deallocate(chunk); + xml_memory::deallocate(chunk); chunk = next; } } @@ -3364,7 +3388,7 @@ namespace T data[xml_memory_page_size / sizeof(T)]; }; - template xml_parse_status load_stream_data_noseek(std::basic_istream& stream, void** out_buffer, size_t* out_size) + template PUGI__FN xml_parse_status load_stream_data_noseek(std::basic_istream& stream, void** out_buffer, size_t* out_size) { buffer_holder chunks(0, xml_stream_chunk::destroy); @@ -3395,7 +3419,7 @@ namespace } // copy chunk list to a contiguous buffer - char* buffer = static_cast(global_allocate(total)); + char* buffer = static_cast(xml_memory::allocate(total)); if (!buffer) return status_out_of_memory; char* write = buffer; @@ -3416,7 +3440,7 @@ namespace return status_ok; } - template xml_parse_status load_stream_data_seek(std::basic_istream& stream, void** out_buffer, size_t* out_size) + template PUGI__FN xml_parse_status load_stream_data_seek(std::basic_istream& stream, void** out_buffer, size_t* out_size) { // get length of remaining data in stream typename std::basic_istream::pos_type pos = stream.tellg(); @@ -3432,7 +3456,7 @@ namespace if (static_cast(read_length) != length || length < 0) return status_out_of_memory; // read stream data into memory (guard against stream exceptions with buffer holder) - buffer_holder buffer(global_allocate((read_length > 0 ? read_length : 1) * sizeof(T)), global_deallocate); + buffer_holder buffer(xml_memory::allocate((read_length > 0 ? read_length : 1) * sizeof(T)), xml_memory::deallocate); if (!buffer.data) return status_out_of_memory; stream.read(static_cast(buffer.data), static_cast(read_length)); @@ -3450,7 +3474,7 @@ namespace return status_ok; } - template xml_parse_result load_stream_impl(xml_document& doc, std::basic_istream& stream, unsigned int options, xml_encoding encoding) + template PUGI__FN xml_parse_result load_stream_impl(xml_document& doc, std::basic_istream& stream, unsigned int options, xml_encoding encoding) { void* buffer = 0; size_t size = 0; @@ -3463,13 +3487,13 @@ namespace } #endif -#if defined(MSVC_CRT_VERSION) || defined(__BORLANDC__) || defined(__MINGW32__) - FILE* open_file_wide(const wchar_t* path, const wchar_t* mode) +#if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) || defined(__MINGW32__) + PUGI__FN FILE* open_file_wide(const wchar_t* path, const wchar_t* mode) { return _wfopen(path, mode); } #else - char* convert_path_heap(const wchar_t* str) + PUGI__FN char* convert_path_heap(const wchar_t* str) { assert(str); @@ -3478,7 +3502,7 @@ namespace size_t size = as_utf8_begin(str, length); // allocate resulting string - char* result = static_cast(global_allocate(size + 1)); + char* result = static_cast(xml_memory::allocate(size + 1)); if (!result) return 0; // second pass: convert to utf8 @@ -3487,7 +3511,7 @@ namespace return result; } - 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) { // 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); @@ -3501,34 +3525,34 @@ namespace FILE* result = fopen(path_utf8, mode_ascii); // free dummy buffer - global_deallocate(path_utf8); + xml_memory::deallocate(path_utf8); return result; } #endif -} +PUGI__NS_END namespace pugi { - xml_writer_file::xml_writer_file(void* file_): file(file_) + PUGI__FN xml_writer_file::xml_writer_file(void* file_): file(file_) { } - void xml_writer_file::write(const void* data, size_t size) + PUGI__FN void xml_writer_file::write(const void* data, size_t size) { fwrite(data, size, 1, static_cast(file)); } #ifndef PUGIXML_NO_STL - xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(&stream), wide_stream(0) + PUGI__FN xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(&stream), wide_stream(0) { } - xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(0), wide_stream(&stream) + PUGI__FN xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(0), wide_stream(&stream) { } - void xml_writer_stream::write(const void* data, size_t size) + PUGI__FN void xml_writer_stream::write(const void* data, size_t size) { if (narrow_stream) { @@ -3545,92 +3569,92 @@ namespace pugi } #endif - xml_tree_walker::xml_tree_walker(): _depth(0) + PUGI__FN xml_tree_walker::xml_tree_walker(): _depth(0) { } - xml_tree_walker::~xml_tree_walker() + PUGI__FN xml_tree_walker::~xml_tree_walker() { } - int xml_tree_walker::depth() const + PUGI__FN int xml_tree_walker::depth() const { return _depth; } - bool xml_tree_walker::begin(xml_node&) + PUGI__FN bool xml_tree_walker::begin(xml_node&) { return true; } - bool xml_tree_walker::end(xml_node&) + PUGI__FN bool xml_tree_walker::end(xml_node&) { return true; } - xml_attribute::xml_attribute(): _attr(0) + PUGI__FN xml_attribute::xml_attribute(): _attr(0) { } - xml_attribute::xml_attribute(xml_attribute_struct* attr): _attr(attr) + PUGI__FN xml_attribute::xml_attribute(xml_attribute_struct* attr): _attr(attr) { } - static void unspecified_bool_xml_attribute(xml_attribute***) + PUGI__FN static void unspecified_bool_xml_attribute(xml_attribute***) { } - xml_attribute::operator xml_attribute::unspecified_bool_type() const + PUGI__FN xml_attribute::operator xml_attribute::unspecified_bool_type() const { return _attr ? unspecified_bool_xml_attribute : 0; } - bool xml_attribute::operator!() const + PUGI__FN bool xml_attribute::operator!() const { return !_attr; } - bool xml_attribute::operator==(const xml_attribute& r) const + PUGI__FN bool xml_attribute::operator==(const xml_attribute& r) const { return (_attr == r._attr); } - bool xml_attribute::operator!=(const xml_attribute& r) const + PUGI__FN bool xml_attribute::operator!=(const xml_attribute& r) const { return (_attr != r._attr); } - bool xml_attribute::operator<(const xml_attribute& r) const + PUGI__FN bool xml_attribute::operator<(const xml_attribute& r) const { return (_attr < r._attr); } - bool xml_attribute::operator>(const xml_attribute& r) const + PUGI__FN bool xml_attribute::operator>(const xml_attribute& r) const { return (_attr > r._attr); } - bool xml_attribute::operator<=(const xml_attribute& r) const + PUGI__FN bool xml_attribute::operator<=(const xml_attribute& r) const { return (_attr <= r._attr); } - bool xml_attribute::operator>=(const xml_attribute& r) const + PUGI__FN bool xml_attribute::operator>=(const xml_attribute& r) const { return (_attr >= r._attr); } - xml_attribute xml_attribute::next_attribute() const + PUGI__FN xml_attribute xml_attribute::next_attribute() const { return _attr ? xml_attribute(_attr->next_attribute) : xml_attribute(); } - xml_attribute xml_attribute::previous_attribute() const + PUGI__FN xml_attribute xml_attribute::previous_attribute() const { return _attr && _attr->prev_attribute_c->next_attribute ? xml_attribute(_attr->prev_attribute_c) : xml_attribute(); } - int xml_attribute::as_int() const + PUGI__FN int xml_attribute::as_int() const { if (!_attr || !_attr->value) return 0; @@ -3641,7 +3665,7 @@ namespace pugi #endif } - unsigned int xml_attribute::as_uint() const + PUGI__FN unsigned int xml_attribute::as_uint() const { if (!_attr || !_attr->value) return 0; @@ -3652,7 +3676,7 @@ namespace pugi #endif } - double xml_attribute::as_double() const + PUGI__FN double xml_attribute::as_double() const { if (!_attr || !_attr->value) return 0; @@ -3663,7 +3687,7 @@ namespace pugi #endif } - float xml_attribute::as_float() const + PUGI__FN float xml_attribute::as_float() const { if (!_attr || !_attr->value) return 0; @@ -3674,7 +3698,7 @@ namespace pugi #endif } - bool xml_attribute::as_bool() const + PUGI__FN bool xml_attribute::as_bool() const { if (!_attr || !_attr->value) return false; @@ -3685,83 +3709,83 @@ namespace pugi return (first == '1' || first == 't' || first == 'T' || first == 'y' || first == 'Y'); } - bool xml_attribute::empty() const + PUGI__FN bool xml_attribute::empty() const { return !_attr; } - const char_t* xml_attribute::name() const + PUGI__FN const char_t* xml_attribute::name() const { return (_attr && _attr->name) ? _attr->name : PUGIXML_TEXT(""); } - const char_t* xml_attribute::value() const + PUGI__FN const char_t* xml_attribute::value() const { return (_attr && _attr->value) ? _attr->value : PUGIXML_TEXT(""); } - size_t xml_attribute::hash_value() const + PUGI__FN size_t xml_attribute::hash_value() const { return static_cast(reinterpret_cast(_attr) / sizeof(xml_attribute_struct)); } - xml_attribute_struct* xml_attribute::internal_object() const + PUGI__FN xml_attribute_struct* xml_attribute::internal_object() const { return _attr; } - xml_attribute& xml_attribute::operator=(const char_t* rhs) + PUGI__FN xml_attribute& xml_attribute::operator=(const char_t* rhs) { set_value(rhs); return *this; } - xml_attribute& xml_attribute::operator=(int rhs) + PUGI__FN xml_attribute& xml_attribute::operator=(int rhs) { set_value(rhs); return *this; } - xml_attribute& xml_attribute::operator=(unsigned int rhs) + PUGI__FN xml_attribute& xml_attribute::operator=(unsigned int rhs) { set_value(rhs); return *this; } - xml_attribute& xml_attribute::operator=(double rhs) + PUGI__FN xml_attribute& xml_attribute::operator=(double rhs) { set_value(rhs); return *this; } - xml_attribute& xml_attribute::operator=(bool rhs) + PUGI__FN xml_attribute& xml_attribute::operator=(bool rhs) { set_value(rhs); return *this; } - bool xml_attribute::set_name(const char_t* rhs) + PUGI__FN bool xml_attribute::set_name(const char_t* rhs) { if (!_attr) return false; - return strcpy_insitu(_attr->name, _attr->header, xml_memory_page_name_allocated_mask, rhs); + return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs); } - bool xml_attribute::set_value(const char_t* rhs) + PUGI__FN bool xml_attribute::set_value(const char_t* rhs) { if (!_attr) return false; - return strcpy_insitu(_attr->value, _attr->header, xml_memory_page_value_allocated_mask, rhs); + return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs); } - bool xml_attribute::set_value(int rhs) + PUGI__FN bool xml_attribute::set_value(int rhs) { char buf[128]; sprintf(buf, "%d", rhs); #ifdef PUGIXML_WCHAR_MODE char_t wbuf[128]; - widen_ascii(wbuf, buf); + impl::widen_ascii(wbuf, buf); return set_value(wbuf); #else @@ -3769,14 +3793,14 @@ namespace pugi #endif } - bool xml_attribute::set_value(unsigned int rhs) + PUGI__FN bool xml_attribute::set_value(unsigned int rhs) { char buf[128]; sprintf(buf, "%u", rhs); #ifdef PUGIXML_WCHAR_MODE char_t wbuf[128]; - widen_ascii(wbuf, buf); + impl::widen_ascii(wbuf, buf); return set_value(wbuf); #else @@ -3784,14 +3808,14 @@ namespace pugi #endif } - bool xml_attribute::set_value(double rhs) + PUGI__FN bool xml_attribute::set_value(double rhs) { char buf[128]; sprintf(buf, "%g", rhs); #ifdef PUGIXML_WCHAR_MODE char_t wbuf[128]; - widen_ascii(wbuf, buf); + impl::widen_ascii(wbuf, buf); return set_value(wbuf); #else @@ -3799,147 +3823,147 @@ namespace pugi #endif } - bool xml_attribute::set_value(bool rhs) + PUGI__FN bool xml_attribute::set_value(bool rhs) { return set_value(rhs ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false")); } #ifdef __BORLANDC__ - bool operator&&(const xml_attribute& lhs, bool rhs) + PUGI__FN bool operator&&(const xml_attribute& lhs, bool rhs) { return (bool)lhs && rhs; } - bool operator||(const xml_attribute& lhs, bool rhs) + PUGI__FN bool operator||(const xml_attribute& lhs, bool rhs) { return (bool)lhs || rhs; } #endif - xml_node::xml_node(): _root(0) + PUGI__FN xml_node::xml_node(): _root(0) { } - xml_node::xml_node(xml_node_struct* p): _root(p) + PUGI__FN xml_node::xml_node(xml_node_struct* p): _root(p) { } - static void unspecified_bool_xml_node(xml_node***) + PUGI__FN static void unspecified_bool_xml_node(xml_node***) { } - xml_node::operator xml_node::unspecified_bool_type() const + PUGI__FN xml_node::operator xml_node::unspecified_bool_type() const { return _root ? unspecified_bool_xml_node : 0; } - bool xml_node::operator!() const + PUGI__FN bool xml_node::operator!() const { return !_root; } - xml_node::iterator xml_node::begin() const + PUGI__FN xml_node::iterator xml_node::begin() const { return iterator(_root ? _root->first_child : 0, _root); } - xml_node::iterator xml_node::end() const + PUGI__FN xml_node::iterator xml_node::end() const { return iterator(0, _root); } - xml_node::attribute_iterator xml_node::attributes_begin() const + PUGI__FN xml_node::attribute_iterator xml_node::attributes_begin() const { return attribute_iterator(_root ? _root->first_attribute : 0, _root); } - xml_node::attribute_iterator xml_node::attributes_end() const + PUGI__FN xml_node::attribute_iterator xml_node::attributes_end() const { return attribute_iterator(0, _root); } - bool xml_node::operator==(const xml_node& r) const + PUGI__FN bool xml_node::operator==(const xml_node& r) const { return (_root == r._root); } - bool xml_node::operator!=(const xml_node& r) const + PUGI__FN bool xml_node::operator!=(const xml_node& r) const { return (_root != r._root); } - bool xml_node::operator<(const xml_node& r) const + PUGI__FN bool xml_node::operator<(const xml_node& r) const { return (_root < r._root); } - bool xml_node::operator>(const xml_node& r) const + PUGI__FN bool xml_node::operator>(const xml_node& r) const { return (_root > r._root); } - bool xml_node::operator<=(const xml_node& r) const + PUGI__FN bool xml_node::operator<=(const xml_node& r) const { return (_root <= r._root); } - bool xml_node::operator>=(const xml_node& r) const + PUGI__FN bool xml_node::operator>=(const xml_node& r) const { return (_root >= r._root); } - bool xml_node::empty() const + PUGI__FN bool xml_node::empty() const { return !_root; } - const char_t* xml_node::name() const + PUGI__FN const char_t* xml_node::name() const { return (_root && _root->name) ? _root->name : PUGIXML_TEXT(""); } - xml_node_type xml_node::type() const + PUGI__FN xml_node_type xml_node::type() const { - return _root ? static_cast((_root->header & xml_memory_page_type_mask) + 1) : node_null; + return _root ? static_cast((_root->header & impl::xml_memory_page_type_mask) + 1) : node_null; } - const char_t* xml_node::value() const + PUGI__FN const char_t* xml_node::value() const { return (_root && _root->value) ? _root->value : PUGIXML_TEXT(""); } - xml_node xml_node::child(const char_t* name_) const + PUGI__FN xml_node xml_node::child(const char_t* name_) const { if (!_root) return xml_node(); for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) - if (i->name && strequal(name_, i->name)) return xml_node(i); + if (i->name && impl::strequal(name_, i->name)) return xml_node(i); return xml_node(); } - xml_attribute xml_node::attribute(const char_t* name_) const + PUGI__FN xml_attribute xml_node::attribute(const char_t* name_) const { if (!_root) return xml_attribute(); for (xml_attribute_struct* i = _root->first_attribute; i; i = i->next_attribute) - if (i->name && strequal(name_, i->name)) + if (i->name && impl::strequal(name_, i->name)) return xml_attribute(i); return xml_attribute(); } - xml_node xml_node::next_sibling(const char_t* name_) const + PUGI__FN xml_node xml_node::next_sibling(const char_t* name_) const { if (!_root) return xml_node(); for (xml_node_struct* i = _root->next_sibling; i; i = i->next_sibling) - if (i->name && strequal(name_, i->name)) return xml_node(i); + if (i->name && impl::strequal(name_, i->name)) return xml_node(i); return xml_node(); } - xml_node xml_node::next_sibling() const + PUGI__FN xml_node xml_node::next_sibling() const { if (!_root) return xml_node(); @@ -3947,17 +3971,17 @@ namespace pugi else return xml_node(); } - xml_node xml_node::previous_sibling(const char_t* name_) const + PUGI__FN xml_node xml_node::previous_sibling(const char_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) - if (i->name && strequal(name_, i->name)) return xml_node(i); + if (i->name && impl::strequal(name_, i->name)) return xml_node(i); return xml_node(); } - xml_node xml_node::previous_sibling() const + PUGI__FN xml_node xml_node::previous_sibling() const { if (!_root) return xml_node(); @@ -3965,27 +3989,27 @@ namespace pugi else return xml_node(); } - xml_node xml_node::parent() const + PUGI__FN xml_node xml_node::parent() const { return _root ? xml_node(_root->parent) : xml_node(); } - xml_node xml_node::root() const + PUGI__FN xml_node xml_node::root() const { if (!_root) return xml_node(); - xml_memory_page* page = reinterpret_cast(_root->header & xml_memory_page_pointer_mask); + impl::xml_memory_page* page = reinterpret_cast(_root->header & impl::xml_memory_page_pointer_mask); - return xml_node(static_cast(page->allocator)); + return xml_node(static_cast(page->allocator)); } - const char_t* xml_node::child_value() const + PUGI__FN const char_t* xml_node::child_value() const { if (!_root) return PUGIXML_TEXT(""); for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) { - xml_node_type type_ = static_cast((i->header & xml_memory_page_type_mask) + 1); + xml_node_type type_ = static_cast((i->header & impl::xml_memory_page_type_mask) + 1); if (i->value && (type_ == node_pcdata || type_ == node_cdata)) return i->value; @@ -3994,46 +4018,46 @@ namespace pugi return PUGIXML_TEXT(""); } - const char_t* xml_node::child_value(const char_t* name_) const + PUGI__FN const char_t* xml_node::child_value(const char_t* name_) const { return child(name_).child_value(); } - xml_attribute xml_node::first_attribute() const + PUGI__FN xml_attribute xml_node::first_attribute() const { return _root ? xml_attribute(_root->first_attribute) : xml_attribute(); } - xml_attribute xml_node::last_attribute() const + PUGI__FN xml_attribute xml_node::last_attribute() const { return _root && _root->first_attribute ? xml_attribute(_root->first_attribute->prev_attribute_c) : xml_attribute(); } - xml_node xml_node::first_child() const + PUGI__FN xml_node xml_node::first_child() const { return _root ? xml_node(_root->first_child) : xml_node(); } - xml_node xml_node::last_child() const + PUGI__FN xml_node xml_node::last_child() const { return _root && _root->first_child ? xml_node(_root->first_child->prev_sibling_c) : xml_node(); } - bool xml_node::set_name(const char_t* rhs) + PUGI__FN bool xml_node::set_name(const char_t* rhs) { switch (type()) { case node_pi: case node_declaration: case node_element: - return strcpy_insitu(_root->name, _root->header, xml_memory_page_name_allocated_mask, rhs); + return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs); default: return false; } } - bool xml_node::set_value(const char_t* rhs) + PUGI__FN bool xml_node::set_value(const char_t* rhs) { switch (type()) { @@ -4042,28 +4066,28 @@ namespace pugi case node_pcdata: case node_comment: case node_doctype: - return strcpy_insitu(_root->value, _root->header, xml_memory_page_value_allocated_mask, rhs); + return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs); default: return false; } } - xml_attribute xml_node::append_attribute(const char_t* name_) + PUGI__FN xml_attribute xml_node::append_attribute(const char_t* name_) { if (type() != node_element && type() != node_declaration) return xml_attribute(); - xml_attribute a(append_attribute_ll(_root, get_allocator(_root))); + xml_attribute a(impl::append_attribute_ll(_root, impl::get_allocator(_root))); a.set_name(name_); return a; } - xml_attribute xml_node::prepend_attribute(const char_t* name_) + PUGI__FN xml_attribute xml_node::prepend_attribute(const char_t* name_) { if (type() != node_element && type() != node_declaration) return xml_attribute(); - xml_attribute a(allocate_attribute(get_allocator(_root))); + xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root))); if (!a) return xml_attribute(); a.set_name(name_); @@ -4084,7 +4108,7 @@ namespace pugi return a; } - xml_attribute xml_node::insert_attribute_before(const char_t* name_, const xml_attribute& attr) + PUGI__FN xml_attribute xml_node::insert_attribute_before(const char_t* name_, const xml_attribute& attr) { if ((type() != node_element && type() != node_declaration) || attr.empty()) return xml_attribute(); @@ -4095,7 +4119,7 @@ namespace pugi if (cur != _root->first_attribute) return xml_attribute(); - xml_attribute a(allocate_attribute(get_allocator(_root))); + xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root))); if (!a) return xml_attribute(); a.set_name(name_); @@ -4112,7 +4136,7 @@ namespace pugi return a; } - xml_attribute xml_node::insert_attribute_after(const char_t* name_, const xml_attribute& attr) + PUGI__FN xml_attribute xml_node::insert_attribute_after(const char_t* name_, const xml_attribute& attr) { if ((type() != node_element && type() != node_declaration) || attr.empty()) return xml_attribute(); @@ -4123,7 +4147,7 @@ namespace pugi if (cur != _root->first_attribute) return xml_attribute(); - xml_attribute a(allocate_attribute(get_allocator(_root))); + xml_attribute a(impl::allocate_attribute(impl::get_allocator(_root))); if (!a) return xml_attribute(); a.set_name(name_); @@ -4140,7 +4164,7 @@ namespace pugi return a; } - xml_attribute xml_node::append_copy(const xml_attribute& proto) + PUGI__FN xml_attribute xml_node::append_copy(const xml_attribute& proto) { if (!proto) return xml_attribute(); @@ -4150,7 +4174,7 @@ namespace pugi return result; } - xml_attribute xml_node::prepend_copy(const xml_attribute& proto) + PUGI__FN xml_attribute xml_node::prepend_copy(const xml_attribute& proto) { if (!proto) return xml_attribute(); @@ -4160,7 +4184,7 @@ namespace pugi return result; } - xml_attribute xml_node::insert_copy_after(const xml_attribute& proto, const xml_attribute& attr) + PUGI__FN xml_attribute xml_node::insert_copy_after(const xml_attribute& proto, const xml_attribute& attr) { if (!proto) return xml_attribute(); @@ -4170,7 +4194,7 @@ namespace pugi return result; } - xml_attribute xml_node::insert_copy_before(const xml_attribute& proto, const xml_attribute& attr) + PUGI__FN xml_attribute xml_node::insert_copy_before(const xml_attribute& proto, const xml_attribute& attr) { if (!proto) return xml_attribute(); @@ -4180,22 +4204,22 @@ namespace pugi return result; } - xml_node xml_node::append_child(xml_node_type type_) + PUGI__FN xml_node xml_node::append_child(xml_node_type type_) { - if (!allow_insert_child(this->type(), type_)) return xml_node(); + if (!impl::allow_insert_child(this->type(), type_)) return xml_node(); - xml_node n(append_node(_root, get_allocator(_root), type_)); + xml_node n(impl::append_node(_root, impl::get_allocator(_root), type_)); if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml")); return n; } - xml_node xml_node::prepend_child(xml_node_type type_) + PUGI__FN xml_node xml_node::prepend_child(xml_node_type type_) { - if (!allow_insert_child(this->type(), type_)) return xml_node(); + if (!impl::allow_insert_child(this->type(), type_)) return xml_node(); - xml_node n(allocate_node(get_allocator(_root), type_)); + xml_node n(impl::allocate_node(impl::get_allocator(_root), type_)); if (!n) return xml_node(); n._root->parent = _root; @@ -4218,12 +4242,12 @@ namespace pugi return n; } - xml_node xml_node::insert_child_before(xml_node_type type_, const xml_node& node) + PUGI__FN xml_node xml_node::insert_child_before(xml_node_type type_, const xml_node& node) { - if (!allow_insert_child(this->type(), type_)) return xml_node(); + if (!impl::allow_insert_child(this->type(), type_)) return xml_node(); if (!node._root || node._root->parent != _root) return xml_node(); - xml_node n(allocate_node(get_allocator(_root), type_)); + xml_node n(impl::allocate_node(impl::get_allocator(_root), type_)); if (!n) return xml_node(); n._root->parent = _root; @@ -4242,12 +4266,12 @@ namespace pugi return n; } - xml_node xml_node::insert_child_after(xml_node_type type_, const xml_node& node) + PUGI__FN xml_node xml_node::insert_child_after(xml_node_type type_, const xml_node& node) { - if (!allow_insert_child(this->type(), type_)) return xml_node(); + if (!impl::allow_insert_child(this->type(), type_)) return xml_node(); if (!node._root || node._root->parent != _root) return xml_node(); - xml_node n(allocate_node(get_allocator(_root), type_)); + xml_node n(impl::allocate_node(impl::get_allocator(_root), type_)); if (!n) return xml_node(); n._root->parent = _root; @@ -4266,7 +4290,7 @@ namespace pugi return n; } - xml_node xml_node::append_child(const char_t* name_) + PUGI__FN xml_node xml_node::append_child(const char_t* name_) { xml_node result = append_child(node_element); @@ -4275,7 +4299,7 @@ namespace pugi return result; } - xml_node xml_node::prepend_child(const char_t* name_) + PUGI__FN xml_node xml_node::prepend_child(const char_t* name_) { xml_node result = prepend_child(node_element); @@ -4284,7 +4308,7 @@ namespace pugi return result; } - xml_node xml_node::insert_child_after(const char_t* name_, const xml_node& node) + PUGI__FN xml_node xml_node::insert_child_after(const char_t* name_, const xml_node& node) { xml_node result = insert_child_after(node_element, node); @@ -4293,7 +4317,7 @@ namespace pugi return result; } - xml_node xml_node::insert_child_before(const char_t* name_, const xml_node& node) + PUGI__FN xml_node xml_node::insert_child_before(const char_t* name_, const xml_node& node) { xml_node result = insert_child_before(node_element, node); @@ -4302,48 +4326,48 @@ namespace pugi return result; } - xml_node xml_node::append_copy(const xml_node& proto) + PUGI__FN xml_node xml_node::append_copy(const xml_node& proto) { xml_node result = append_child(proto.type()); - if (result) recursive_copy_skip(result, proto, result); + if (result) impl::recursive_copy_skip(result, proto, result); return result; } - xml_node xml_node::prepend_copy(const xml_node& proto) + PUGI__FN xml_node xml_node::prepend_copy(const xml_node& proto) { xml_node result = prepend_child(proto.type()); - if (result) recursive_copy_skip(result, proto, result); + if (result) impl::recursive_copy_skip(result, proto, result); return result; } - xml_node xml_node::insert_copy_after(const xml_node& proto, const xml_node& node) + PUGI__FN xml_node xml_node::insert_copy_after(const xml_node& proto, const xml_node& node) { xml_node result = insert_child_after(proto.type(), node); - if (result) recursive_copy_skip(result, proto, result); + if (result) impl::recursive_copy_skip(result, proto, result); return result; } - xml_node xml_node::insert_copy_before(const xml_node& proto, const xml_node& node) + PUGI__FN xml_node xml_node::insert_copy_before(const xml_node& proto, const xml_node& node) { xml_node result = insert_child_before(proto.type(), node); - if (result) recursive_copy_skip(result, proto, result); + if (result) impl::recursive_copy_skip(result, proto, result); return result; } - bool xml_node::remove_attribute(const char_t* name_) + PUGI__FN bool xml_node::remove_attribute(const char_t* name_) { return remove_attribute(attribute(name_)); } - bool xml_node::remove_attribute(const xml_attribute& a) + PUGI__FN bool xml_node::remove_attribute(const xml_attribute& a) { if (!_root || !a._attr) return false; @@ -4360,17 +4384,17 @@ namespace pugi if (a._attr->prev_attribute_c->next_attribute) a._attr->prev_attribute_c->next_attribute = a._attr->next_attribute; else _root->first_attribute = a._attr->next_attribute; - destroy_attribute(a._attr, get_allocator(_root)); + impl::destroy_attribute(a._attr, impl::get_allocator(_root)); return true; } - bool xml_node::remove_child(const char_t* name_) + PUGI__FN bool xml_node::remove_child(const char_t* name_) { return remove_child(child(name_)); } - bool xml_node::remove_child(const xml_node& n) + PUGI__FN bool xml_node::remove_child(const xml_node& n) { if (!_root || !n._root || n._root->parent != _root) return false; @@ -4380,40 +4404,40 @@ namespace pugi if (n._root->prev_sibling_c->next_sibling) n._root->prev_sibling_c->next_sibling = n._root->next_sibling; else _root->first_child = n._root->next_sibling; - destroy_node(n._root, get_allocator(_root)); + impl::destroy_node(n._root, impl::get_allocator(_root)); return true; } - xml_node xml_node::find_child_by_attribute(const char_t* name_, const char_t* attr_name, const char_t* attr_value) const + PUGI__FN xml_node xml_node::find_child_by_attribute(const char_t* name_, const char_t* attr_name, const char_t* attr_value) const { if (!_root) return xml_node(); for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) - if (i->name && strequal(name_, i->name)) + if (i->name && impl::strequal(name_, i->name)) { for (xml_attribute_struct* a = i->first_attribute; a; a = a->next_attribute) - if (strequal(attr_name, a->name) && strequal(attr_value, a->value)) + if (impl::strequal(attr_name, a->name) && impl::strequal(attr_value, a->value)) return xml_node(i); } return xml_node(); } - xml_node xml_node::find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const + PUGI__FN xml_node xml_node::find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const { if (!_root) return xml_node(); for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) for (xml_attribute_struct* a = i->first_attribute; a; a = a->next_attribute) - if (strequal(attr_name, a->name) && strequal(attr_value, a->value)) + if (impl::strequal(attr_name, a->name) && impl::strequal(attr_value, a->value)) return xml_node(i); return xml_node(); } #ifndef PUGIXML_NO_STL - string_t xml_node::path(char_t delimiter) const + PUGI__FN string_t xml_node::path(char_t delimiter) const { xml_node cursor = *this; // Make a copy. @@ -4433,7 +4457,7 @@ namespace pugi } #endif - xml_node xml_node::first_element_by_path(const char_t* path_, char_t delimiter) const + PUGI__FN xml_node xml_node::first_element_by_path(const char_t* path_, char_t delimiter) const { xml_node found = *this; // Current search context. @@ -4468,7 +4492,7 @@ namespace pugi { for (xml_node_struct* j = found._root->first_child; j; j = j->next_sibling) { - if (j->name && strequalrange(j->name, path_segment, static_cast(path_segment_end - path_segment))) + if (j->name && impl::strequalrange(j->name, path_segment, static_cast(path_segment_end - path_segment))) { xml_node subsearch = xml_node(j).first_element_by_path(next_segment, delimiter); @@ -4480,7 +4504,7 @@ namespace pugi } } - bool xml_node::traverse(xml_tree_walker& walker) + PUGI__FN bool xml_node::traverse(xml_tree_walker& walker) { walker._depth = -1; @@ -4528,34 +4552,34 @@ namespace pugi return walker.end(arg_end); } - size_t xml_node::hash_value() const + PUGI__FN size_t xml_node::hash_value() const { return static_cast(reinterpret_cast(_root) / sizeof(xml_node_struct)); } - xml_node_struct* xml_node::internal_object() const + PUGI__FN xml_node_struct* xml_node::internal_object() const { return _root; } - void xml_node::print(xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding, unsigned int depth) const + PUGI__FN void xml_node::print(xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding, unsigned int depth) const { if (!_root) return; - xml_buffered_writer buffered_writer(writer, encoding); + impl::xml_buffered_writer buffered_writer(writer, encoding); - node_output(buffered_writer, *this, indent, flags, depth); + impl::node_output(buffered_writer, *this, indent, flags, depth); } #ifndef PUGIXML_NO_STL - void xml_node::print(std::basic_ostream >& stream, const char_t* indent, unsigned int flags, xml_encoding encoding, unsigned int depth) const + PUGI__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); } - void xml_node::print(std::basic_ostream >& stream, const char_t* indent, unsigned int flags, unsigned int depth) const + PUGI__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); @@ -4563,13 +4587,13 @@ namespace pugi } #endif - ptrdiff_t xml_node::offset_debug() const + PUGI__FN ptrdiff_t xml_node::offset_debug() const { xml_node_struct* r = root()._root; if (!r) return -1; - const char_t* buffer = static_cast(r)->buffer; + const char_t* buffer = static_cast(r)->buffer; if (!buffer) return -1; @@ -4581,13 +4605,13 @@ namespace pugi case node_element: case node_declaration: case node_pi: - return (_root->header & xml_memory_page_name_allocated_mask) ? -1 : _root->name - buffer; + return (_root->header & impl::xml_memory_page_name_allocated_mask) ? -1 : _root->name - buffer; case node_pcdata: case node_cdata: case node_comment: case node_doctype: - return (_root->header & xml_memory_page_value_allocated_mask) ? -1 : _root->value - buffer; + return (_root->header & impl::xml_memory_page_value_allocated_mask) ? -1 : _root->value - buffer; default: return -1; @@ -4595,149 +4619,149 @@ namespace pugi } #ifdef __BORLANDC__ - bool operator&&(const xml_node& lhs, bool rhs) + PUGI__FN bool operator&&(const xml_node& lhs, bool rhs) { return (bool)lhs && rhs; } - bool operator||(const xml_node& lhs, bool rhs) + PUGI__FN bool operator||(const xml_node& lhs, bool rhs) { return (bool)lhs || rhs; } #endif - xml_node_iterator::xml_node_iterator() + PUGI__FN xml_node_iterator::xml_node_iterator() { } - xml_node_iterator::xml_node_iterator(const xml_node& node): _wrap(node), _parent(node.parent()) + PUGI__FN xml_node_iterator::xml_node_iterator(const xml_node& node): _wrap(node), _parent(node.parent()) { } - xml_node_iterator::xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent): _wrap(ref), _parent(parent) + PUGI__FN xml_node_iterator::xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent): _wrap(ref), _parent(parent) { } - bool xml_node_iterator::operator==(const xml_node_iterator& rhs) const + PUGI__FN bool xml_node_iterator::operator==(const xml_node_iterator& rhs) const { return _wrap._root == rhs._wrap._root && _parent._root == rhs._parent._root; } - bool xml_node_iterator::operator!=(const xml_node_iterator& rhs) const + PUGI__FN bool xml_node_iterator::operator!=(const xml_node_iterator& rhs) const { return _wrap._root != rhs._wrap._root || _parent._root != rhs._parent._root; } - xml_node& xml_node_iterator::operator*() + PUGI__FN xml_node& xml_node_iterator::operator*() { assert(_wrap._root); return _wrap; } - xml_node* xml_node_iterator::operator->() + PUGI__FN xml_node* xml_node_iterator::operator->() { assert(_wrap._root); return &_wrap; } - const xml_node_iterator& xml_node_iterator::operator++() + PUGI__FN const xml_node_iterator& xml_node_iterator::operator++() { assert(_wrap._root); _wrap._root = _wrap._root->next_sibling; return *this; } - xml_node_iterator xml_node_iterator::operator++(int) + PUGI__FN xml_node_iterator xml_node_iterator::operator++(int) { xml_node_iterator temp = *this; ++*this; return temp; } - const xml_node_iterator& xml_node_iterator::operator--() + PUGI__FN const xml_node_iterator& xml_node_iterator::operator--() { _wrap = _wrap._root ? _wrap.previous_sibling() : _parent.last_child(); return *this; } - xml_node_iterator xml_node_iterator::operator--(int) + PUGI__FN xml_node_iterator xml_node_iterator::operator--(int) { xml_node_iterator temp = *this; --*this; return temp; } - xml_attribute_iterator::xml_attribute_iterator() + PUGI__FN xml_attribute_iterator::xml_attribute_iterator() { } - xml_attribute_iterator::xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent): _wrap(attr), _parent(parent) + PUGI__FN xml_attribute_iterator::xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent): _wrap(attr), _parent(parent) { } - xml_attribute_iterator::xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent): _wrap(ref), _parent(parent) + PUGI__FN xml_attribute_iterator::xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent): _wrap(ref), _parent(parent) { } - bool xml_attribute_iterator::operator==(const xml_attribute_iterator& rhs) const + PUGI__FN bool xml_attribute_iterator::operator==(const xml_attribute_iterator& rhs) const { return _wrap._attr == rhs._wrap._attr && _parent._root == rhs._parent._root; } - bool xml_attribute_iterator::operator!=(const xml_attribute_iterator& rhs) const + PUGI__FN bool xml_attribute_iterator::operator!=(const xml_attribute_iterator& rhs) const { return _wrap._attr != rhs._wrap._attr || _parent._root != rhs._parent._root; } - xml_attribute& xml_attribute_iterator::operator*() + PUGI__FN xml_attribute& xml_attribute_iterator::operator*() { assert(_wrap._attr); return _wrap; } - xml_attribute* xml_attribute_iterator::operator->() + PUGI__FN xml_attribute* xml_attribute_iterator::operator->() { assert(_wrap._attr); return &_wrap; } - const xml_attribute_iterator& xml_attribute_iterator::operator++() + PUGI__FN const xml_attribute_iterator& xml_attribute_iterator::operator++() { assert(_wrap._attr); _wrap._attr = _wrap._attr->next_attribute; return *this; } - xml_attribute_iterator xml_attribute_iterator::operator++(int) + PUGI__FN xml_attribute_iterator xml_attribute_iterator::operator++(int) { xml_attribute_iterator temp = *this; ++*this; return temp; } - const xml_attribute_iterator& xml_attribute_iterator::operator--() + PUGI__FN const xml_attribute_iterator& xml_attribute_iterator::operator--() { _wrap = _wrap._attr ? _wrap.previous_attribute() : _parent.last_attribute(); return *this; } - xml_attribute_iterator xml_attribute_iterator::operator--(int) + PUGI__FN xml_attribute_iterator xml_attribute_iterator::operator--(int) { xml_attribute_iterator temp = *this; --*this; return temp; } - xml_parse_result::xml_parse_result(): status(status_internal_error), offset(0), encoding(encoding_auto) + PUGI__FN xml_parse_result::xml_parse_result(): status(status_internal_error), offset(0), encoding(encoding_auto) { } - xml_parse_result::operator bool() const + PUGI__FN xml_parse_result::operator bool() const { return status == status_ok; } - const char* xml_parse_result::description() const + PUGI__FN const char* xml_parse_result::description() const { switch (status) { @@ -4764,23 +4788,23 @@ namespace pugi } } - xml_document::xml_document(): _buffer(0) + PUGI__FN xml_document::xml_document(): _buffer(0) { create(); } - xml_document::~xml_document() + PUGI__FN xml_document::~xml_document() { destroy(); } - void xml_document::reset() + PUGI__FN void xml_document::reset() { destroy(); create(); } - void xml_document::reset(const xml_document& proto) + PUGI__FN void xml_document::reset(const xml_document& proto) { reset(); @@ -4788,48 +4812,48 @@ namespace pugi append_copy(cur); } - void xml_document::create() + PUGI__FN void xml_document::create() { // initialize sentinel page - STATIC_ASSERT(offsetof(xml_memory_page, data) + sizeof(xml_document_struct) + xml_memory_page_alignment <= sizeof(_memory)); + PUGI__STATIC_ASSERT(offsetof(impl::xml_memory_page, data) + sizeof(impl::xml_document_struct) + impl::xml_memory_page_alignment <= sizeof(_memory)); // align upwards to page boundary - void* page_memory = reinterpret_cast((reinterpret_cast(_memory) + (xml_memory_page_alignment - 1)) & ~(xml_memory_page_alignment - 1)); + void* page_memory = reinterpret_cast((reinterpret_cast(_memory) + (impl::xml_memory_page_alignment - 1)) & ~(impl::xml_memory_page_alignment - 1)); // prepare page structure - xml_memory_page* page = xml_memory_page::construct(page_memory); + impl::xml_memory_page* page = impl::xml_memory_page::construct(page_memory); - page->busy_size = xml_memory_page_size; + page->busy_size = impl::xml_memory_page_size; // allocate new root - _root = new (page->data) xml_document_struct(page); + _root = new (page->data) impl::xml_document_struct(page); _root->prev_sibling_c = _root; // setup sentinel page - page->allocator = static_cast(_root); + page->allocator = static_cast(_root); } - void xml_document::destroy() + PUGI__FN void xml_document::destroy() { // destroy static storage if (_buffer) { - global_deallocate(_buffer); + impl::xml_memory::deallocate(_buffer); _buffer = 0; } // destroy dynamic storage, leave sentinel page (it's in static memory) if (_root) { - xml_memory_page* root_page = reinterpret_cast(_root->header & xml_memory_page_pointer_mask); + impl::xml_memory_page* root_page = reinterpret_cast(_root->header & impl::xml_memory_page_pointer_mask); assert(root_page && !root_page->prev && !root_page->memory); // destroy all pages - for (xml_memory_page* page = root_page->next; page; ) + for (impl::xml_memory_page* page = root_page->next; page; ) { - xml_memory_page* next = page->next; + impl::xml_memory_page* next = page->next; - xml_allocator::deallocate_page(page); + impl::xml_allocator::deallocate_page(page); page = next; } @@ -4844,22 +4868,22 @@ namespace pugi } #ifndef PUGIXML_NO_STL - xml_parse_result xml_document::load(std::basic_istream >& stream, unsigned int options, xml_encoding encoding) + PUGI__FN xml_parse_result xml_document::load(std::basic_istream >& stream, unsigned int options, xml_encoding encoding) { reset(); - return load_stream_impl(*this, stream, options, encoding); + return impl::load_stream_impl(*this, stream, options, encoding); } - xml_parse_result xml_document::load(std::basic_istream >& stream, unsigned int options) + PUGI__FN xml_parse_result xml_document::load(std::basic_istream >& stream, unsigned int options) { reset(); - return load_stream_impl(*this, stream, options, encoding_wchar); + return impl::load_stream_impl(*this, stream, options, encoding_wchar); } #endif - xml_parse_result xml_document::load(const char_t* contents, unsigned int options) + PUGI__FN xml_parse_result xml_document::load(const char_t* contents, unsigned int options) { // Force native encoding (skip autodetection) #ifdef PUGIXML_WCHAR_MODE @@ -4868,28 +4892,28 @@ namespace pugi xml_encoding encoding = encoding_utf8; #endif - return load_buffer(contents, strlength(contents) * sizeof(char_t), options, encoding); + return load_buffer(contents, impl::strlength(contents) * sizeof(char_t), options, encoding); } - xml_parse_result xml_document::load_file(const char* path_, unsigned int options, xml_encoding encoding) + PUGI__FN xml_parse_result xml_document::load_file(const char* path_, unsigned int options, xml_encoding encoding) { reset(); FILE* file = fopen(path_, "rb"); - return load_file_impl(*this, file, options, encoding); + return impl::load_file_impl(*this, file, options, encoding); } - xml_parse_result xml_document::load_file(const wchar_t* path_, unsigned int options, xml_encoding encoding) + PUGI__FN xml_parse_result xml_document::load_file(const wchar_t* path_, unsigned int options, xml_encoding encoding) { reset(); - FILE* file = open_file_wide(path_, L"rb"); + FILE* file = impl::open_file_wide(path_, L"rb"); - return load_file_impl(*this, file, options, encoding); + return impl::load_file_impl(*this, file, options, encoding); } - xml_parse_result xml_document::load_buffer_impl(void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own) + PUGI__FN xml_parse_result xml_document::load_buffer_impl(void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own) { reset(); @@ -4897,19 +4921,19 @@ namespace pugi assert(contents || size == 0); // get actual encoding - xml_encoding buffer_encoding = get_buffer_encoding(encoding, contents, size); + xml_encoding buffer_encoding = impl::get_buffer_encoding(encoding, contents, size); // get private buffer char_t* buffer = 0; size_t length = 0; - if (!convert_buffer(buffer, length, buffer_encoding, contents, size, is_mutable)) return make_parse_result(status_out_of_memory); + if (!impl::convert_buffer(buffer, length, buffer_encoding, contents, size, is_mutable)) return impl::make_parse_result(status_out_of_memory); // delete original buffer if we performed a conversion - if (own && buffer != contents && contents) global_deallocate(contents); + if (own && buffer != contents && contents) impl::xml_memory::deallocate(contents); // parse - xml_parse_result res = xml_parser::parse(buffer, length, _root, options); + xml_parse_result res = impl::xml_parser::parse(buffer, length, _root, options); // remember encoding res.encoding = buffer_encoding; @@ -4920,28 +4944,28 @@ namespace pugi return res; } - xml_parse_result xml_document::load_buffer(const void* contents, size_t size, unsigned int options, xml_encoding encoding) + PUGI__FN xml_parse_result xml_document::load_buffer(const void* contents, size_t size, unsigned int options, xml_encoding encoding) { return load_buffer_impl(const_cast(contents), size, options, encoding, false, false); } - xml_parse_result xml_document::load_buffer_inplace(void* contents, size_t size, unsigned int options, xml_encoding encoding) + PUGI__FN xml_parse_result xml_document::load_buffer_inplace(void* contents, size_t size, unsigned int options, xml_encoding encoding) { return load_buffer_impl(contents, size, options, encoding, true, false); } - xml_parse_result xml_document::load_buffer_inplace_own(void* contents, size_t size, unsigned int options, xml_encoding encoding) + PUGI__FN xml_parse_result xml_document::load_buffer_inplace_own(void* contents, size_t size, unsigned int options, xml_encoding encoding) { return load_buffer_impl(contents, size, options, encoding, true, true); } - void xml_document::save(xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding) const + PUGI__FN void xml_document::save(xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding) const { - if (flags & format_write_bom) write_bom(writer, get_write_encoding(encoding)); + if (flags & format_write_bom) impl::write_bom(writer, impl::get_write_encoding(encoding)); - xml_buffered_writer buffered_writer(writer, encoding); + impl::xml_buffered_writer buffered_writer(writer, encoding); - if (!(flags & format_no_declaration) && !has_declaration(*this)) + if (!(flags & format_no_declaration) && !impl::has_declaration(*this)) { buffered_writer.write(PUGIXML_TEXT(" >& stream, const char_t* indent, unsigned int flags, xml_encoding encoding) const + PUGI__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); } - void xml_document::save(std::basic_ostream >& stream, const char_t* indent, unsigned int flags) const + PUGI__FN void xml_document::save(std::basic_ostream >& stream, const char_t* indent, unsigned int flags) const { xml_writer_stream writer(stream); @@ -4968,7 +4992,7 @@ namespace pugi } #endif - 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 { FILE* file = fopen(path_, "wb"); if (!file) return false; @@ -4981,9 +5005,9 @@ namespace pugi return true; } - bool xml_document::save_file(const wchar_t* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const + PUGI__FN bool xml_document::save_file(const wchar_t* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const { - FILE* file = open_file_wide(path_, L"wb"); + FILE* file = impl::open_file_wide(path_, L"wb"); if (!file) return false; xml_writer_file writer(file); @@ -4994,55 +5018,55 @@ namespace pugi return true; } - xml_node xml_document::document_element() const + PUGI__FN xml_node xml_document::document_element() const { for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) - if ((i->header & xml_memory_page_type_mask) + 1 == node_element) + if ((i->header & impl::xml_memory_page_type_mask) + 1 == node_element) return xml_node(i); return xml_node(); } #ifndef PUGIXML_NO_STL - std::string PUGIXML_FUNCTION as_utf8(const wchar_t* str) + PUGI__FN std::string PUGIXML_FUNCTION as_utf8(const wchar_t* str) { assert(str); - return as_utf8_impl(str, wcslen(str)); + return impl::as_utf8_impl(str, wcslen(str)); } - std::string PUGIXML_FUNCTION as_utf8(const std::basic_string& str) + PUGI__FN std::string PUGIXML_FUNCTION as_utf8(const std::basic_string& str) { - return as_utf8_impl(str.c_str(), str.size()); + return impl::as_utf8_impl(str.c_str(), str.size()); } - std::basic_string PUGIXML_FUNCTION as_wide(const char* str) + PUGI__FN std::basic_string PUGIXML_FUNCTION as_wide(const char* str) { assert(str); - return as_wide_impl(str, strlen(str)); + return impl::as_wide_impl(str, strlen(str)); } - std::basic_string PUGIXML_FUNCTION as_wide(const std::string& str) + PUGI__FN std::basic_string PUGIXML_FUNCTION as_wide(const std::string& str) { - return as_wide_impl(str.c_str(), str.size()); + return impl::as_wide_impl(str.c_str(), str.size()); } #endif - void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate) + PUGI__FN void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate) { - global_allocate = allocate; - global_deallocate = deallocate; + impl::xml_memory::allocate = allocate; + impl::xml_memory::deallocate = deallocate; } - allocation_function PUGIXML_FUNCTION get_memory_allocation_function() + PUGI__FN allocation_function PUGIXML_FUNCTION get_memory_allocation_function() { - return global_allocate; + return impl::xml_memory::allocate; } - deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function() + PUGI__FN deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function() { - return global_deallocate; + return impl::xml_memory::deallocate; } } @@ -5050,12 +5074,12 @@ namespace pugi namespace std { // Workarounds for (non-standard) iterator category detection for older versions (MSVC7/IC8 and earlier) - std::bidirectional_iterator_tag _Iter_cat(const xml_node_iterator&) + PUGI__FN std::bidirectional_iterator_tag _Iter_cat(const pugi::xml_node_iterator&) { return std::bidirectional_iterator_tag(); } - std::bidirectional_iterator_tag _Iter_cat(const xml_attribute_iterator&) + PUGI__FN std::bidirectional_iterator_tag _Iter_cat(const pugi::xml_attribute_iterator&) { return std::bidirectional_iterator_tag(); } @@ -5066,12 +5090,12 @@ namespace std namespace std { // Workarounds for (non-standard) iterator category detection - std::bidirectional_iterator_tag __iterator_category(const xml_node_iterator&) + PUGI__FN std::bidirectional_iterator_tag __iterator_category(const pugi::xml_node_iterator&) { return std::bidirectional_iterator_tag(); } - std::bidirectional_iterator_tag __iterator_category(const xml_attribute_iterator&) + PUGI__FN std::bidirectional_iterator_tag __iterator_category(const pugi::xml_attribute_iterator&) { return std::bidirectional_iterator_tag(); } @@ -5081,8 +5105,7 @@ namespace std #ifndef PUGIXML_NO_XPATH // STL replacements -namespace -{ +PUGI__NS_BEGIN struct equal_to { template bool operator()(const T& lhs, const T& rhs) const @@ -5306,11 +5329,10 @@ namespace // insertion sort small chunk if (begin != end) insertion_sort(begin, end, pred, &*begin); } -} +PUGI__NS_END // Allocator used for AST and evaluation stacks -namespace -{ +PUGI__NS_BEGIN struct xpath_memory_block { xpath_memory_block* next; @@ -5353,7 +5375,7 @@ namespace size_t block_data_size = (size > block_capacity) ? size : block_capacity; size_t block_size = block_data_size + offsetof(xpath_memory_block, data); - xpath_memory_block* block = static_cast(global_allocate(block_size)); + xpath_memory_block* block = static_cast(xml_memory::allocate(block_size)); if (!block) return 0; block->next = _root; @@ -5418,7 +5440,7 @@ namespace if (next) { // deallocate the whole page, unless it was the first one - global_deallocate(_root->next); + xml_memory::deallocate(_root->next); _root->next = next; } } @@ -5436,7 +5458,7 @@ namespace { xpath_memory_block* next = cur->next; - global_deallocate(cur); + xml_memory::deallocate(cur); cur = next; } @@ -5455,7 +5477,7 @@ namespace { xpath_memory_block* next = cur->next; - global_deallocate(cur); + xml_memory::deallocate(cur); cur = next; } @@ -5512,11 +5534,10 @@ namespace temp.release(); } }; -} +PUGI__NS_END // String class -namespace -{ +PUGI__NS_BEGIN class xpath_string { const char_t* _buffer; @@ -5642,15 +5663,14 @@ namespace } }; - xpath_string xpath_string_const(const char_t* str) + PUGI__FN xpath_string xpath_string_const(const char_t* str) { return xpath_string(str, false); } -} +PUGI__NS_END -namespace -{ - bool starts_with(const char_t* string, const char_t* pattern) +PUGI__NS_BEGIN + PUGI__FN bool starts_with(const char_t* string, const char_t* pattern) { while (*pattern && *string == *pattern) { @@ -5661,7 +5681,7 @@ namespace return *pattern == 0; } - const char_t* find_char(const char_t* s, char_t c) + PUGI__FN const char_t* find_char(const char_t* s, char_t c) { #ifdef PUGIXML_WCHAR_MODE return wcschr(s, c); @@ -5670,7 +5690,7 @@ namespace #endif } - const char_t* find_substring(const char_t* s, const char_t* p) + PUGI__FN const char_t* find_substring(const char_t* s, const char_t* p) { #ifdef PUGIXML_WCHAR_MODE // MSVC6 wcsstr bug workaround (if s is empty it always returns 0) @@ -5681,12 +5701,12 @@ namespace } // Converts symbol to lower case, if it is an ASCII one - char_t tolower_ascii(char_t ch) + PUGI__FN char_t tolower_ascii(char_t ch) { return static_cast(ch - 'A') < 26 ? static_cast(ch | ' ') : ch; } - xpath_string string_value(const xpath_node& na, xpath_allocator* alloc) + PUGI__FN xpath_string string_value(const xpath_node& na, xpath_allocator* alloc) { if (na.attribute()) return xpath_string_const(na.attribute().value()); @@ -5736,7 +5756,7 @@ namespace } } - unsigned int node_height(xml_node n) + PUGI__FN unsigned int node_height(xml_node n) { unsigned int result = 0; @@ -5749,7 +5769,7 @@ namespace return result; } - bool node_is_before(xml_node ln, unsigned int lh, xml_node rn, unsigned int rh) + PUGI__FN bool node_is_before(xml_node ln, unsigned int lh, xml_node rn, unsigned int rh) { // normalize heights for (unsigned int i = rh; i < lh; i++) ln = ln.parent(); @@ -5776,14 +5796,14 @@ namespace return false; } - bool node_is_ancestor(xml_node parent, xml_node node) + PUGI__FN bool node_is_ancestor(xml_node parent, xml_node node) { while (node && node != parent) node = node.parent(); return parent && node == parent; } - const void* document_order(const xpath_node& xnode) + PUGI__FN const void* document_order(const xpath_node& xnode) { xml_node_struct* node = xnode.node().internal_object(); @@ -5870,10 +5890,10 @@ namespace } }; - double gen_nan() + PUGI__FN double gen_nan() { #if defined(__STDC_IEC_559__) || ((FLT_RADIX - 0 == 2) && (FLT_MAX_EXP - 0 == 128) && (FLT_MANT_DIG - 0 == 24)) - union { float f; int32_t i; } u[sizeof(float) == sizeof(int32_t) ? 1 : -1]; + union { float f; uint32_t i; } u[sizeof(float) == sizeof(uint32_t) ? 1 : -1]; u[0].i = 0x7fc00000; return u[0].f; #else @@ -5883,9 +5903,9 @@ namespace #endif } - bool is_nan(double value) + PUGI__FN bool is_nan(double value) { - #if defined(MSVC_CRT_VERSION) || defined(__BORLANDC__) + #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) return !!_isnan(value); #elif defined(fpclassify) && defined(FP_NAN) return fpclassify(value) == FP_NAN; @@ -5896,9 +5916,9 @@ namespace #endif } - const char_t* convert_number_to_string_special(double value) + PUGI__FN const char_t* convert_number_to_string_special(double value) { - #if defined(MSVC_CRT_VERSION) || defined(__BORLANDC__) + #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) if (_finite(value)) return (value == 0) ? PUGIXML_TEXT("0") : 0; if (_isnan(value)) return PUGIXML_TEXT("NaN"); return value > 0 ? PUGIXML_TEXT("Infinity") : PUGIXML_TEXT("-Infinity"); @@ -5928,12 +5948,12 @@ namespace #endif } - bool convert_number_to_boolean(double value) + PUGI__FN bool convert_number_to_boolean(double value) { return (value != 0 && !is_nan(value)); } - void truncate_zeros(char* begin, char* end) + PUGI__FN void truncate_zeros(char* begin, char* end) { while (begin != end && end[-1] == '0') end--; @@ -5941,8 +5961,8 @@ namespace } // gets mantissa digits in the form of 0.xxxxx with 0. implied and the exponent -#if defined(MSVC_CRT_VERSION) && MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE) - void convert_number_to_mantissa_exponent(double value, char* buffer, size_t buffer_size, char** out_mantissa, int* out_exponent) +#if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE) + PUGI__FN void convert_number_to_mantissa_exponent(double value, char* buffer, size_t buffer_size, char** out_mantissa, int* out_exponent) { // get base values int sign, exponent; @@ -5956,7 +5976,7 @@ namespace *out_exponent = exponent; } #else - void convert_number_to_mantissa_exponent(double value, char* buffer, size_t buffer_size, char** out_mantissa, int* out_exponent) + PUGI__FN void convert_number_to_mantissa_exponent(double value, char* buffer, size_t buffer_size, char** out_mantissa, int* out_exponent) { // get a scientific notation value with IEEE DBL_DIG decimals sprintf(buffer, "%.*e", DBL_DIG, value); @@ -5987,7 +6007,7 @@ namespace } #endif - xpath_string convert_number_to_string(double value, xpath_allocator* alloc) + PUGI__FN xpath_string convert_number_to_string(double value, xpath_allocator* alloc) { // try special number conversion const char_t* special = convert_number_to_string_special(value); @@ -6050,10 +6070,10 @@ namespace return xpath_string(result, alloc); } - bool check_string_to_number_format(const char_t* string) + PUGI__FN bool check_string_to_number_format(const char_t* string) { // parse leading whitespace - while (IS_CHARTYPE(*string, ct_space)) ++string; + while (PUGI__IS_CHARTYPE(*string, ct_space)) ++string; // parse sign if (*string == '-') ++string; @@ -6061,26 +6081,26 @@ namespace if (!*string) return false; // if there is no integer part, there should be a decimal part with at least one digit - if (!IS_CHARTYPEX(string[0], ctx_digit) && (string[0] != '.' || !IS_CHARTYPEX(string[1], ctx_digit))) return false; + if (!PUGI__IS_CHARTYPEX(string[0], ctx_digit) && (string[0] != '.' || !PUGI__IS_CHARTYPEX(string[1], ctx_digit))) return false; // parse integer part - while (IS_CHARTYPEX(*string, ctx_digit)) ++string; + while (PUGI__IS_CHARTYPEX(*string, ctx_digit)) ++string; // parse decimal part if (*string == '.') { ++string; - while (IS_CHARTYPEX(*string, ctx_digit)) ++string; + while (PUGI__IS_CHARTYPEX(*string, ctx_digit)) ++string; } // parse trailing whitespace - while (IS_CHARTYPE(*string, ct_space)) ++string; + while (PUGI__IS_CHARTYPE(*string, ct_space)) ++string; return *string == 0; } - double convert_string_to_number(const char_t* string) + PUGI__FN double convert_string_to_number(const char_t* string) { // check string format if (!check_string_to_number_format(string)) return gen_nan(); @@ -6093,7 +6113,7 @@ namespace #endif } - bool convert_string_to_number(const char_t* begin, const char_t* end, double* out_result) + PUGI__FN bool convert_string_to_number(const char_t* begin, const char_t* end, double* out_result) { char_t buffer[32]; @@ -6103,7 +6123,7 @@ namespace if (length >= sizeof(buffer) / sizeof(buffer[0])) { // need to make dummy on-heap copy - scratch = static_cast(global_allocate((length + 1) * sizeof(char_t))); + scratch = static_cast(xml_memory::allocate((length + 1) * sizeof(char_t))); if (!scratch) return false; } @@ -6114,29 +6134,29 @@ namespace *out_result = convert_string_to_number(scratch); // free dummy buffer - if (scratch != buffer) global_deallocate(scratch); + if (scratch != buffer) xml_memory::deallocate(scratch); return true; } - double round_nearest(double value) + PUGI__FN double round_nearest(double value) { return floor(value + 0.5); } - double round_nearest_nzero(double value) + PUGI__FN double round_nearest_nzero(double value) { // same as round_nearest, but returns -0 for [-0.5, -0] // ceil is used to differentiate between +0 and -0 (we return -0 for [-0.5, -0] and +0 for +0) return (value >= -0.5 && value <= 0) ? ceil(value) : floor(value + 0.5); } - const char_t* qualified_name(const xpath_node& node) + PUGI__FN const char_t* qualified_name(const xpath_node& node) { return node.attribute() ? node.attribute().name() : node.node().name(); } - const char_t* local_name(const xpath_node& node) + PUGI__FN const char_t* local_name(const xpath_node& node) { const char_t* name = qualified_name(node); const char_t* p = find_char(name, ':'); @@ -6167,7 +6187,7 @@ namespace } }; - const char_t* namespace_uri(const xml_node& node) + PUGI__FN const char_t* namespace_uri(const xml_node& node) { namespace_uri_predicate pred = node.name(); @@ -6185,7 +6205,7 @@ namespace return PUGIXML_TEXT(""); } - const char_t* namespace_uri(const xml_attribute& attr, const xml_node& parent) + PUGI__FN const char_t* namespace_uri(const xml_attribute& attr, const xml_node& parent) { namespace_uri_predicate pred = attr.name(); @@ -6206,12 +6226,12 @@ namespace return PUGIXML_TEXT(""); } - const char_t* namespace_uri(const xpath_node& node) + PUGI__FN const char_t* namespace_uri(const xpath_node& node) { return node.attribute() ? namespace_uri(node.attribute(), node.parent()) : namespace_uri(node.node()); } - void normalize_space(char_t* buffer) + PUGI__FN void normalize_space(char_t* buffer) { char_t* write = buffer; @@ -6219,10 +6239,10 @@ namespace { char_t ch = *it++; - if (IS_CHARTYPE(ch, ct_space)) + if (PUGI__IS_CHARTYPE(ch, ct_space)) { // replace whitespace sequence with single space - while (IS_CHARTYPE(*it, ct_space)) it++; + while (PUGI__IS_CHARTYPE(*it, ct_space)) it++; // avoid leading spaces if (write != buffer) *write++ = ' '; @@ -6231,13 +6251,13 @@ namespace } // remove trailing space - if (write != buffer && IS_CHARTYPE(write[-1], ct_space)) write--; + if (write != buffer && PUGI__IS_CHARTYPE(write[-1], ct_space)) write--; // zero-terminate *write = 0; } - void translate(char_t* buffer, const char_t* from, const char_t* to) + PUGI__FN void translate(char_t* buffer, const char_t* from, const char_t* to) { size_t to_length = strlength(to); @@ -6245,7 +6265,7 @@ namespace while (*buffer) { - DMC_VOLATILE char_t ch = *buffer++; + PUGI__DMC_VOLATILE char_t ch = *buffer++; const char_t* pos = find_char(from, ch); @@ -6287,7 +6307,7 @@ namespace ~xpath_variable_string() { - if (value) global_deallocate(value); + if (value) xml_memory::deallocate(value); } char_t* value; @@ -6300,9 +6320,9 @@ namespace char_t name[1]; }; - const xpath_node_set dummy_node_set; + static const xpath_node_set dummy_node_set; - unsigned int hash_string(const char_t* str) + PUGI__FN unsigned int hash_string(const char_t* str) { // Jenkins one-at-a-time hash (http://en.wikipedia.org/wiki/Jenkins_hash_function#one-at-a-time) unsigned int result = 0; @@ -6321,13 +6341,13 @@ namespace return result; } - template T* new_xpath_variable(const char_t* name) + template PUGI__FN T* new_xpath_variable(const char_t* name) { size_t length = strlength(name); if (length == 0) return 0; // 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 = global_allocate(sizeof(T) + length * sizeof(char_t)); + void* memory = xml_memory::allocate(sizeof(T) + length * sizeof(char_t)); if (!memory) return 0; T* result = new (memory) T(); @@ -6337,7 +6357,7 @@ namespace return result; } - xpath_variable* new_xpath_variable(xpath_value_type type, const char_t* name) + PUGI__FN xpath_variable* new_xpath_variable(xpath_value_type type, const char_t* name) { switch (type) { @@ -6358,13 +6378,13 @@ namespace } } - template void delete_xpath_variable(T* var) + template PUGI__FN void delete_xpath_variable(T* var) { var->~T(); - global_deallocate(var); + xml_memory::deallocate(var); } - void delete_xpath_variable(xpath_value_type type, xpath_variable* var) + PUGI__FN void delete_xpath_variable(xpath_value_type type, xpath_variable* var) { switch (type) { @@ -6389,7 +6409,7 @@ namespace } } - xpath_variable* get_variable(xpath_variable_set* set, const char_t* begin, const char_t* end) + PUGI__FN xpath_variable* get_variable(xpath_variable_set* set, const char_t* begin, const char_t* end) { char_t buffer[32]; @@ -6399,7 +6419,7 @@ namespace if (length >= sizeof(buffer) / sizeof(buffer[0])) { // need to make dummy on-heap copy - scratch = static_cast(global_allocate((length + 1) * sizeof(char_t))); + scratch = static_cast(xml_memory::allocate((length + 1) * sizeof(char_t))); if (!scratch) return 0; } @@ -6410,16 +6430,15 @@ namespace xpath_variable* result = set->get(scratch); // free dummy buffer - if (scratch != buffer) global_deallocate(scratch); + if (scratch != buffer) xml_memory::deallocate(scratch); return result; } -} +PUGI__NS_END // Internal node set class -namespace -{ - xpath_node_set::type_t xpath_sort(xpath_node* begin, xpath_node* end, xpath_node_set::type_t type, bool rev) +PUGI__NS_BEGIN + PUGI__FN xpath_node_set::type_t xpath_sort(xpath_node* begin, xpath_node* end, xpath_node_set::type_t type, bool rev) { xpath_node_set::type_t order = rev ? xpath_node_set::type_sorted_reverse : xpath_node_set::type_sorted; @@ -6435,7 +6454,7 @@ namespace return order; } - xpath_node xpath_first(const xpath_node* begin, const xpath_node* end, xpath_node_set::type_t type) + PUGI__FN xpath_node xpath_first(const xpath_node* begin, const xpath_node* end, xpath_node_set::type_t type) { if (begin == end) return xpath_node(); @@ -6455,6 +6474,7 @@ namespace return xpath_node(); } } + class xpath_node_set_raw { xpath_node_set::type_t _type; @@ -6567,10 +6587,9 @@ namespace _type = value; } }; -} +PUGI__NS_END -namespace -{ +PUGI__NS_BEGIN struct xpath_context { xpath_node n; @@ -6652,7 +6671,7 @@ namespace { const char_t* cur = _cur; - while (IS_CHARTYPE(*cur, ct_space)) ++cur; + while (PUGI__IS_CHARTYPE(*cur, ct_space)) ++cur; // save lexeme position for error reporting _cur_lexeme_pos = cur; @@ -6734,17 +6753,17 @@ namespace case '$': cur += 1; - if (IS_CHARTYPEX(*cur, ctx_start_symbol)) + if (PUGI__IS_CHARTYPEX(*cur, ctx_start_symbol)) { _cur_lexeme_contents.begin = cur; - while (IS_CHARTYPEX(*cur, ctx_symbol)) cur++; + while (PUGI__IS_CHARTYPEX(*cur, ctx_symbol)) cur++; - if (cur[0] == ':' && IS_CHARTYPEX(cur[1], ctx_symbol)) // qname + if (cur[0] == ':' && PUGI__IS_CHARTYPEX(cur[1], ctx_symbol)) // qname { cur++; // : - while (IS_CHARTYPEX(*cur, ctx_symbol)) cur++; + while (PUGI__IS_CHARTYPEX(*cur, ctx_symbol)) cur++; } _cur_lexeme_contents.end = cur; @@ -6807,13 +6826,13 @@ namespace cur += 2; _cur_lexeme = lex_double_dot; } - else if (IS_CHARTYPEX(*(cur+1), ctx_digit)) + else if (PUGI__IS_CHARTYPEX(*(cur+1), ctx_digit)) { _cur_lexeme_contents.begin = cur; // . ++cur; - while (IS_CHARTYPEX(*cur, ctx_digit)) cur++; + while (PUGI__IS_CHARTYPEX(*cur, ctx_digit)) cur++; _cur_lexeme_contents.end = cur; @@ -6867,28 +6886,28 @@ namespace break; default: - if (IS_CHARTYPEX(*cur, ctx_digit)) + if (PUGI__IS_CHARTYPEX(*cur, ctx_digit)) { _cur_lexeme_contents.begin = cur; - while (IS_CHARTYPEX(*cur, ctx_digit)) cur++; + while (PUGI__IS_CHARTYPEX(*cur, ctx_digit)) cur++; if (*cur == '.') { cur++; - while (IS_CHARTYPEX(*cur, ctx_digit)) cur++; + while (PUGI__IS_CHARTYPEX(*cur, ctx_digit)) cur++; } _cur_lexeme_contents.end = cur; _cur_lexeme = lex_number; } - else if (IS_CHARTYPEX(*cur, ctx_start_symbol)) + else if (PUGI__IS_CHARTYPEX(*cur, ctx_start_symbol)) { _cur_lexeme_contents.begin = cur; - while (IS_CHARTYPEX(*cur, ctx_symbol)) cur++; + while (PUGI__IS_CHARTYPEX(*cur, ctx_symbol)) cur++; if (cur[0] == ':') { @@ -6896,11 +6915,11 @@ namespace { cur += 2; // :* } - else if (IS_CHARTYPEX(cur[1], ctx_symbol)) // namespace test qname + else if (PUGI__IS_CHARTYPEX(cur[1], ctx_symbol)) // namespace test qname { cur++; // : - while (IS_CHARTYPEX(*cur, ctx_symbol)) cur++; + while (PUGI__IS_CHARTYPEX(*cur, ctx_symbol)) cur++; } } @@ -9012,7 +9031,7 @@ namespace // This is either a function call, or not - if not, we shall proceed with location path const char_t* state = _lexer.state(); - while (IS_CHARTYPE(*state, ct_space)) ++state; + while (PUGI__IS_CHARTYPE(*state, ct_space)) ++state; if (*state != '(') return parse_location_path(); @@ -9241,7 +9260,7 @@ namespace { static xpath_query_impl* create() { - void* memory = global_allocate(sizeof(xpath_query_impl)); + void* memory = xml_memory::allocate(sizeof(xpath_query_impl)); return new (memory) xpath_query_impl(); } @@ -9254,7 +9273,7 @@ namespace static_cast(ptr)->alloc.release(); // free allocator memory (with the first page) - global_deallocate(ptr); + xml_memory::deallocate(ptr); } xpath_query_impl(): root(0), alloc(&block) @@ -9267,7 +9286,7 @@ namespace xpath_memory_block block; }; - xpath_string evaluate_string_impl(xpath_query_impl* impl, const xpath_node& n, xpath_stack_data& sd) + PUGI__FN xpath_string evaluate_string_impl(xpath_query_impl* impl, const xpath_node& n, xpath_stack_data& sd) { if (!impl) return xpath_string(); @@ -9279,91 +9298,91 @@ namespace return impl->root->eval_string(c, sd.stack); } -} +PUGI__NS_END namespace pugi { #ifndef PUGIXML_NO_EXCEPTIONS - xpath_exception::xpath_exception(const xpath_parse_result& result_): _result(result_) + PUGI__FN xpath_exception::xpath_exception(const xpath_parse_result& result_): _result(result_) { assert(_result.error); } - const char* xpath_exception::what() const throw() + PUGI__FN const char* xpath_exception::what() const throw() { return _result.error; } - const xpath_parse_result& xpath_exception::result() const + PUGI__FN const xpath_parse_result& xpath_exception::result() const { return _result; } #endif - xpath_node::xpath_node() + PUGI__FN xpath_node::xpath_node() { } - xpath_node::xpath_node(const xml_node& node_): _node(node_) + PUGI__FN xpath_node::xpath_node(const xml_node& node_): _node(node_) { } - xpath_node::xpath_node(const xml_attribute& attribute_, const xml_node& parent_): _node(attribute_ ? parent_ : xml_node()), _attribute(attribute_) + PUGI__FN xpath_node::xpath_node(const xml_attribute& attribute_, const xml_node& parent_): _node(attribute_ ? parent_ : xml_node()), _attribute(attribute_) { } - xml_node xpath_node::node() const + PUGI__FN xml_node xpath_node::node() const { return _attribute ? xml_node() : _node; } - xml_attribute xpath_node::attribute() const + PUGI__FN xml_attribute xpath_node::attribute() const { return _attribute; } - xml_node xpath_node::parent() const + PUGI__FN xml_node xpath_node::parent() const { return _attribute ? _node : _node.parent(); } - static void unspecified_bool_xpath_node(xpath_node***) + PUGI__FN static void unspecified_bool_xpath_node(xpath_node***) { } - xpath_node::operator xpath_node::unspecified_bool_type() const + PUGI__FN xpath_node::operator xpath_node::unspecified_bool_type() const { return (_node || _attribute) ? unspecified_bool_xpath_node : 0; } - bool xpath_node::operator!() const + PUGI__FN bool xpath_node::operator!() const { return !(_node || _attribute); } - bool xpath_node::operator==(const xpath_node& n) const + PUGI__FN bool xpath_node::operator==(const xpath_node& n) const { return _node == n._node && _attribute == n._attribute; } - bool xpath_node::operator!=(const xpath_node& n) const + PUGI__FN bool xpath_node::operator!=(const xpath_node& n) const { return _node != n._node || _attribute != n._attribute; } #ifdef __BORLANDC__ - bool operator&&(const xpath_node& lhs, bool rhs) + PUGI__FN bool operator&&(const xpath_node& lhs, bool rhs) { return (bool)lhs && rhs; } - bool operator||(const xpath_node& lhs, bool rhs) + PUGI__FN bool operator||(const xpath_node& lhs, bool rhs) { return (bool)lhs || rhs; } #endif - void xpath_node_set::_assign(const_iterator begin_, const_iterator end_) + PUGI__FN void xpath_node_set::_assign(const_iterator begin_, const_iterator end_) { assert(begin_ <= end_); @@ -9372,7 +9391,7 @@ namespace pugi if (size_ <= 1) { // deallocate old buffer - if (_begin != &_storage) global_deallocate(_begin); + if (_begin != &_storage) impl::xml_memory::deallocate(_begin); // use internal buffer if (begin_ != end_) _storage = *begin_; @@ -9383,7 +9402,7 @@ namespace pugi else { // make heap copy - xpath_node* storage = static_cast(global_allocate(size_ * sizeof(xpath_node))); + xpath_node* storage = static_cast(impl::xml_memory::allocate(size_ * sizeof(xpath_node))); if (!storage) { @@ -9397,7 +9416,7 @@ namespace pugi memcpy(storage, begin_, size_ * sizeof(xpath_node)); // deallocate old buffer - if (_begin != &_storage) global_deallocate(_begin); + if (_begin != &_storage) impl::xml_memory::deallocate(_begin); // finalize _begin = storage; @@ -9405,26 +9424,26 @@ namespace pugi } } - xpath_node_set::xpath_node_set(): _type(type_unsorted), _begin(&_storage), _end(&_storage) + PUGI__FN xpath_node_set::xpath_node_set(): _type(type_unsorted), _begin(&_storage), _end(&_storage) { } - xpath_node_set::xpath_node_set(const_iterator begin_, const_iterator end_, type_t type_): _type(type_), _begin(&_storage), _end(&_storage) + PUGI__FN xpath_node_set::xpath_node_set(const_iterator begin_, const_iterator end_, type_t type_): _type(type_), _begin(&_storage), _end(&_storage) { _assign(begin_, end_); } - xpath_node_set::~xpath_node_set() + PUGI__FN xpath_node_set::~xpath_node_set() { - if (_begin != &_storage) global_deallocate(_begin); + if (_begin != &_storage) impl::xml_memory::deallocate(_begin); } - xpath_node_set::xpath_node_set(const xpath_node_set& ns): _type(ns._type), _begin(&_storage), _end(&_storage) + PUGI__FN xpath_node_set::xpath_node_set(const xpath_node_set& ns): _type(ns._type), _begin(&_storage), _end(&_storage) { _assign(ns._begin, ns._end); } - xpath_node_set& xpath_node_set::operator=(const xpath_node_set& ns) + PUGI__FN xpath_node_set& xpath_node_set::operator=(const xpath_node_set& ns) { if (this == &ns) return *this; @@ -9434,79 +9453,80 @@ namespace pugi return *this; } - xpath_node_set::type_t xpath_node_set::type() const + PUGI__FN xpath_node_set::type_t xpath_node_set::type() const { return _type; } - size_t xpath_node_set::size() const + PUGI__FN size_t xpath_node_set::size() const { return _end - _begin; } - bool xpath_node_set::empty() const + PUGI__FN bool xpath_node_set::empty() const { return _begin == _end; } - const xpath_node& xpath_node_set::operator[](size_t index) const + PUGI__FN const xpath_node& xpath_node_set::operator[](size_t index) const { assert(index < size()); return _begin[index]; } - xpath_node_set::const_iterator xpath_node_set::begin() const + PUGI__FN xpath_node_set::const_iterator xpath_node_set::begin() const { return _begin; } - xpath_node_set::const_iterator xpath_node_set::end() const + PUGI__FN xpath_node_set::const_iterator xpath_node_set::end() const { return _end; } - void xpath_node_set::sort(bool reverse) + PUGI__FN void xpath_node_set::sort(bool reverse) { - _type = xpath_sort(_begin, _end, _type, reverse); + _type = impl::xpath_sort(_begin, _end, _type, reverse); } - xpath_node xpath_node_set::first() const + PUGI__FN xpath_node xpath_node_set::first() const { - return xpath_first(_begin, _end, _type); + return impl::xpath_first(_begin, _end, _type); } - xpath_parse_result::xpath_parse_result(): error("Internal error"), offset(0) + PUGI__FN xpath_parse_result::xpath_parse_result(): error("Internal error"), offset(0) { } - xpath_parse_result::operator bool() const + PUGI__FN xpath_parse_result::operator bool() const { return error == 0; } - const char* xpath_parse_result::description() const + + PUGI__FN const char* xpath_parse_result::description() const { return error ? error : "No error"; } - xpath_variable::xpath_variable() + PUGI__FN xpath_variable::xpath_variable() { } - const char_t* xpath_variable::name() const + PUGI__FN const char_t* xpath_variable::name() const { switch (_type) { case xpath_type_node_set: - return static_cast(this)->name; + return static_cast(this)->name; case xpath_type_number: - return static_cast(this)->name; + return static_cast(this)->name; case xpath_type_string: - return static_cast(this)->name; + return static_cast(this)->name; case xpath_type_boolean: - return static_cast(this)->name; + return static_cast(this)->name; default: assert(!"Invalid variable type"); @@ -9514,83 +9534,83 @@ namespace pugi } } - xpath_value_type xpath_variable::type() const + PUGI__FN xpath_value_type xpath_variable::type() const { return _type; } - bool xpath_variable::get_boolean() const + PUGI__FN bool xpath_variable::get_boolean() const { - return (_type == xpath_type_boolean) ? static_cast(this)->value : false; + return (_type == xpath_type_boolean) ? static_cast(this)->value : false; } - double xpath_variable::get_number() const + PUGI__FN double xpath_variable::get_number() const { - return (_type == xpath_type_number) ? static_cast(this)->value : gen_nan(); + return (_type == xpath_type_number) ? static_cast(this)->value : impl::gen_nan(); } - const char_t* xpath_variable::get_string() const + PUGI__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 : 0; return value ? value : PUGIXML_TEXT(""); } - const xpath_node_set& xpath_variable::get_node_set() const + PUGI__FN const xpath_node_set& xpath_variable::get_node_set() const { - return (_type == xpath_type_node_set) ? static_cast(this)->value : dummy_node_set; + return (_type == xpath_type_node_set) ? static_cast(this)->value : impl::dummy_node_set; } - bool xpath_variable::set(bool value) + PUGI__FN bool xpath_variable::set(bool value) { if (_type != xpath_type_boolean) return false; - static_cast(this)->value = value; + static_cast(this)->value = value; return true; } - bool xpath_variable::set(double value) + PUGI__FN bool xpath_variable::set(double value) { if (_type != xpath_type_number) return false; - static_cast(this)->value = value; + static_cast(this)->value = value; return true; } - bool xpath_variable::set(const char_t* value) + PUGI__FN bool xpath_variable::set(const char_t* value) { if (_type != xpath_type_string) return false; - xpath_variable_string* var = static_cast(this); + impl::xpath_variable_string* var = static_cast(this); // duplicate string - size_t size = (strlength(value) + 1) * sizeof(char_t); + size_t size = (impl::strlength(value) + 1) * sizeof(char_t); - char_t* copy = static_cast(global_allocate(size)); + char_t* copy = static_cast(impl::xml_memory::allocate(size)); if (!copy) return false; memcpy(copy, value, size); // replace old string - if (var->value) global_deallocate(var->value); + if (var->value) impl::xml_memory::deallocate(var->value); var->value = copy; return true; } - bool xpath_variable::set(const xpath_node_set& value) + PUGI__FN bool xpath_variable::set(const xpath_node_set& value) { if (_type != xpath_type_node_set) return false; - static_cast(this)->value = value; + static_cast(this)->value = value; return true; } - xpath_variable_set::xpath_variable_set() + PUGI__FN xpath_variable_set::xpath_variable_set() { for (size_t i = 0; i < sizeof(_data) / sizeof(_data[0]); ++i) _data[i] = 0; } - xpath_variable_set::~xpath_variable_set() + PUGI__FN xpath_variable_set::~xpath_variable_set() { for (size_t i = 0; i < sizeof(_data) / sizeof(_data[0]); ++i) { @@ -9600,38 +9620,38 @@ namespace pugi { xpath_variable* next = var->_next; - delete_xpath_variable(var->_type, var); + impl::delete_xpath_variable(var->_type, var); var = next; } } } - xpath_variable* xpath_variable_set::find(const char_t* name) const + PUGI__FN xpath_variable* xpath_variable_set::find(const char_t* name) const { const size_t hash_size = sizeof(_data) / sizeof(_data[0]); - size_t hash = hash_string(name) % hash_size; + size_t hash = impl::hash_string(name) % hash_size; // look for existing variable for (xpath_variable* var = _data[hash]; var; var = var->_next) - if (strequal(var->name(), name)) + if (impl::strequal(var->name(), name)) return var; return 0; } - xpath_variable* xpath_variable_set::add(const char_t* name, xpath_value_type type) + PUGI__FN xpath_variable* xpath_variable_set::add(const char_t* name, xpath_value_type type) { const size_t hash_size = sizeof(_data) / sizeof(_data[0]); - size_t hash = hash_string(name) % hash_size; + size_t hash = impl::hash_string(name) % hash_size; // look for existing variable for (xpath_variable* var = _data[hash]; var; var = var->_next) - if (strequal(var->name(), name)) + if (impl::strequal(var->name(), name)) return var->type() == type ? var : 0; // add new variable - xpath_variable* result = new_xpath_variable(type, name); + xpath_variable* result = impl::new_xpath_variable(type, name); if (result) { @@ -9644,45 +9664,45 @@ namespace pugi return result; } - bool xpath_variable_set::set(const char_t* name, bool value) + PUGI__FN bool xpath_variable_set::set(const char_t* name, bool value) { xpath_variable* var = add(name, xpath_type_boolean); return var ? var->set(value) : false; } - bool xpath_variable_set::set(const char_t* name, double value) + PUGI__FN bool xpath_variable_set::set(const char_t* name, double value) { xpath_variable* var = add(name, xpath_type_number); return var ? var->set(value) : false; } - bool xpath_variable_set::set(const char_t* name, const char_t* value) + PUGI__FN bool xpath_variable_set::set(const char_t* name, const char_t* value) { xpath_variable* var = add(name, xpath_type_string); return var ? var->set(value) : false; } - bool xpath_variable_set::set(const char_t* name, const xpath_node_set& value) + PUGI__FN bool xpath_variable_set::set(const char_t* name, const xpath_node_set& value) { xpath_variable* var = add(name, xpath_type_node_set); return var ? var->set(value) : false; } - xpath_variable* xpath_variable_set::get(const char_t* name) + PUGI__FN xpath_variable* xpath_variable_set::get(const char_t* name) { return find(name); } - const xpath_variable* xpath_variable_set::get(const char_t* name) const + PUGI__FN const xpath_variable* xpath_variable_set::get(const char_t* name) const { return find(name); } - xpath_query::xpath_query(const char_t* query, xpath_variable_set* variables): _impl(0) + PUGI__FN xpath_query::xpath_query(const char_t* query, xpath_variable_set* variables): _impl(0) { - xpath_query_impl* impl = xpath_query_impl::create(); + impl::xpath_query_impl* qimpl = impl::xpath_query_impl::create(); - if (!impl) + if (!qimpl) { #ifdef PUGIXML_NO_EXCEPTIONS _result.error = "Out of memory"; @@ -9692,72 +9712,72 @@ namespace pugi } else { - buffer_holder impl_holder(impl, xpath_query_impl::destroy); + impl::buffer_holder impl_holder(qimpl, impl::xpath_query_impl::destroy); - impl->root = xpath_parser::parse(query, variables, &impl->alloc, &_result); + qimpl->root = impl::xpath_parser::parse(query, variables, &qimpl->alloc, &_result); - if (impl->root) + if (qimpl->root) { - _impl = static_cast(impl_holder.release()); + _impl = static_cast(impl_holder.release()); _result.error = 0; } } } - xpath_query::~xpath_query() + PUGI__FN xpath_query::~xpath_query() { - xpath_query_impl::destroy(_impl); + impl::xpath_query_impl::destroy(_impl); } - xpath_value_type xpath_query::return_type() const + PUGI__FN xpath_value_type xpath_query::return_type() const { if (!_impl) return xpath_type_none; - return static_cast(_impl)->root->rettype(); + return static_cast(_impl)->root->rettype(); } - bool xpath_query::evaluate_boolean(const xpath_node& n) const + PUGI__FN bool xpath_query::evaluate_boolean(const xpath_node& n) const { if (!_impl) return false; - xpath_context c(n, 1, 1); - xpath_stack_data sd; + impl::xpath_context c(n, 1, 1); + impl::xpath_stack_data sd; #ifdef PUGIXML_NO_EXCEPTIONS if (setjmp(sd.error_handler)) return false; #endif - return static_cast(_impl)->root->eval_boolean(c, sd.stack); + return static_cast(_impl)->root->eval_boolean(c, sd.stack); } - double xpath_query::evaluate_number(const xpath_node& n) const + PUGI__FN double xpath_query::evaluate_number(const xpath_node& n) const { - if (!_impl) return gen_nan(); + if (!_impl) return impl::gen_nan(); - xpath_context c(n, 1, 1); - xpath_stack_data sd; + impl::xpath_context c(n, 1, 1); + impl::xpath_stack_data sd; #ifdef PUGIXML_NO_EXCEPTIONS - if (setjmp(sd.error_handler)) return gen_nan(); + if (setjmp(sd.error_handler)) return impl::gen_nan(); #endif - return static_cast(_impl)->root->eval_number(c, sd.stack); + return static_cast(_impl)->root->eval_number(c, sd.stack); } #ifndef PUGIXML_NO_STL - string_t xpath_query::evaluate_string(const xpath_node& n) const + PUGI__FN string_t xpath_query::evaluate_string(const xpath_node& n) const { - xpath_stack_data sd; + impl::xpath_stack_data sd; - return evaluate_string_impl(static_cast(_impl), n, sd).c_str(); + return impl::evaluate_string_impl(static_cast(_impl), n, sd).c_str(); } #endif - size_t xpath_query::evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const + PUGI__FN size_t xpath_query::evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const { - xpath_stack_data sd; + impl::xpath_stack_data sd; - xpath_string r = evaluate_string_impl(static_cast(_impl), n, sd); + impl::xpath_string r = impl::evaluate_string_impl(static_cast(_impl), n, sd); size_t full_size = r.length() + 1; @@ -9773,11 +9793,11 @@ namespace pugi return full_size; } - xpath_node_set xpath_query::evaluate_node_set(const xpath_node& n) const + PUGI__FN xpath_node_set xpath_query::evaluate_node_set(const xpath_node& n) const { if (!_impl) return xpath_node_set(); - xpath_ast_node* root = static_cast(_impl)->root; + impl::xpath_ast_node* root = static_cast(_impl)->root; if (root->rettype() != xpath_type_node_set) { @@ -9791,56 +9811,56 @@ namespace pugi #endif } - xpath_context c(n, 1, 1); - xpath_stack_data sd; + impl::xpath_context c(n, 1, 1); + impl::xpath_stack_data sd; #ifdef PUGIXML_NO_EXCEPTIONS if (setjmp(sd.error_handler)) return xpath_node_set(); #endif - xpath_node_set_raw r = root->eval_node_set(c, sd.stack); + impl::xpath_node_set_raw r = root->eval_node_set(c, sd.stack); return xpath_node_set(r.begin(), r.end(), r.type()); } - const xpath_parse_result& xpath_query::result() const + PUGI__FN const xpath_parse_result& xpath_query::result() const { return _result; } - static void unspecified_bool_xpath_query(xpath_query***) + PUGI__FN static void unspecified_bool_xpath_query(xpath_query***) { } - xpath_query::operator xpath_query::unspecified_bool_type() const + PUGI__FN xpath_query::operator xpath_query::unspecified_bool_type() const { return _impl ? unspecified_bool_xpath_query : 0; } - bool xpath_query::operator!() const + PUGI__FN bool xpath_query::operator!() const { return !_impl; } - xpath_node xml_node::select_single_node(const char_t* query, xpath_variable_set* variables) const + PUGI__FN xpath_node xml_node::select_single_node(const char_t* query, xpath_variable_set* variables) const { xpath_query q(query, variables); return select_single_node(q); } - xpath_node xml_node::select_single_node(const xpath_query& query) const + PUGI__FN xpath_node xml_node::select_single_node(const xpath_query& query) const { xpath_node_set s = query.evaluate_node_set(*this); return s.empty() ? xpath_node() : s.first(); } - xpath_node_set xml_node::select_nodes(const char_t* query, xpath_variable_set* variables) const + PUGI__FN xpath_node_set xml_node::select_nodes(const char_t* query, xpath_variable_set* variables) const { xpath_query q(query, variables); return select_nodes(q); } - xpath_node_set xml_node::select_nodes(const xpath_query& query) const + PUGI__FN xpath_node_set xml_node::select_nodes(const xpath_query& query) const { return query.evaluate_node_set(*this); } @@ -9848,6 +9868,51 @@ namespace pugi #endif +// SNC seems to have the same bug as Intel (below); I need to test more versions to do a proper check here +// #ifdef __SNC__ +// # pragma diag_pop +// #endif + +#ifdef __BORLANDC__ +# pragma option pop +#endif + +// Some Intel C++ versions (9, 10) do 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(__INTEL_COMPILER) || __INTEL_COMPILER >= 1100 +# ifdef __INTEL_COMPILER +# pragma warning(pop) +# endif + +# ifdef _MSC_VER +# pragma warning(pop) +# endif +#endif + +// Undefine all local macros (makes sure we're not leaking macros in header-only mode) +#undef PUGI__NO_INLINE +#undef PUGI__STATIC_ASSERT +#undef PUGI__DMC_VOLATILE +#undef PUGI__MSVC_CRT_VERSION +#undef PUGI__NS_BEGIN +#undef PUGI__NS_END +#undef PUGI__FN +#undef PUGI__FN_NO_INLINE +#undef PUGI__IS_CHARTYPE_IMPL +#undef PUGI__IS_CHARTYPE +#undef PUGI__IS_CHARTYPEX +#undef PUGI__SKIPWS +#undef PUGI__OPTSET +#undef PUGI__PUSHNODE +#undef PUGI__POPNODE +#undef PUGI__SCANFOR +#undef PUGI__SCANWHILE +#undef PUGI__ENDSEG +#undef PUGI__THROW_ERROR +#undef PUGI__CHECK_ERROR + +#endif + /** * Copyright (c) 2006-2010 Arseny Kapoulkine * diff --git a/src/pugixml.hpp b/src/pugixml.hpp index d0a8623..b01da4f 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -11,15 +11,17 @@ * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) */ -#ifndef HEADER_PUGIXML_HPP -#define HEADER_PUGIXML_HPP - +#ifndef PUGIXML_VERSION // Define version macro; evaluates to major * 100 + minor so that it's safe to use in less-than comparisons -#define PUGIXML_VERSION 100 +# define PUGIXML_VERSION 100 +#endif // Include user configuration file (this can define various configuration macros) #include "pugiconfig.hpp" +#ifndef HEADER_PUGIXML_HPP +#define HEADER_PUGIXML_HPP + // Include stddef.h for size_t and ptrdiff_t #include -- cgit v1.2.3