15 #ifndef SOURCE_PUGIXML_CPP
16 #define SOURCE_PUGIXML_CPP
26 #ifdef PUGIXML_WCHAR_MODE
30 #ifndef PUGIXML_NO_XPATH
33 # ifdef PUGIXML_NO_EXCEPTIONS
38 #ifndef PUGIXML_NO_STL
48 # pragma warning(push)
49 # pragma warning(disable: 4127) // conditional expression is constant
50 # pragma warning(disable: 4324) // structure was padded due to __declspec(align())
51 # pragma warning(disable: 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
52 # pragma warning(disable: 4702) // unreachable code
53 # pragma warning(disable: 4996) // this function or variable may be unsafe
54 # pragma warning(disable: 4793) // function compiled as native: presence of '_setjmp' makes a function unmanaged
57 #ifdef __INTEL_COMPILER
58 # pragma warning(disable: 177) // function was declared but never referenced
59 # pragma warning(disable: 279) // controlling expression is constant
60 # pragma warning(disable: 1478 1786) // function was declared "deprecated"
61 # pragma warning(disable: 1684) // conversion from pointer to same-sized integral type
64 #if defined(__BORLANDC__) && defined(PUGIXML_HEADER_ONLY)
65 # pragma warn -8080 // symbol is declared but never used; disabling this inside push/pop bracket does not make the warning go away
70 # pragma warn -8008 // condition is always false
71 # pragma warn -8066 // unreachable code
76 # pragma diag_suppress=178 // function was declared but never referenced
77 # pragma diag_suppress=237 // controlling expression is constant
81 #if defined(_MSC_VER) && _MSC_VER >= 1300
82 # define PUGI__NO_INLINE __declspec(noinline)
83 #elif defined(__GNUC__)
84 # define PUGI__NO_INLINE __attribute__((noinline))
86 # define PUGI__NO_INLINE
91 # define PUGI__UNLIKELY(cond) __builtin_expect(cond, 0)
93 # define PUGI__UNLIKELY(cond) (cond)
97 #define PUGI__STATIC_ASSERT(cond) { static const char condition_failed[(cond) ? 1 : -1] = {0}; (void)condition_failed[0]; }
101 # define PUGI__DMC_VOLATILE volatile
103 # define PUGI__DMC_VOLATILE
107 #if defined(__BORLANDC__) && !defined(__MEM_H_USING_LIST)
114 #if defined(PUGIXML_HAS_LONG_LONG) && defined(__MINGW32__) && defined(__STRICT_ANSI__) && !defined(LLONG_MAX) && !defined(LLONG_MIN) && !defined(ULLONG_MAX)
115 # define LLONG_MAX 9223372036854775807LL
116 # define LLONG_MIN (-LLONG_MAX-1)
117 # define ULLONG_MAX (2ULL*LLONG_MAX+1)
121 #if defined(_MSC_VER) && !defined(__S3E__)
122 # define PUGI__MSVC_CRT_VERSION _MSC_VER
125 #ifdef PUGIXML_HEADER_ONLY
126 # define PUGI__NS_BEGIN OIIO_NAMESPACE_BEGIN namespace pugi { namespace impl {
127 # define PUGI__NS_END } } OIIO_NAMESPACE_END
128 # define PUGI__FN inline
129 # define PUGI__FN_NO_INLINE inline
131 # if defined(_MSC_VER) && _MSC_VER < 1300 // MSVC6 seems to have an amusing bug with anonymous namespaces inside namespaces
132 # define PUGI__NS_BEGIN OIIO_NAMESPACE_BEGIN namespace pugi { namespace impl {
133 # define PUGI__NS_END } } OIIO_NAMESPACE_END
135 # define PUGI__NS_BEGIN OIIO_NAMESPACE_BEGIN namespace pugi { namespace impl { namespace {
136 # define PUGI__NS_END } } } OIIO_NAMESPACE_END
139 # define PUGI__FN_NO_INLINE PUGI__NO_INLINE
143 #if (defined(_MSC_VER) && _MSC_VER < 1600) || (defined(__BORLANDC__) && __BORLANDC__ < 0x561)
146 # ifndef _UINTPTR_T_DEFINED
150 typedef unsigned __int8 uint8_t;
151 typedef unsigned __int16 uint16_t;
152 typedef unsigned __int32 uint32_t;
170 template <
typename T>
192 #ifdef PUGIXML_WCHAR_MODE
204 #ifdef PUGIXML_WCHAR_MODE
205 return wcscmp(src, dst) == 0;
207 return strcmp(src, dst) == 0;
214 for (
size_t i = 0; i <
count; ++i)
215 if (lhs[i] != rhs[i])
218 return lhs[
count] == 0;
226 #ifdef PUGIXML_WCHAR_MODE
229 const wchar_t*
end =
s;
231 return static_cast<size_t>(end -
s);
263 #ifdef PUGIXML_COMPACT
265 class compact_hash_table
268 compact_hash_table(): _items(0), _capacity(0), _count(0)
283 void**
find(
const void* key)
287 if (_capacity == 0)
return 0;
289 size_t hashmod = _capacity - 1;
290 size_t bucket = hash(key) & hashmod;
292 for (
size_t probe = 0; probe <= hashmod; ++probe)
294 item_t& probe_item = _items[bucket];
296 if (probe_item.key == key)
297 return &probe_item.value;
299 if (probe_item.key == 0)
303 bucket = (bucket + probe + 1) & hashmod;
306 assert(
false &&
"Hash table is full");
310 void**
insert(
const void* key)
313 assert(_capacity != 0 && _count < _capacity - _capacity / 4);
315 size_t hashmod = _capacity - 1;
316 size_t bucket = hash(key) & hashmod;
318 for (
size_t probe = 0; probe <= hashmod; ++probe)
320 item_t& probe_item = _items[bucket];
322 if (probe_item.key == 0)
324 probe_item.key = key;
326 return &probe_item.value;
329 if (probe_item.key == key)
330 return &probe_item.value;
333 bucket = (bucket + probe + 1) & hashmod;
336 assert(
false &&
"Hash table is full");
342 if (_count + 16 >= _capacity - _capacity / 4)
362 static unsigned int hash(
const void* key)
364 unsigned int h =
static_cast<unsigned int>(
reinterpret_cast<uintptr_t>(key));
379 compact_hash_table rt;
380 rt._capacity = (_capacity == 0) ? 32 : _capacity * 2;
386 memset(rt._items, 0,
sizeof(item_t) * rt._capacity);
388 for (
size_t i = 0; i < _capacity; ++i)
390 *rt.insert(_items[i].key) = _items[i].value;
395 _capacity = rt._capacity;
398 assert(_count == rt._count);
407 #ifdef PUGIXML_COMPACT
408 static const uintptr_t xml_memory_block_alignment = 4;
410 static const uintptr_t xml_memory_block_alignment =
sizeof(
void*);
414 static const uintptr_t xml_memory_page_contents_shared_mask = 64;
415 static const uintptr_t xml_memory_page_name_allocated_mask = 32;
416 static const uintptr_t xml_memory_page_value_allocated_mask = 16;
417 static const uintptr_t xml_memory_page_type_mask = 15;
420 static const uintptr_t xml_memory_page_name_allocated_or_shared_mask = xml_memory_page_name_allocated_mask | xml_memory_page_contents_shared_mask;
421 static const uintptr_t xml_memory_page_value_allocated_or_shared_mask = xml_memory_page_value_allocated_mask | xml_memory_page_contents_shared_mask;
423 #ifdef PUGIXML_COMPACT
424 #define PUGI__GETHEADER_IMPL(object, page, flags) // unused
425 #define PUGI__GETPAGE_IMPL(header) (header).get_page()
427 #define PUGI__GETHEADER_IMPL(object, page, flags) (((reinterpret_cast<char*>(object) - reinterpret_cast<char*>(page)) << 8) | (flags))
429 #define PUGI__GETPAGE_IMPL(header) static_cast<impl::xml_memory_page*>(const_cast<void*>(static_cast<const void*>(reinterpret_cast<const char*>(&header) - (header >> 8))))
432 #define PUGI__GETPAGE(n) PUGI__GETPAGE_IMPL((n)->header)
433 #define PUGI__NODETYPE(n) static_cast<xml_node_type>((n)->header & impl::xml_memory_page_type_mask)
449 #ifdef PUGIXML_COMPACT
450 result->compact_string_base = 0;
451 result->compact_shared_parent = 0;
452 result->compact_page_marker = 0;
466 #ifdef PUGIXML_COMPACT
467 char_t* compact_string_base;
468 void* compact_shared_parent;
469 uint32_t* compact_page_marker;
473 static const size_t xml_memory_page_size =
474 #ifdef PUGIXML_MEMORY_PAGE_SIZE
475 (PUGIXML_MEMORY_PAGE_SIZE)
491 #ifdef PUGIXML_COMPACT
502 if (!memory)
return 0;
534 #ifdef PUGIXML_COMPACT
538 if (!result)
return 0;
541 ptrdiff_t
offset =
static_cast<char*
>(
result) - reinterpret_cast<char*>(out_page->compact_page_marker);
543 if (
PUGI__UNLIKELY(static_cast<uintptr_t>(offset) >= 256 * xml_memory_block_alignment))
546 uint32_t* marker =
static_cast<uint32_t*
>(
result);
548 *marker =
static_cast<uint32_t
>(
reinterpret_cast<char*
>(marker) - reinterpret_cast<char*>(out_page));
549 out_page->compact_page_marker = marker;
586 assert(
_root == page);
592 #ifdef PUGIXML_COMPACT
594 page->compact_string_base = 0;
595 page->compact_shared_parent = 0;
596 page->compact_page_marker = 0;
603 assert(
_root != page);
618 static const size_t max_encoded_offset = (1 << 16) * xml_memory_block_alignment;
626 size_t full_size = (size + (xml_memory_block_alignment - 1)) & ~(xml_memory_block_alignment - 1);
631 if (!header)
return 0;
634 ptrdiff_t page_offset =
reinterpret_cast<char*
>(header) - reinterpret_cast<char*>(page) -
sizeof(
xml_memory_page);
636 assert(page_offset % xml_memory_block_alignment == 0);
637 assert(page_offset >= 0 && static_cast<size_t>(page_offset) < max_encoded_offset);
638 header->
page_offset =
static_cast<uint16_t
>(
static_cast<size_t>(page_offset) / xml_memory_block_alignment);
641 assert(full_size % xml_memory_block_alignment == 0);
642 assert(full_size < max_encoded_offset || (page->
busy_size == full_size && page_offset == 0));
643 header->
full_size =
static_cast<uint16_t
>(full_size < max_encoded_offset ? full_size / xml_memory_block_alignment : 0);
647 return static_cast<char_t*
>(
static_cast<void*
>(header + 1));
661 xml_memory_page* page = reinterpret_cast<xml_memory_page*>(static_cast<void*>(reinterpret_cast<char*>(header) - page_offset));
664 size_t full_size = header->
full_size == 0 ? page->busy_size : header->
full_size * xml_memory_block_alignment;
671 #ifdef PUGIXML_COMPACT
672 return _hash->reserve();
681 #ifdef PUGIXML_COMPACT
682 compact_hash_table* _hash;
688 const size_t large_allocation_threshold = xml_memory_page_size / 4;
695 if (size <= large_allocation_threshold)
725 #ifdef PUGIXML_COMPACT
727 static const uintptr_t compact_alignment_log2 = 2;
728 static const uintptr_t compact_alignment = 1 << compact_alignment_log2;
737 ptrdiff_t offset = (
reinterpret_cast<char*
>(
this) - reinterpret_cast<char*>(page->compact_page_marker));
738 assert(offset % compact_alignment == 0 && static_cast<uintptr_t>(offset) < 256 * compact_alignment);
740 _page =
static_cast<unsigned char>(offset >> compact_alignment_log2);
741 _flags =
static_cast<unsigned char>(
flags);
746 _flags &=
static_cast<unsigned char>(mod);
751 _flags |=
static_cast<unsigned char>(mod);
762 const char* page_marker =
reinterpret_cast<const char*
>(
this) - (_page << compact_alignment_log2);
763 const char* page = page_marker - *
reinterpret_cast<const uint32_t*
>(
static_cast<const void*
>(page_marker));
770 unsigned char _flags;
775 const compact_header* header =
reinterpret_cast<const compact_header*
>(
static_cast<const char*
>(
object) - header_offset);
777 return header->get_page();
780 template <
int header_offset,
typename T>
PUGI__FN_NO_INLINE T* compact_get_value(
const void*
object)
782 return static_cast<T*
>(*compact_get_page(
object, header_offset)->allocator->_hash->find(
object));
785 template <
int header_offset,
typename T>
PUGI__FN_NO_INLINE void compact_set_value(
const void*
object, T*
value)
787 *compact_get_page(
object, header_offset)->allocator->_hash->insert(
object) =
value;
790 template <
typename T,
int header_offset,
int start = -126>
class compact_pointer
793 compact_pointer(): _data(0)
797 void operator=(
const compact_pointer& rhs)
810 ptrdiff_t diff =
reinterpret_cast<char*
>(
value) - reinterpret_cast<char*>(
this);
811 ptrdiff_t offset = ((diff +
int(compact_alignment - 1)) >> compact_alignment_log2) -
start;
813 if (static_cast<uintptr_t>(offset) <= 253)
814 _data = static_cast<unsigned char>(offset + 1);
817 compact_set_value<header_offset>(
this,
value);
834 return reinterpret_cast<T*
>(base + ((_data - 1 +
start) << compact_alignment_log2));
837 return compact_get_value<header_offset, T>(
this);
843 T* operator->()
const
852 template <
typename T,
int header_offset>
class compact_pointer_parent
855 compact_pointer_parent(): _data(0)
859 void operator=(
const compact_pointer_parent& rhs)
872 ptrdiff_t diff =
reinterpret_cast<char*
>(
value) - reinterpret_cast<char*>(
this);
873 ptrdiff_t offset = ((diff +
int(compact_alignment - 1)) >> compact_alignment_log2) + 65533;
875 if (static_cast<uintptr_t>(offset) <= 65533)
877 _data =
static_cast<unsigned short>(offset + 1);
884 page->compact_shared_parent =
value;
886 if (page->compact_shared_parent == value)
892 compact_set_value<header_offset>(
this,
value);
912 return reinterpret_cast<T*
>(base + ((_data - 1 - 65533) << compact_alignment_log2));
914 else if (_data == 65534)
915 return static_cast<T*
>(compact_get_page(
this, header_offset)->compact_shared_parent);
917 return compact_get_value<header_offset, T>(
this);
923 T* operator->()
const
932 template <
int header_offset,
int base_offset>
class compact_string
935 compact_string(): _data(0)
939 void operator=(
const compact_string& rhs)
951 page->compact_string_base =
value;
953 ptrdiff_t offset = value - page->compact_string_base;
955 if (static_cast<uintptr_t>(offset) < (65535 << 7))
958 uint16_t* base =
reinterpret_cast<uint16_t*
>(
static_cast<void*
>(
reinterpret_cast<char*
>(
this) - base_offset));
962 *base =
static_cast<uint16_t
>((offset >> 7) + 1);
963 _data =
static_cast<unsigned char>((offset & 127) + 1);
967 ptrdiff_t remainder = offset - ((*base - 1) << 7);
969 if (static_cast<uintptr_t>(remainder) <= 253)
971 _data =
static_cast<unsigned char>(remainder + 1);
975 compact_set_value<header_offset>(
this,
value);
983 compact_set_value<header_offset>(
this,
value);
1003 const uint16_t* base =
reinterpret_cast<const uint16_t*
>(
static_cast<const void*
>(
reinterpret_cast<const char*
>(
this) - base_offset));
1006 ptrdiff_t offset = ((*base - 1) << 7) + (_data - 1);
1008 return page->compact_string_base +
offset;
1012 return compact_get_value<header_offset, char_t>(
this);
1020 unsigned char _data;
1025 #ifdef PUGIXML_COMPACT
1028 struct xml_attribute_struct
1035 impl::compact_header
header;
1037 uint16_t namevalue_base;
1039 impl::compact_string<4, 2>
name;
1040 impl::compact_string<5, 3>
value;
1043 impl::compact_pointer<xml_attribute_struct, 7, 0>
next_attribute;
1046 struct xml_node_struct
1053 impl::compact_header
header;
1055 uint16_t namevalue_base;
1057 impl::compact_string<4, 2>
name;
1058 impl::compact_string<5, 3>
value;
1060 impl::compact_pointer_parent<xml_node_struct, 6>
parent;
1062 impl::compact_pointer<xml_node_struct, 8, 0>
first_child;
1065 impl::compact_pointer<xml_node_struct, 10, 0>
next_sibling;
1130 #ifdef PUGIXML_COMPACT
1131 compact_hash_table hash;
1156 if (!memory)
return 0;
1158 return new (
memory) xml_attribute_struct(page);
1165 if (!memory)
return 0;
1167 return new (
memory) xml_node_struct(page, type);
1172 if (a->header & impl::xml_memory_page_name_allocated_mask)
1175 if (a->header & impl::xml_memory_page_value_allocated_mask)
1183 if (n->header & impl::xml_memory_page_name_allocated_mask)
1186 if (n->header & impl::xml_memory_page_value_allocated_mask)
1189 for (xml_attribute_struct* attr = n->first_attribute; attr; )
1191 xml_attribute_struct* next = attr->next_attribute;
1198 for (xml_node_struct* child = n->first_child; child; )
1200 xml_node_struct* next = child->next_sibling;
1210 inline void append_node(xml_node_struct* child, xml_node_struct* node)
1212 child->parent = node;
1214 xml_node_struct*
head = node->first_child;
1218 xml_node_struct* tail = head->prev_sibling_c;
1220 tail->next_sibling = child;
1221 child->prev_sibling_c = tail;
1222 head->prev_sibling_c = child;
1226 node->first_child = child;
1227 child->prev_sibling_c = child;
1233 child->parent = node;
1235 xml_node_struct*
head = node->first_child;
1239 child->prev_sibling_c = head->prev_sibling_c;
1240 head->prev_sibling_c = child;
1243 child->prev_sibling_c = child;
1245 child->next_sibling =
head;
1246 node->first_child = child;
1251 xml_node_struct* parent = node->parent;
1253 child->parent = parent;
1255 if (node->next_sibling)
1256 node->next_sibling->prev_sibling_c = child;
1258 parent->first_child->prev_sibling_c = child;
1260 child->next_sibling = node->next_sibling;
1261 child->prev_sibling_c = node;
1263 node->next_sibling = child;
1268 xml_node_struct* parent = node->parent;
1270 child->parent = parent;
1272 if (node->prev_sibling_c->next_sibling)
1273 node->prev_sibling_c->next_sibling = child;
1275 parent->first_child = child;
1277 child->prev_sibling_c = node->prev_sibling_c;
1278 child->next_sibling = node;
1280 node->prev_sibling_c = child;
1285 xml_node_struct* parent = node->parent;
1287 if (node->next_sibling)
1288 node->next_sibling->prev_sibling_c = node->prev_sibling_c;
1290 parent->first_child->prev_sibling_c = node->prev_sibling_c;
1292 if (node->prev_sibling_c->next_sibling)
1293 node->prev_sibling_c->next_sibling = node->next_sibling;
1295 parent->first_child = node->next_sibling;
1298 node->prev_sibling_c = 0;
1299 node->next_sibling = 0;
1304 xml_attribute_struct*
head = node->first_attribute;
1308 xml_attribute_struct* tail = head->prev_attribute_c;
1310 tail->next_attribute = attr;
1311 attr->prev_attribute_c = tail;
1312 head->prev_attribute_c = attr;
1316 node->first_attribute = attr;
1317 attr->prev_attribute_c = attr;
1323 xml_attribute_struct*
head = node->first_attribute;
1327 attr->prev_attribute_c = head->prev_attribute_c;
1328 head->prev_attribute_c = attr;
1331 attr->prev_attribute_c = attr;
1333 attr->next_attribute =
head;
1334 node->first_attribute = attr;
1339 if (place->next_attribute)
1340 place->next_attribute->prev_attribute_c = attr;
1342 node->first_attribute->prev_attribute_c = attr;
1344 attr->next_attribute = place->next_attribute;
1345 attr->prev_attribute_c = place;
1346 place->next_attribute = attr;
1351 if (place->prev_attribute_c->next_attribute)
1352 place->prev_attribute_c->next_attribute = attr;
1354 node->first_attribute = attr;
1356 attr->prev_attribute_c = place->prev_attribute_c;
1357 attr->next_attribute = place;
1358 place->prev_attribute_c = attr;
1363 if (attr->next_attribute)
1364 attr->next_attribute->prev_attribute_c = attr->prev_attribute_c;
1366 node->first_attribute->prev_attribute_c = attr->prev_attribute_c;
1368 if (attr->prev_attribute_c->next_attribute)
1369 attr->prev_attribute_c->next_attribute = attr->next_attribute;
1371 node->first_attribute = attr->next_attribute;
1373 attr->prev_attribute_c = 0;
1374 attr->next_attribute = 0;
1379 if (!alloc.
reserve())
return 0;
1382 if (!child)
return 0;
1391 if (!alloc.
reserve())
return 0;
1394 if (!attr)
return 0;
1419 return static_cast<uint16_t
>(((value & 0xff) << 8) | (value >> 8));
1424 return ((value & 0xff) << 24) | ((value & 0xff00) << 8) | ((value & 0xff0000) >> 8) | (value >> 24);
1434 if (ch < 0x80)
return result + 1;
1436 else if (ch < 0x800)
return result + 2;
1438 else return result + 3;
1457 *result =
static_cast<uint8_t
>(ch);
1461 else if (ch < 0x800)
1463 result[0] =
static_cast<uint8_t
>(0xC0 | (ch >> 6));
1464 result[1] =
static_cast<uint8_t
>(0x80 | (ch & 0x3F));
1470 result[0] =
static_cast<uint8_t
>(0xE0 | (ch >> 12));
1471 result[1] =
static_cast<uint8_t
>(0x80 | ((ch >> 6) & 0x3F));
1472 result[2] =
static_cast<uint8_t
>(0x80 | (ch & 0x3F));
1480 result[0] =
static_cast<uint8_t
>(0xF0 | (ch >> 18));
1481 result[1] =
static_cast<uint8_t
>(0x80 | ((ch >> 12) & 0x3F));
1482 result[2] =
static_cast<uint8_t
>(0x80 | ((ch >> 6) & 0x3F));
1483 result[3] =
static_cast<uint8_t
>(0x80 | (ch & 0x3F));
1489 return (ch < 0x10000) ?
low(result, ch) :
high(result, ch);
1514 *result =
static_cast<uint16_t
>(ch);
1521 uint32_t msh =
static_cast<uint32_t
>(ch - 0x10000) >> 10;
1522 uint32_t lsh =
static_cast<uint32_t
>(ch - 0x10000) & 0x3ff;
1524 result[0] =
static_cast<uint16_t
>(0xD800 + msh);
1525 result[1] =
static_cast<uint16_t
>(0xDC00 + lsh);
1532 return (ch < 0x10000) ?
low(result, ch) :
high(result, ch);
1583 *result =
static_cast<uint8_t
>(ch > 255 ?
'?' : ch);
1604 const uint8_t utf8_byte_mask = 0x3f;
1608 uint8_t lead = *
data;
1613 result = Traits::low(result, lead);
1618 if ((reinterpret_cast<uintptr_t>(data) & 3) == 0)
1621 while (size >= 4 && (*static_cast<const uint32_t*>(static_cast<const void*>(data)) & 0x80808080) == 0)
1623 result = Traits::low(result, data[0]);
1624 result = Traits::low(result, data[1]);
1625 result = Traits::low(result, data[2]);
1626 result = Traits::low(result, data[3]);
1633 else if (static_cast<unsigned int>(lead - 0xC0) < 0x20 && size >= 2 && (data[1] & 0xc0) == 0x80)
1635 result = Traits::low(result, ((lead & ~0xC0) << 6) | (data[1] & utf8_byte_mask));
1640 else if (static_cast<unsigned int>(lead - 0xE0) < 0x10 && size >= 3 && (data[1] & 0xc0) == 0x80 && (data[2] & 0xc0) == 0x80)
1642 result = Traits::low(result, ((lead & ~0xE0) << 12) | ((data[1] & utf8_byte_mask) << 6) | (data[2] & utf8_byte_mask));
1647 else if (static_cast<unsigned int>(lead - 0xF0) < 0x08 && size >= 4 && (data[1] & 0xc0) == 0x80 && (data[2] & 0xc0) == 0x80 && (data[3] & 0xc0) == 0x80)
1649 result = Traits::high(result, ((lead & ~0xF0) << 18) | ((data[1] & utf8_byte_mask) << 12) | ((data[2] & utf8_byte_mask) << 6) | (data[3] & utf8_byte_mask));
1678 result = Traits::low(result, lead);
1683 else if (static_cast<unsigned int>(lead - 0xE000) < 0x2000)
1685 result = Traits::low(result, lead);
1690 else if (static_cast<unsigned int>(lead - 0xD800) < 0x400 && size >= 2)
1694 if (static_cast<unsigned int>(next - 0xDC00) < 0x400)
1696 result = Traits::high(result, 0x10000 + ((lead & 0x3ff) << 10) + (next & 0x3ff));
1730 result = Traits::low(result, lead);
1737 result = Traits::high(result, lead);
1755 result = Traits::low(result, *data);
1793 return decoder::process(reinterpret_cast<const typename decoder::type*>(data), size, result, traits);
1797 #ifdef PUGIXML_WCHAR_MODE
1798 PUGI__FN void convert_wchar_endian_swap(
wchar_t* result,
const wchar_t*
data,
size_t length)
1800 for (
size_t i = 0; i <
length; ++i)
1819 static const unsigned char chartype_table[256] =
1821 55, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 0, 0, 63, 0, 0,
1822 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1823 8, 0, 6, 0, 0, 0, 7, 6, 0, 0, 0, 0, 0, 96, 64, 0,
1824 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 192, 0, 1, 0, 48, 0,
1825 0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1826 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 16, 0, 192,
1827 0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1828 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 0,
1830 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1831 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1832 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1833 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1834 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1835 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1836 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
1837 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192
1849 static const unsigned char chartypex_table[256] =
1851 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 2, 3, 3, 2, 3, 3,
1852 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1853 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 16, 16, 0,
1854 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0, 3, 0, 3, 0,
1856 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1857 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 20,
1858 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1859 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0,
1861 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1862 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1863 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1864 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1865 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1866 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1867 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
1868 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20
1871 #ifdef PUGIXML_WCHAR_MODE
1872 #define PUGI__IS_CHARTYPE_IMPL(c, ct, table) ((static_cast<unsigned int>(c) < 128 ? table[static_cast<unsigned int>(c)] : table[128]) & (ct))
1874 #define PUGI__IS_CHARTYPE_IMPL(c, ct, table) (table[static_cast<unsigned char>(c)] & (ct))
1877 #define PUGI__IS_CHARTYPE(c, ct) PUGI__IS_CHARTYPE_IMPL(c, ct, chartype_table)
1878 #define PUGI__IS_CHARTYPEX(c, ct) PUGI__IS_CHARTYPE_IMPL(c, ct, chartypex_table)
1882 unsigned int ui = 1;
1884 return *
reinterpret_cast<unsigned char*
>(&ui) == 1;
1891 if (
sizeof(
wchar_t) == 2)
1899 #define PUGI__SCANCHAR(ch) { if (offset >= size || data[offset] != ch) return false; offset++; }
1900 #define PUGI__SCANCHARTYPE(ct) { while (offset < size && PUGI__IS_CHARTYPE(data[offset], ct)) offset++; }
1903 if (size < 6 || !((data[0] ==
'<') & (data[1] ==
'?') & (data[2] ==
'x') & (data[3] ==
'm') & (data[4] ==
'l') &&
PUGI__IS_CHARTYPE(data[5],
ct_space)))
1907 for (
size_t i = 6; i + 1 <
size; ++i)
1913 if (data[i] ==
'e' && data[i + 1] ==
'n')
1927 uint8_t delimiter = (offset < size && data[
offset] ==
'"') ?
'"' :
'\'';
1933 out_encoding = data +
offset;
1937 out_length = offset -
start;
1947 #undef PUGI__SCANCHAR
1948 #undef PUGI__SCANCHARTYPE
1956 uint8_t d0 = data[0], d1 = data[1], d2 = data[2], d3 = data[3];
1963 if (d0 == 0xef && d1 == 0xbb && d2 == 0xbf)
return encoding_utf8;
1976 const uint8_t* enc = 0;
1977 size_t enc_length = 0;
1982 if (enc_length == 10
1983 && (enc[0] |
' ') ==
'i' && (enc[1] |
' ') ==
's' && (enc[2] |
' ') ==
'o'
1984 && enc[3] ==
'-' && enc[4] ==
'8' && enc[5] ==
'8' && enc[6] ==
'5' && enc[7] ==
'9'
1985 && enc[8] ==
'-' && enc[9] ==
'1')
1990 && (enc[0] |
' ') ==
'l' && (enc[1] |
' ') ==
'a' && (enc[2] |
' ') ==
't'
1991 && (enc[3] |
' ') ==
'i' && (enc[4] |
' ') ==
'n'
2014 const uint8_t* data =
static_cast<const uint8_t*
>(contents);
2021 size_t length = size /
sizeof(
char_t);
2025 out_buffer =
static_cast<char_t*
>(
const_cast<void*
>(contents));
2031 if (!buffer)
return false;
2034 memcpy(buffer, contents, length *
sizeof(
char_t));
2036 assert(length == 0);
2041 out_length = length + 1;
2047 #ifdef PUGIXML_WCHAR_MODE
2054 PUGI__FN bool convert_buffer_endian_swap(
char_t*& out_buffer,
size_t& out_length,
const void* contents,
size_t size,
bool is_mutable)
2056 const char_t* data =
static_cast<const char_t*
>(contents);
2057 size_t length = size /
sizeof(
char_t);
2063 convert_wchar_endian_swap(buffer, data, length);
2071 if (!buffer)
return false;
2073 convert_wchar_endian_swap(buffer, data, length);
2077 out_length = length + 1;
2085 const typename D::type* data =
static_cast<const typename
D::type*
>(contents);
2086 size_t data_length = size /
sizeof(
typename D::type);
2089 size_t length = D::process(data, data_length, 0,
wchar_counter());
2093 if (!buffer)
return false;
2099 assert(oend == obegin + length);
2103 out_length = length + 1;
2114 if (encoding == wchar_encoding)
2118 if (need_endian_swap_utf(encoding, wchar_encoding))
2119 return convert_buffer_endian_swap(out_buffer, out_length, contents, size, is_mutable);
2130 return (native_encoding == encoding) ?
2140 return (native_encoding == encoding) ?
2149 assert(
false &&
"Invalid encoding");
2155 const typename D::type* data =
static_cast<const typename
D::type*
>(contents);
2156 size_t data_length = size /
sizeof(
typename D::type);
2159 size_t length = D::process(data, data_length, 0,
utf8_counter());
2163 if (!buffer)
return false;
2166 uint8_t* obegin =
reinterpret_cast<uint8_t*
>(
buffer);
2167 uint8_t* oend = D::process(data, data_length, obegin,
utf8_writer());
2169 assert(oend == obegin + length);
2173 out_length = length + 1;
2180 for (
size_t i = 0; i <
size; ++i)
2189 const uint8_t* data =
static_cast<const uint8_t*
>(contents);
2190 size_t data_length =
size;
2194 assert(prefix_length <= data_length);
2196 const uint8_t* postfix = data + prefix_length;
2197 size_t postfix_length = data_length - prefix_length;
2200 if (postfix_length == 0)
return get_mutable_buffer(out_buffer, out_length, contents, size, is_mutable);
2207 if (!buffer)
return false;
2210 memcpy(buffer, data, prefix_length);
2212 uint8_t* obegin =
reinterpret_cast<uint8_t*
>(
buffer);
2215 assert(oend == obegin + length);
2219 out_length = length + 1;
2235 return (native_encoding == encoding) ?
2245 return (native_encoding == encoding) ?
2254 assert(
false &&
"Invalid encoding");
2268 uint8_t*
begin =
reinterpret_cast<uint8_t*
>(
buffer);
2271 assert(begin + size == end);
2276 #ifndef PUGIXML_NO_STL
2284 result.resize(size);
2287 if (size > 0)
as_utf8_end(&result[0], size, str, length);
2294 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(str);
2301 result.resize(length);
2309 assert(begin + length == end);
2317 template <
typename Header>
2321 if (header & xml_memory_page_contents_shared_mask)
return false;
2323 size_t target_length =
strlength(target);
2326 if ((header & header_mask) == 0)
return target_length >=
length;
2329 const size_t reuse_threshold = 32;
2331 return target_length >= length && (target_length < reuse_threshold || target_length - length < target_length / 2);
2334 template <
typename String,
typename Header>
2337 if (source_length == 0)
2346 header &= ~header_mask;
2353 memcpy(dest, source, source_length *
sizeof(
char_t));
2354 dest[source_length] = 0;
2362 if (!alloc->
reserve())
return false;
2366 if (!buf)
return false;
2369 memcpy(buf, source, source_length *
sizeof(
char_t));
2370 buf[source_length] = 0;
2377 header |= header_mask;
2400 memmove(
end - size,
end, reinterpret_cast<char*>(s) - reinterpret_cast<char*>(
end));
2417 memmove(
end - size,
end, reinterpret_cast<char*>(s) - reinterpret_cast<char*>(
end));
2433 unsigned int ucsc = 0;
2441 if (ch ==
';')
return stre;
2445 if (static_cast<unsigned int>(ch -
'0') <= 9)
2446 ucsc = 16 * ucsc + (ch -
'0');
2447 else if (static_cast<unsigned int>((ch |
' ') -
'a') <= 5)
2448 ucsc = 16 * ucsc + ((ch |
' ') -
'a' + 10);
2463 if (ch ==
';')
return stre;
2467 if (static_cast<unsigned int>(static_cast<unsigned int>(ch) -
'0') <= 9)
2468 ucsc = 10 * ucsc + (ch -
'0');
2480 #ifdef PUGIXML_WCHAR_MODE
2486 g.
push(s, stre - s);
2496 if (*++stre ==
'p' && *++stre ==
';')
2501 g.
push(s, stre - s);
2505 else if (*stre ==
'p')
2507 if (*++stre ==
'o' && *++stre ==
's' && *++stre ==
';')
2512 g.
push(s, stre - s);
2521 if (*++stre ==
't' && *++stre ==
';')
2526 g.
push(s, stre - s);
2534 if (*++stre ==
't' && *++stre ==
';')
2539 g.
push(s, stre - s);
2547 if (*++stre ==
'u' && *++stre ==
'o' && *++stre ==
't' && *++stre ==
';')
2552 g.
push(s, stre - s);
2566 #define PUGI__ENDSWITH(c, e) ((c) == (e) || ((c) == 0 && endch == (e)))
2567 #define PUGI__SKIPWS() { while (PUGI__IS_CHARTYPE(*s, ct_space)) ++s; }
2568 #define PUGI__OPTSET(OPT) ( optmsk & (OPT) )
2569 #define PUGI__PUSHNODE(TYPE) { cursor = append_new_node(cursor, *alloc, TYPE); if (!cursor) PUGI__THROW_ERROR(status_out_of_memory, s); }
2570 #define PUGI__POPNODE() { cursor = cursor->parent; }
2571 #define PUGI__SCANFOR(X) { while (*s != 0 && !(X)) ++s; }
2572 #define PUGI__SCANWHILE(X) { while (X) ++s; }
2573 #define PUGI__SCANWHILE_UNROLL(X) { for (;;) { char_t ss = s[0]; if (PUGI__UNLIKELY(!(X))) { break; } ss = s[1]; if (PUGI__UNLIKELY(!(X))) { s += 1; break; } ss = s[2]; if (PUGI__UNLIKELY(!(X))) { s += 2; break; } ss = s[3]; if (PUGI__UNLIKELY(!(X))) { s += 3; break; } s += 4; } }
2574 #define PUGI__ENDSEG() { ch = *s; *s = 0; ++s; }
2575 #define PUGI__THROW_ERROR(err, m) return error_offset = m, error_status = err, static_cast<char_t*>(0)
2576 #define PUGI__CHECK_ERROR(err, m) { if (*s == 0) PUGI__THROW_ERROR(err, m); }
2590 if (*s ==
'\n') g.
push(s, 1);
2592 else if (s[0] ==
'-' && s[1] ==
'-' &&
PUGI__ENDSWITH(s[2],
'>'))
2596 return s + (s[2] ==
'>' ? 3 : 2);
2618 if (*s ==
'\n') g.
push(s, 1);
2620 else if (s[0] ==
']' && s[1] ==
']' &&
PUGI__ENDSWITH(s[2],
'>'))
2664 if (*s ==
'\n') g.
push(s, 1);
2691 switch (((optmask >> 4) & 3) | ((optmask >> 9) & 4))
2701 default: assert(
false);
return 0;
2728 if (*s == end_quote)
2730 char_t* str = g.
flush(s);
2743 char_t* str = s + 1;
2769 if (*s == end_quote)
2781 if (*s ==
'\n') g.
push(s, 1);
2805 if (*s == end_quote)
2811 else if (*s ==
'\r')
2815 if (*s ==
'\n') g.
push(s, 1);
2837 if (*s == end_quote)
2860 switch ((optmask >> 4) & 15)
2878 default: assert(
false);
return 0;
2885 result.status = status;
2910 if (*s ==
'"' || *s ==
'\'')
2919 else if (s[0] ==
'<' && s[1] ==
'?')
2928 else if (s[0] ==
'<' && s[1] ==
'!' && s[2] ==
'-' && s[3] ==
'-')
2945 assert(s[0] ==
'<' && s[1] ==
'!' && s[2] ==
'[');
2950 if (s[0] ==
'<' && s[1] ==
'!' && s[2] ==
'[')
2956 else if (s[0] ==
']' && s[1] ==
']' && s[2] ==
'>')
2976 assert((s[0] ==
'<' || s[0] == 0) && s[1] ==
'!');
2981 if (s[0] ==
'<' && s[1] ==
'!' && s[2] !=
'-')
2996 else if (s[0] ==
'<' || s[0] ==
'"' || s[0] ==
'\'')
3052 s += (s[2] ==
'>' ? 3 : 2);
3060 if (*++s==
'C' && *++s==
'D' && *++s==
'A' && *++s==
'T' && *++s==
'A' && *++s ==
'[')
3093 s += (s[1] ==
'>' ? 2 : 1);
3097 else if (s[0] ==
'D' && s[1] ==
'O' && s[2] ==
'C' && s[3] ==
'T' && s[4] ==
'Y' && s[5] ==
'P' &&
PUGI__ENDSWITH(s[6],
'E'))
3103 char_t* mark = s + 9;
3108 assert((*s == 0 && endch ==
'>') || *s ==
'>');
3117 cursor->value = mark;
3127 char_t*
parse_question(char_t*
s, xml_node_struct*& ref_cursor,
unsigned int optmsk, char_t endch)
3130 xml_node_struct* cursor = ref_cursor;
3145 bool declaration = (target[0] |
' ') ==
'x' && (target[1] |
' ') ==
'm' && (target[2] |
' ') ==
'l' && target + 3 == s;
3195 cursor->value =
value;
3212 s += (s[1] ==
'>' ? 2 : 1);
3216 ref_cursor = cursor;
3221 char_t*
parse_tree(char_t*
s, xml_node_struct* root,
unsigned int optmsk, char_t endch)
3227 xml_node_struct* cursor = root;
3279 if (*s ==
'"' || *s ==
'\'')
3285 s = strconv_attribute(s, ch);
3308 else if (*s == 0 && endch ==
'>')
3321 else if (*s == 0 && endch ==
'>')
3353 char_t*
name = cursor->name;
3403 if (*s ==
'<' || !*s)
3414 if (s[0] !=
'<' || s[1] !=
'/' || cursor->first_child)
continue;
3436 s = strconv_pcdata(s);
3459 #ifdef PUGIXML_WCHAR_MODE
3462 unsigned int bom = 0xfeff;
3463 return (s[0] == static_cast<wchar_t>(bom)) ? s + 1 :
s;
3468 return (s[0] ==
'\xef' && s[1] ==
'\xbb' && s[2] ==
'\xbf') ? s + 3 :
s;
3478 node = node->next_sibling;
3491 xml_node_struct* last_root_child = root->first_child ? root->first_child->prev_sibling_c + 0 : 0;
3494 xml_parser parser(static_cast<xml_allocator*>(xmldoc));
3497 char_t endch = buffer[length - 1];
3498 buffer[length - 1] = 0;
3504 parser.
parse_tree(buffer_data, root, optmsk, endch);
3507 assert(result.offset >= 0 && static_cast<size_t>(result.offset) <= length);
3516 xml_node_struct* first_root_child_parsed = last_root_child ? last_root_child->next_sibling + 0 : root->first_child+ 0;
3524 if (result.offset > 0 && static_cast<size_t>(result.offset) == length - 1 && endch == 0)
3535 #ifdef PUGIXML_WCHAR_MODE
3564 typename T::value_type end = D::process(reinterpret_cast<const typename D::type*>(data), length, dest,
T());
3566 return static_cast<size_t>(end - dest) *
sizeof(*dest);
3573 typename T::value_type end = D::process(reinterpret_cast<const typename D::type*>(data), length, dest,
T());
3581 return static_cast<size_t>(end - dest) *
sizeof(*dest);
3584 #ifdef PUGIXML_WCHAR_MODE
3587 if (length < 1)
return 0;
3590 return (
sizeof(
wchar_t) == 2 && static_cast<unsigned int>(static_cast<uint16_t>(data[length - 1]) - 0xD800) < 0x400) ? length - 1 :
length;
3598 convert_wchar_endian_swap(r_char, data, length);
3600 return length *
sizeof(
char_t);
3627 assert(
false &&
"Invalid encoding");
3633 if (length < 5)
return 0;
3635 for (
size_t i = 1; i <= 4; ++i)
3637 uint8_t ch =
static_cast<uint8_t
>(data[length - i]);
3640 if ((ch & 0xc0) != 0x80)
return length - i;
3666 assert(
false &&
"Invalid encoding");
3689 void flush(
const char_t* data,
size_t size)
3691 if (size == 0)
return;
3695 writer.write(data, size *
sizeof(char_t));
3700 assert(result <=
sizeof(
scratch));
3718 writer.write(data, length *
sizeof(char_t));
3731 flush(data, chunk_size);
3735 length -= chunk_size;
3742 memcpy(buffer +
bufsize, data, length *
sizeof(char_t));
3752 memcpy(buffer + offset, data, length *
sizeof(char_t));
3767 buffer[offset++] = *data++;
3777 size_t length = offset -
bufsize;
3780 bufsize = offset - extra;
3791 buffer[offset + 0] = d0;
3800 buffer[offset + 0] = d0;
3801 buffer[offset + 1] = d1;
3805 void write(char_t d0, char_t d1, char_t d2)
3810 buffer[offset + 0] = d0;
3811 buffer[offset + 1] = d1;
3812 buffer[offset + 2] = d2;
3816 void write(char_t d0, char_t d1, char_t d2, char_t d3)
3821 buffer[offset + 0] = d0;
3822 buffer[offset + 1] = d1;
3823 buffer[offset + 2] = d2;
3824 buffer[offset + 3] = d3;
3828 void write(char_t d0, char_t d1, char_t d2, char_t d3, char_t d4)
3833 buffer[offset + 0] = d0;
3834 buffer[offset + 1] = d1;
3835 buffer[offset + 2] = d2;
3836 buffer[offset + 3] = d3;
3837 buffer[offset + 4] = d4;
3841 void write(char_t d0, char_t d1, char_t d2, char_t d3, char_t d4, char_t d5)
3846 buffer[offset + 0] = d0;
3847 buffer[offset + 1] = d1;
3848 buffer[offset + 2] = d2;
3849 buffer[offset + 3] = d3;
3850 buffer[offset + 4] = d4;
3851 buffer[offset + 5] = d5;
3861 #ifdef PUGIXML_MEMORY_OUTPUT_STACK
3862 PUGIXML_MEMORY_OUTPUT_STACK
3889 const char_t* prev =
s;
3894 writer.
write_buffer(prev, static_cast<size_t>(s - prev));
3900 writer.
write(
'&',
'a',
'm',
'p',
';');
3904 writer.
write(
'&',
'l',
't',
';');
3908 writer.
write(
'&',
'g',
't',
';');
3912 writer.
write(
'&',
'q',
'u',
'o',
't',
';');
3917 unsigned int ch =
static_cast<unsigned int>(*s++);
3920 writer.
write(
'&',
'#', static_cast<char_t>((ch / 10) +
'0'), static_cast<char_t>((ch % 10) +
'0'),
';');
3938 writer.
write(
'<',
'!',
'[',
'C',
'D');
3939 writer.
write(
'A',
'T',
'A',
'[');
3941 const char_t* prev =
s;
3944 while (*s && !(s[0] ==
']' && s[1] ==
']' && s[2] ==
'>')) ++
s;
3949 writer.
write_buffer(prev, static_cast<size_t>(s - prev));
3951 writer.
write(
']',
']',
'>');
3958 switch (indent_length)
3962 for (
unsigned int i = 0; i <
depth; ++i)
3963 writer.
write(indent[0]);
3969 for (
unsigned int i = 0; i <
depth; ++i)
3970 writer.
write(indent[0], indent[1]);
3976 for (
unsigned int i = 0; i <
depth; ++i)
3977 writer.
write(indent[0], indent[1], indent[2]);
3983 for (
unsigned int i = 0; i <
depth; ++i)
3984 writer.
write(indent[0], indent[1], indent[2], indent[3]);
3990 for (
unsigned int i = 0; i <
depth; ++i)
3998 writer.
write(
'<',
'!',
'-',
'-');
4002 const char_t* prev =
s;
4005 while (*s && !(s[0] ==
'-' && (s[1] ==
'-' || s[1] == 0))) ++
s;
4007 writer.
write_buffer(prev, static_cast<size_t>(s - prev));
4013 writer.
write(
'-',
' ');
4018 writer.
write(
'-',
'-',
'>');
4025 const char_t* prev =
s;
4028 while (*s && !(s[0] ==
'?' && s[1] ==
'>')) ++
s;
4030 writer.
write_buffer(prev, static_cast<size_t>(s - prev));
4034 assert(s[0] ==
'?' && s[1] ==
'>');
4036 writer.
write(
'?',
' ',
'>');
4044 const char_t* default_name =
PUGIXML_TEXT(
":anonymous");
4046 for (xml_attribute_struct*
a = node->first_attribute;
a;
a =
a->next_attribute)
4060 writer.
write(
'=',
'"');
4071 const char_t* default_name =
PUGIXML_TEXT(
":anonymous");
4072 const char_t*
name = node->name ? node->name + 0 : default_name;
4077 if (node->first_attribute)
4083 if (!node->first_child)
4087 writer.
write(
'>',
'<',
'/');
4098 writer.
write(
'/',
'>');
4116 if (!node->first_child)
4118 writer.
write(
'<',
'/');
4133 const char_t* default_name =
PUGIXML_TEXT(
":anonymous");
4134 const char_t*
name = node->name ? node->name + 0 : default_name;
4136 writer.
write(
'<',
'/');
4143 const char_t* default_name =
PUGIXML_TEXT(
":anonymous");
4160 writer.
write(
'<',
'?');
4161 writer.
write_string(node->name ? node->name + 0 : default_name);
4169 writer.
write(
'?',
'>');
4173 writer.
write(
'<',
'?');
4174 writer.
write_string(node->name ? node->name + 0 : default_name);
4176 writer.
write(
'?',
'>');
4180 writer.
write(
'<',
'!',
'D',
'O',
'C');
4181 writer.
write(
'T',
'Y',
'P',
'E');
4193 assert(
false &&
"Invalid node type");
4208 xml_node_struct* node = root;
4239 node = node->first_child;
4248 if (node->first_child)
4250 node = node->first_child;
4263 while (node != root)
4265 if (node->next_sibling)
4267 node = node->next_sibling;
4271 node = node->parent;
4290 while (node != root);
4298 for (xml_node_struct* child = node->first_child; child; child = child->next_sibling)
4311 for (xml_attribute_struct*
a = node->first_attribute;
a;
a =
a->next_attribute)
4339 if (parent.root() != child.root())
4343 xml_node cur = parent;
4356 template <
typename String,
typename Header>
4359 assert(!dest && (header & header_mask) == 0);
4363 if (alloc && (source_header & header_mask) == 0)
4368 header |= xml_memory_page_contents_shared_mask;
4369 source_header |= xml_memory_page_contents_shared_mask;
4378 node_copy_string(dn->name, dn->header, xml_memory_page_name_allocated_mask, sn->name, sn->header, shared_alloc);
4379 node_copy_string(dn->value, dn->header, xml_memory_page_value_allocated_mask, sn->value, sn->header, shared_alloc);
4381 for (xml_attribute_struct* sa = sn->first_attribute; sa; sa = sa->next_attribute)
4387 node_copy_string(da->name, da->header, xml_memory_page_name_allocated_mask, sa->name, sa->header, shared_alloc);
4388 node_copy_string(da->value, da->header, xml_memory_page_value_allocated_mask, sa->value, sa->header, shared_alloc);
4400 xml_node_struct* dit = dn;
4401 xml_node_struct* sit = sn->first_child;
4403 while (sit && sit != sn)
4413 if (sit->first_child)
4416 sit = sit->first_child;
4425 if (sit->next_sibling)
4427 sit = sit->next_sibling;
4443 node_copy_string(da->name, da->header, xml_memory_page_name_allocated_mask, sa->name, sa->header, shared_alloc);
4444 node_copy_string(da->value, da->header, xml_memory_page_value_allocated_mask, sa->value, sa->header, shared_alloc);
4458 const char_t* s =
value;
4465 s += (*s ==
'+' || *s ==
'-');
4467 bool overflow =
false;
4469 if (s[0] ==
'0' && (s[1] |
' ') ==
'x')
4477 const char_t* start =
s;
4481 if (static_cast<unsigned>(*s -
'0') < 10)
4482 result = result * 16 + (*s -
'0');
4483 else if (static_cast<unsigned>((*s |
' ') -
'a') < 6)
4484 result = result * 16 + ((*s |
' ') -
'a' + 10);
4491 size_t digits =
static_cast<size_t>(s -
start);
4493 overflow = digits >
sizeof(U) * 2;
4501 const char_t* start =
s;
4505 if (static_cast<unsigned>(*s -
'0') < 10)
4506 result = result * 10 + (*s -
'0');
4513 size_t digits =
static_cast<size_t>(s -
start);
4517 const size_t max_digits10 =
sizeof(U) == 8 ? 20 :
sizeof(U) == 4 ? 10 : 5;
4518 const char_t max_lead =
sizeof(U) == 8 ?
'1' :
sizeof(U) == 4 ?
'4' :
'6';
4519 const size_t high_bit =
sizeof(U) * 8 - 1;
4525 return (overflow || result > minneg) ? 0 - minneg : 0 -
result;
4527 return (overflow || result > maxpos) ? maxpos :
result;
4532 return string_to_integer<unsigned int>(
value, 0 -
static_cast<unsigned int>(INT_MIN), INT_MAX);
4537 return string_to_integer<unsigned int>(
value, 0, UINT_MAX);
4542 #ifdef PUGIXML_WCHAR_MODE
4543 return wcstod(value, 0);
4551 #ifdef PUGIXML_WCHAR_MODE
4552 return static_cast<float>(wcstod(value, 0));
4554 return static_cast<float>(
strtod(value, 0));
4564 return (first ==
'1' || first ==
't' || first ==
'T' || first ==
'y' || first ==
'Y');
4567 #ifdef PUGIXML_HAS_LONG_LONG
4568 PUGI__FN long long get_value_llong(
const char_t* value)
4570 return string_to_integer<unsigned long long>(
value, 0 -
static_cast<unsigned long long>(LLONG_MIN), LLONG_MAX);
4573 PUGI__FN unsigned long long get_value_ullong(
const char_t* value)
4575 return string_to_integer<unsigned long long>(
value, 0, ULLONG_MAX);
4581 char_t* result = end - 1;
4586 *result-- =
static_cast<char_t
>(
'0' + (rest % 10));
4591 assert(result >= begin);
4600 template <
typename String,
typename Header>
4603 #ifdef PUGIXML_WCHAR_MODE
4605 assert(strlen(buf) <
sizeof(wbuf) /
sizeof(wbuf[0]));
4608 for (; buf[
offset]; ++
offset) wbuf[offset] = buf[offset];
4610 return strcpy_insitu(dest, header, header_mask, wbuf, offset);
4612 return strcpy_insitu(dest, header, header_mask, buf, strlen(buf));
4616 template <
typename U,
typename String,
typename Header>
4620 char_t*
end = buf +
sizeof(
buf) /
sizeof(buf[0]);
4623 return strcpy_insitu(dest, header, header_mask, begin, end - begin);
4626 template <
typename String,
typename Header>
4635 template <
typename String,
typename Header>
4644 template <
typename String,
typename Header>
4665 if (own && buffer != contents && contents) impl::xml_memory::deallocate(contents);
4668 if (own || buffer != contents) *out_buffer =
buffer;
4674 xml_parse_result res = impl::xml_parser::parse(buffer, length, doc, root, options);
4677 res.encoding = buffer_encoding;
4685 #if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE)
4687 typedef __int64 length_type;
4690 length_type length = _ftelli64(file);
4692 #elif defined(__MINGW32__) && !defined(__NO_MINGW_LFS) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR))
4694 typedef off64_t length_type;
4697 length_type length = ftello64(file);
4701 typedef long length_type;
4704 length_type length =
ftell(file);
4712 size_t result =
static_cast<size_t>(
length);
4726 #ifdef PUGIXML_WCHAR_MODE
4729 if (encoding == wchar_encoding || need_endian_swap_utf(encoding, wchar_encoding))
4731 size_t length = size /
sizeof(
char_t);
4733 static_cast<char_t*
>(
buffer)[length] = 0;
4734 return (length + 1) *
sizeof(
char_t);
4739 static_cast<char*
>(
buffer)[size] = 0;
4756 size_t max_suffix_size =
sizeof(
char_t);
4763 size_t read_size = fread(contents, 1, size, file);
4765 if (read_size != size)
4773 return load_buffer_impl(doc, doc, contents,
zero_terminate_buffer(contents, size, real_encoding), options, real_encoding,
true,
true, out_buffer);
4781 #ifndef PUGIXML_NO_STL
4787 if (!memory)
return 0;
4812 T data[xml_memory_page_size /
sizeof(
T)];
4823 while (!stream.eof())
4830 if (last) last = last->
next = chunk;
4831 else chunks.
data = last = chunk;
4834 stream.read(chunk->
data, static_cast<std::streamsize>(
sizeof(chunk->
data) /
sizeof(
T)));
4835 chunk->
size =
static_cast<size_t>(stream.gcount()) *
sizeof(
T);
4838 if (stream.bad() || (!stream.eof() && stream.fail()))
return status_io_error;
4842 total += chunk->
size;
4845 size_t max_suffix_size =
sizeof(
char_t);
4855 assert(write + chunk->size <= buffer + total);
4856 memcpy(write, chunk->data, chunk->size);
4857 write += chunk->size;
4860 assert(write == buffer + total);
4872 typename std::basic_istream<T>::pos_type pos = stream.tellg();
4874 std::streamoff length = stream.tellg() - pos;
4880 size_t read_length =
static_cast<size_t>(
length);
4882 if (static_cast<std::streamsize>(read_length) != length || length < 0)
return status_out_of_memory;
4884 size_t max_suffix_size =
sizeof(
char_t);
4890 stream.read(static_cast<T*>(buffer.
data), static_cast<std::streamsize>(read_length));
4893 if (stream.bad() || (!stream.eof() && stream.fail()))
return status_io_error;
4896 size_t actual_length =
static_cast<size_t>(stream.gcount());
4897 assert(actual_length <= read_length);
4899 *out_buffer = buffer.
release();
4900 *out_size = actual_length *
sizeof(
T);
4915 if (stream.tellg() < 0)
4927 return load_buffer_impl(doc, doc, buffer,
zero_terminate_buffer(buffer, size, real_encoding), options, real_encoding,
true,
true, out_buffer);
4931 #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) || (defined(__MINGW32__) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR)))
4934 return _wfopen(path, mode);
4947 if (!result)
return 0;
4962 if (!path_utf8)
return 0;
4965 char mode_ascii[4] = {0};
4966 for (
size_t i = 0; mode[i]; ++i) mode_ascii[i] = static_cast<char>(mode[i]);
4969 FILE* result =
fopen(path_utf8, mode_ascii);
4980 if (!file)
return false;
4982 xml_writer_file writer(file);
4983 doc.save(writer, indent, flags, encoding);
4985 return ferror(file) == 0;
5013 size_t result = fwrite(data, 1, size, static_cast<FILE*>(file));
5017 #ifndef PUGIXML_NO_STL
5030 assert(!wide_stream);
5031 narrow_stream->write(reinterpret_cast<const char*>(data), static_cast<std::streamsize>(size));
5035 assert(wide_stream);
5036 assert(size %
sizeof(
wchar_t) == 0);
5038 wide_stream->write(reinterpret_cast<const wchar_t*>(data), static_cast<std::streamsize>(size /
sizeof(
wchar_t)));
5078 PUGI__FN xml_attribute::operator xml_attribute::unspecified_bool_type()
const
5080 return _attr ? unspecified_bool_xml_attribute : 0;
5090 return (_attr == r._attr);
5095 return (_attr != r._attr);
5100 return (_attr < r._attr);
5105 return (_attr > r._attr);
5110 return (_attr <= r._attr);
5115 return (_attr >= r._attr);
5130 return (_attr && _attr->
value) ? _attr->
value + 0 : def;
5158 #ifdef PUGIXML_HAS_LONG_LONG
5159 PUGI__FN long long xml_attribute::as_llong(
long long def)
const
5161 return (_attr && _attr->
value) ? impl::get_value_llong(_attr->
value) : def;
5164 PUGI__FN unsigned long long xml_attribute::as_ullong(
unsigned long long def)
const
5166 return (_attr && _attr->
value) ? impl::get_value_ullong(_attr->
value) : def;
5243 #ifdef PUGIXML_HAS_LONG_LONG
5259 if (!_attr)
return false;
5266 if (!_attr)
return false;
5273 if (!_attr)
return false;
5275 return impl::set_value_integer<unsigned int>(_attr->
value, _attr->
header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0);
5280 if (!_attr)
return false;
5282 return impl::set_value_integer<unsigned int>(_attr->
value, _attr->
header, impl::xml_memory_page_value_allocated_mask, rhs,
false);
5287 if (!_attr)
return false;
5289 return impl::set_value_integer<unsigned long>(_attr->
value, _attr->
header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0);
5294 if (!_attr)
return false;
5296 return impl::set_value_integer<unsigned long>(_attr->
value, _attr->
header, impl::xml_memory_page_value_allocated_mask, rhs,
false);
5301 if (!_attr)
return false;
5308 if (!_attr)
return false;
5315 if (!_attr)
return false;
5320 #ifdef PUGIXML_HAS_LONG_LONG
5323 if (!_attr)
return false;
5325 return impl::set_value_integer<unsigned long long>(_attr->
value, _attr->
header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0);
5330 if (!_attr)
return false;
5332 return impl::set_value_integer<unsigned long long>(_attr->
value, _attr->
header, impl::xml_memory_page_value_allocated_mask, rhs,
false);
5339 return (
bool)lhs && rhs;
5344 return (
bool)lhs || rhs;
5362 return _root ? unspecified_bool_xml_node : 0;
5762 if (!alloc.reserve())
return xml_node();
5779 if (!alloc.reserve())
return xml_node();
5797 if (!alloc.reserve())
return xml_node();
5815 if (!alloc.reserve())
return xml_node();
5869 if (!alloc.reserve())
return xml_node();
5886 if (!alloc.reserve())
return xml_node();
5904 if (!alloc.reserve())
return xml_node();
5922 if (!alloc.reserve())
return xml_node();
5938 if (!alloc.reserve())
return xml_node();
5954 if (!alloc.reserve())
return xml_node();
5972 if (!alloc.reserve())
return xml_node();
5990 if (!alloc.reserve())
return xml_node();
6008 if (!
_root || !a._attr)
return false;
6012 if (!alloc.reserve())
return false;
6030 if (!alloc.reserve())
return false;
6047 doc->header |= impl::xml_memory_page_contents_shared_mask;
6050 impl::xml_memory_page* page = 0;
6051 impl::xml_extra_buffer* extra =
static_cast<impl::xml_extra_buffer*
>(doc->allocate_memory(
sizeof(impl::xml_extra_buffer), page));
6058 extra->next = doc->extra_buffers;
6059 doc->extra_buffers = extra;
6062 impl::name_null_sentry sentry(
_root);
6094 #ifndef PUGIXML_NO_STL
6103 offset += (i !=
_root);
6108 result.resize(offset);
6113 result[--
offset] = delimiter;
6115 if (
j->name && *
j->name)
6120 memcpy(&result[offset],
j->name, length *
sizeof(char_t));
6124 assert(offset == 0);
6134 if (!
_root || !path_ || !path_[0])
return found;
6136 if (path_[0] == delimiter)
6139 found = found.
root();
6143 const char_t* path_segment = path_;
6145 while (*path_segment == delimiter) ++path_segment;
6147 const char_t* path_segment_end = path_segment;
6149 while (*path_segment_end && *path_segment_end != delimiter) ++path_segment_end;
6151 if (path_segment == path_segment_end)
return found;
6153 const char_t* next_segment = path_segment_end;
6155 while (*next_segment == delimiter) ++next_segment;
6157 if (*path_segment ==
'.' && path_segment + 1 == path_segment_end)
6159 else if (*path_segment ==
'.' && *(path_segment+1) ==
'.' && path_segment + 2 == path_segment_end)
6165 if (
j->name &&
impl::strequalrange(
j->name, path_segment, static_cast<size_t>(path_segment_end - path_segment)))
6167 xml_node subsearch =
xml_node(
j).first_element_by_path(next_segment, delimiter);
6169 if (subsearch)
return subsearch;
6182 if (!walker.
begin(arg_begin))
return false;
6193 if (!walker.
for_each(arg_for_each))
6216 while (cur && cur != *
this);
6219 assert(walker._depth == -1);
6222 return walker.
end(arg_end);
6239 impl::xml_buffered_writer buffered_writer(writer, encoding);
6243 buffered_writer.flush();
6246 #ifndef PUGIXML_NO_STL
6251 print(writer, indent, flags, encoding, depth);
6264 if (!
_root)
return -1;
6269 if (!doc.buffer || doc.extra_buffers)
return -1;
6295 return (
bool)lhs && rhs;
6300 return (
bool)lhs || rhs;
6308 PUGI__FN xml_node_struct* xml_text::_data()
const
6323 PUGI__FN xml_node_struct* xml_text::_data_new()
6325 xml_node_struct* d = _data();
6339 PUGI__FN xml_text::operator xml_text::unspecified_bool_type()
const
6341 return _data() ? unspecified_bool_xml_text : 0;
6351 return _data() == 0;
6358 return (d && d->value) ? d->value + 0 :
PUGIXML_TEXT(
"");
6365 return (d && d->value) ? d->value + 0 : def;
6403 #ifdef PUGIXML_HAS_LONG_LONG
6404 PUGI__FN long long xml_text::as_llong(
long long def)
const
6408 return (d && d->value) ? impl::get_value_llong(d->value) : def;
6411 PUGI__FN unsigned long long xml_text::as_ullong(
unsigned long long def)
const
6413 xml_node_struct* d = _data();
6415 return (d && d->value) ? impl::get_value_ullong(d->value) : def;
6430 return dn ? impl::set_value_integer<unsigned int>(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) :
false;
6437 return dn ? impl::set_value_integer<unsigned int>(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs,
false) :
false;
6444 return dn ? impl::set_value_integer<unsigned long>(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) :
false;
6451 return dn ? impl::set_value_integer<unsigned long>(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs,
false) :
false;
6458 return dn ?
impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs) :
false;
6465 return dn ?
impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs) :
false;
6472 return dn ?
impl::set_value_bool(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs) :
false;
6475 #ifdef PUGIXML_HAS_LONG_LONG
6480 return dn ? impl::set_value_integer<unsigned long long>(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) :
false;
6485 xml_node_struct* dn = _data_new();
6487 return dn ? impl::set_value_integer<unsigned long long>(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs,
false) :
false;
6539 #ifdef PUGIXML_HAS_LONG_LONG
6561 return (
bool)lhs && rhs;
6566 return (
bool)lhs || rhs;
6594 assert(_wrap.
_root);
6600 assert(_wrap.
_root);
6601 return const_cast<xml_node*
>(&_wrap);
6606 assert(_wrap.
_root);
6645 return _wrap._attr == rhs._wrap._attr && _parent.
_root == rhs._parent.
_root;
6650 return _wrap._attr != rhs._wrap._attr || _parent.
_root != rhs._parent.
_root;
6655 assert(_wrap._attr);
6661 assert(_wrap._attr);
6667 assert(_wrap._attr);
6716 assert(_wrap.
_root);
6722 assert(_wrap.
_root);
6723 return const_cast<xml_node*
>(&_wrap);
6728 assert(_wrap.
_root);
6784 case status_bad_pi:
return "Error parsing document declaration/processing instruction";
6798 default:
return "Unknown error";
6826 PUGI__FN void xml_document::_create()
6830 #ifdef PUGIXML_COMPACT
6831 const size_t page_offset =
sizeof(uint32_t);
6833 const size_t page_offset = 0;
6837 PUGI__STATIC_ASSERT(
sizeof(impl::xml_memory_page) +
sizeof(impl::xml_document_struct) + page_offset <=
sizeof(_memory));
6840 impl::xml_memory_page* page = impl::xml_memory_page::construct(_memory);
6843 page->busy_size = impl::xml_memory_page_size;
6846 #ifdef PUGIXML_COMPACT
6848 page->compact_page_marker =
reinterpret_cast<uint32_t*
>(
static_cast<void*
>(
reinterpret_cast<char*
>(page) +
sizeof(impl::xml_memory_page)));
6849 *page->compact_page_marker =
sizeof(impl::xml_memory_page);
6853 _root =
new (
reinterpret_cast<char*
>(page) +
sizeof(impl::xml_memory_page) + page_offset) impl::xml_document_struct(page);
6857 page->allocator =
static_cast<impl::xml_document_struct*
>(
_root);
6860 #ifdef PUGIXML_COMPACT
6861 page->allocator->_hash = &
static_cast<impl::xml_document_struct*
>(
_root)->hash;
6865 assert(reinterpret_cast<char*>(
_root) +
sizeof(impl::xml_document_struct) <= _memory +
sizeof(_memory));
6868 PUGI__FN void xml_document::_destroy()
6875 impl::xml_memory::deallocate(_buffer);
6880 for (impl::xml_extra_buffer* extra = static_cast<impl::xml_document_struct*>(
_root)->extra_buffers; extra; extra = extra->next)
6882 if (extra->buffer) impl::xml_memory::deallocate(extra->buffer);
6887 assert(root_page && !root_page->prev);
6888 assert(reinterpret_cast<char*>(root_page) >= _memory && reinterpret_cast<char*>(root_page) < _memory +
sizeof(_memory));
6890 for (impl::xml_memory_page* page = root_page->next; page; )
6892 impl::xml_memory_page* next = page->next;
6894 impl::xml_allocator::deallocate_page(page);
6899 #ifdef PUGIXML_COMPACT
6901 static_cast<impl::xml_document_struct*
>(
_root)->hash.clear();
6907 #ifndef PUGIXML_NO_STL
6926 #ifdef PUGIXML_WCHAR_MODE
6944 using impl::auto_deleter;
6954 using impl::auto_deleter;
6964 return impl::load_buffer_impl(static_cast<impl::xml_document_struct*>(
_root),
_root, const_cast<void*>(contents), size, options, encoding,
false,
false, &_buffer);
6983 impl::xml_buffered_writer buffered_writer(writer, encoding);
6988 #ifdef PUGIXML_WCHAR_MODE
6989 unsigned int bom = 0xfeff;
6990 buffered_writer.write(static_cast<wchar_t>(bom));
6992 buffered_writer.write(
'\xef',
'\xbb',
'\xbf');
6998 buffered_writer.write_string(
PUGIXML_TEXT(
"<?xml version=\"1.0\""));
7000 buffered_writer.write(
'?',
'>');
7001 if (!(flags &
format_raw)) buffered_writer.write(
'\n');
7006 buffered_writer.flush();
7009 #ifndef PUGIXML_NO_STL
7014 save(writer, indent, flags, encoding);
7027 using impl::auto_deleter;
7035 using impl::auto_deleter;
7052 #ifndef PUGIXML_NO_STL
7080 impl::xml_memory::allocate = allocate;
7081 impl::xml_memory::deallocate = deallocate;
7086 return impl::xml_memory::allocate;
7091 return impl::xml_memory::deallocate;
7095 #if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
7101 return std::bidirectional_iterator_tag();
7106 return std::bidirectional_iterator_tag();
7111 return std::bidirectional_iterator_tag();
7116 #if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
7122 return std::bidirectional_iterator_tag();
7127 return std::bidirectional_iterator_tag();
7132 return std::bidirectional_iterator_tag();
7137 #ifndef PUGIXML_NO_XPATH
7172 template <
typename T>
void swap(T& lhs, T& rhs)
7183 for (I it = begin + 1; it !=
end; ++it)
7184 if (pred(*it, *result))
7192 while (end - begin > 1)
swap(*begin++, *--end);
7198 while (end - begin > 1 && *begin != *(begin + 1)) begin++;
7200 if (begin == end)
return begin;
7206 while (begin != end)
7208 if (*begin != *write)
7209 *++write = *begin++;
7220 while (begin != end) *--target = *--
end;
7225 assert(begin != end);
7227 for (I it = begin + 1; it !=
end; ++it)
7231 if (pred(val, *begin))
7242 while (pred(val, *(hole - 1)))
7244 *hole = *(hole - 1);
7255 template <
typename I,
typename Pred>
void partition(I
begin, I middle, I
end,
const Pred& pred, I* out_eqbeg, I* out_eqend)
7257 I eqbeg = middle, eqend = middle + 1;
7260 while (eqbeg != begin && *(eqbeg - 1) == *eqbeg) --eqbeg;
7261 while (eqend != end && *eqend == *eqbeg) ++eqend;
7264 I ltend = eqbeg, gtbeg = eqend;
7269 for (; gtbeg !=
end; ++gtbeg)
7270 if (!pred(*eqbeg, *gtbeg))
7272 if (*gtbeg == *eqbeg)
swap(*gtbeg, *eqend++);
7277 for (; ltend !=
begin; --ltend)
7278 if (!pred(*(ltend - 1), *eqbeg))
7280 if (*eqbeg == *(ltend - 1))
swap(*(ltend - 1), *--eqbeg);
7285 if (gtbeg == end && ltend == begin)
7295 if (--ltend != --eqbeg)
swap(*ltend, *eqbeg);
7296 swap(*eqbeg, *--eqend);
7298 else if (ltend == begin)
7300 if (eqend != gtbeg)
swap(*eqbeg, *eqend);
7302 swap(*gtbeg++, *eqbeg++);
7304 else swap(*gtbeg++, *--ltend);
7310 if (pred(*middle, *first))
swap(*middle, *first);
7311 if (pred(*last, *middle))
swap(*last, *middle);
7312 if (pred(*middle, *first))
swap(*middle, *first);
7315 template <
typename I,
typename Pred>
void median(I
first, I middle, I
last,
const Pred& pred)
7317 if (last - first <= 40)
7320 median3(first, middle, last, pred);
7325 size_t step = (last - first + 1) / 8;
7327 median3(first, first + step, first + 2 * step, pred);
7328 median3(middle - step, middle, middle + step, pred);
7329 median3(last - 2 * step, last - step, last, pred);
7330 median3(first + step, middle, last - step, pred);
7334 template <
typename I,
typename Pred>
void sort(I
begin, I
end,
const Pred& pred)
7337 while (end - begin > 32)
7340 I middle = begin + (end -
begin) / 2;
7341 median(begin, middle, end - 1, pred);
7345 partition(begin, middle, end, pred, &eqbeg, &eqend);
7348 if (eqbeg - begin > end - eqend)
7350 sort(eqend, end, pred);
7355 sort(begin, eqbeg, pred);
7367 static const size_t xpath_memory_page_size =
7368 #ifdef PUGIXML_MEMORY_XPATH_PAGE_SIZE
7369 PUGIXML_MEMORY_XPATH_PAGE_SIZE
7375 static const uintptr_t xpath_memory_block_alignment =
sizeof(double) >
sizeof(
void*) ?
sizeof(double) :
sizeof(
void*);
7384 char data[xpath_memory_page_size];
7395 #ifdef PUGIXML_NO_EXCEPTIONS
7401 #ifdef PUGIXML_NO_EXCEPTIONS
7409 size = (size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1);
7413 void*
buf = &_root->
data[0] + _root_size;
7420 size_t block_capacity_base =
sizeof(_root->
data);
7421 size_t block_capacity_req = size + block_capacity_base / 4;
7422 size_t block_capacity = (block_capacity_base > block_capacity_req) ? block_capacity_base : block_capacity_req;
7427 if (!block)
return 0;
7429 block->
next = _root;
7445 #ifdef PUGIXML_NO_EXCEPTIONS
7449 throw std::bad_alloc();
7459 old_size = (old_size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1);
7460 new_size = (new_size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1);
7463 assert(ptr == 0 || static_cast<char*>(ptr) + old_size == &_root->
data[0] + _root_size);
7466 bool only_object = (_root_size == old_size);
7468 if (ptr) _root_size -= old_size;
7475 if (result != ptr && ptr)
7478 assert(new_size >= old_size);
7479 memcpy(result, ptr, old_size);
7484 assert(_root->
data == result);
7485 assert(_root->
next);
7506 while (cur != state._root)
7516 _root = state._root;
7517 _root_size = state._root_size;
7564 #ifdef PUGIXML_NO_EXCEPTIONS
7576 #ifdef PUGIXML_NO_EXCEPTIONS
7593 const char_t* _buffer;
7595 size_t _length_heap;
7597 static char_t* duplicate_string(
const char_t*
string,
size_t length,
xpath_allocator* alloc)
7599 char_t* result =
static_cast<char_t*
>(alloc->
allocate((length + 1) *
sizeof(char_t)));
7602 memcpy(result,
string, length *
sizeof(char_t));
7608 xpath_string(
const char_t* buffer,
bool uses_heap_,
size_t length_heap): _buffer(buffer), _uses_heap(uses_heap_), _length_heap(length_heap)
7620 assert(begin <= end && *end == 0);
7622 return xpath_string(begin,
true, static_cast<size_t>(end - begin));
7627 assert(begin <= end);
7629 size_t length =
static_cast<size_t>(end -
begin);
7641 if (!*o._buffer)
return;
7644 if (!*_buffer && !_uses_heap && !o._uses_heap)
7646 _buffer = o._buffer;
7651 size_t target_length =
length();
7652 size_t source_length = o.
length();
7653 size_t result_length = target_length + source_length;
7656 char_t* result =
static_cast<char_t*
>(alloc->
reallocate(_uses_heap ? const_cast<char_t*>(_buffer) : 0, (target_length + 1) *
sizeof(char_t), (result_length + 1) *
sizeof(char_t)));
7660 if (!_uses_heap) memcpy(result, _buffer, target_length *
sizeof(char_t));
7663 memcpy(result + target_length, o._buffer, source_length *
sizeof(char_t));
7664 result[result_length] = 0;
7669 _length_heap = result_length;
7680 return _uses_heap ? _length_heap :
strlength(_buffer);
7690 _buffer = duplicate_string(_buffer, length_, alloc);
7692 _length_heap = length_;
7695 return const_cast<char_t*
>(_buffer);
7700 return *_buffer == 0;
7705 return strequal(_buffer, o._buffer);
7710 return !
strequal(_buffer, o._buffer);
7723 while (*pattern && *
string == *pattern)
7729 return *pattern == 0;
7734 #ifdef PUGIXML_WCHAR_MODE
7735 return wcschr(s, c);
7737 return strchr(s, c);
7743 #ifdef PUGIXML_WCHAR_MODE
7745 return (*p == 0) ? s : wcsstr(s, p);
7747 return strstr(s, p);
7754 return static_cast<unsigned int>(ch -
'A') < 26 ? static_cast<char_t>(ch |
' ') : ch;
7763 xml_node
n = na.node();
7782 xml_node cur = n.first_child();
7784 while (cur && cur != n)
7789 if (cur.first_child())
7790 cur = cur.first_child();
7791 else if (cur.next_sibling())
7792 cur = cur.next_sibling();
7795 while (!cur.next_sibling() && cur !=
n)
7798 if (cur != n) cur = cur.next_sibling();
7813 assert(ln->parent == rn->parent);
7816 if (!ln->parent)
return ln < rn;
7819 xml_node_struct* ls = ln;
7820 xml_node_struct* rs = rn;
7824 if (ls == rn)
return true;
7825 if (rs == ln)
return false;
7827 ls = ls->next_sibling;
7828 rs = rs->next_sibling;
7838 xml_node_struct* lp = ln;
7839 xml_node_struct* rp = rn;
7841 while (lp && rp && lp->parent != rp->parent)
7851 bool left_higher = !lp;
7866 if (ln == rn)
return left_higher;
7869 while (ln->parent != rn->parent)
7880 while (node && node != parent) node = node->parent;
7882 return parent && node == parent;
7887 xml_node_struct* node = xnode.node().internal_object();
7891 if ((
get_document(node).header & xml_memory_page_contents_shared_mask) == 0)
7893 if (node->name && (node->header & impl::xml_memory_page_name_allocated_or_shared_mask) == 0)
return node->name;
7894 if (node->value && (node->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0)
return node->value;
7900 xml_attribute_struct* attr = xnode.attribute().internal_object();
7904 if ((
get_document(attr).header & xml_memory_page_contents_shared_mask) == 0)
7906 if ((attr->header & impl::xml_memory_page_name_allocated_or_shared_mask) == 0)
return attr->name;
7907 if ((attr->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0)
return attr->value;
7918 bool operator()(
const xpath_node& lhs,
const xpath_node& rhs)
const
7924 if (lo && ro)
return lo < ro;
7927 xml_node ln = lhs.node(), rn = rhs.node();
7930 if (lhs.attribute() && rhs.attribute())
7933 if (lhs.parent() == rhs.parent())
7936 for (xml_attribute
a = lhs.attribute();
a;
a =
a.next_attribute())
7937 if (
a == rhs.attribute())
7947 else if (lhs.attribute())
7950 if (lhs.parent() == rhs.node())
return false;
7954 else if (rhs.attribute())
7957 if (rhs.parent() == lhs.node())
return true;
7962 if (ln == rn)
return false;
7964 if (!ln || !rn)
return ln < rn;
7966 return node_is_before(ln.internal_object(), rn.internal_object());
7972 bool operator()(
const xpath_node& lhs,
const xpath_node& rhs)
const
7974 if (lhs.attribute())
return rhs.attribute() ? lhs.attribute() < rhs.attribute() :
true;
7975 else return rhs.attribute() ?
false : lhs.node() < rhs.node();
7981 #if defined(__STDC_IEC_559__) || ((FLT_RADIX - 0 == 2) && (FLT_MAX_EXP - 0 == 128) && (FLT_MANT_DIG - 0 == 24))
7983 typedef uint32_t UI;
7984 union {
float f; UI i; } u;
7989 const volatile double zero = 0.0;
7996 #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__)
7997 return !!_isnan(value);
7998 #elif defined(fpclassify) && defined(FP_NAN)
7999 return fpclassify(value) == FP_NAN;
8002 const volatile double v =
value;
8009 #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__)
8010 if (_finite(value))
return (value == 0) ?
PUGIXML_TEXT(
"0") : 0;
8013 #elif defined(fpclassify) && defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO)
8014 switch (fpclassify(value))
8030 const volatile double v =
value;
8041 return (value != 0 && !
is_nan(value));
8046 while (begin != end && end[-1] ==
'0') end--;
8052 #if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE)
8057 _ecvt_s(buffer, buffer_size, value, DBL_DIG + 1, &exponent, &sign);
8064 *out_exponent = exponent;
8070 sprintf(buffer,
"%.*e", DBL_DIG, value);
8071 assert(strlen(buffer) < buffer_size);
8075 char* exponent_string = strchr(buffer,
'e');
8076 assert(exponent_string);
8078 int exponent = atoi(exponent_string + 1);
8081 char* mantissa = buffer[0] ==
'-' ? buffer + 1 :
buffer;
8082 assert(mantissa[0] !=
'0' && mantissa[1] ==
'.');
8085 mantissa[1] = mantissa[0];
8093 *out_mantissa = mantissa;
8094 *out_exponent = exponent;
8105 char mantissa_buffer[32];
8112 size_t result_size = strlen(mantissa_buffer) + (exponent > 0 ? exponent : -exponent) + 4;
8113 char_t* result =
static_cast<char_t*
>(alloc->
allocate(
sizeof(char_t) * result_size));
8120 if (value < 0) *s++ =
'-';
8129 while (exponent > 0)
8131 assert(*mantissa == 0 || static_cast<unsigned int>(static_cast<unsigned int>(*mantissa) -
'0') <= 9);
8132 *s++ = *mantissa ? *mantissa++ :
'0';
8144 while (exponent < 0)
8153 assert(static_cast<unsigned int>(*mantissa -
'0') <= 9);
8159 assert(s < result + result_size);
8171 if (*
string ==
'-') ++
string;
8173 if (!*
string)
return false;
8192 return *
string == 0;
8201 #ifdef PUGIXML_WCHAR_MODE
8202 return wcstod(
string, 0);
8204 return strtod(
string, 0);
8210 size_t length =
static_cast<size_t>(end -
begin);
8211 char_t* scratch =
buffer;
8213 if (length >=
sizeof(buffer) /
sizeof(buffer[0]))
8217 if (!scratch)
return false;
8221 memcpy(scratch, begin, length *
sizeof(char_t));
8234 return floor(value + 0.5);
8241 return (value >= -0.5 && value <= 0) ?
ceil(value) :
floor(value + 0.5);
8246 return node.attribute() ? node.attribute().name() : node.node().name();
8254 return p ? p + 1 :
name;
8264 const char_t* pos =
find_char(name,
':');
8272 const char_t*
name = a.name();
8288 xml_attribute
a = p.find_attribute(pred);
8290 if (a)
return a.value();
8305 xml_node p = parent;
8309 xml_attribute
a = p.find_attribute(pred);
8311 if (a)
return a.value();
8328 for (char_t* it = buffer; *it; )
8338 if (write != buffer) *write++ =
' ';
8360 const char_t* pos =
find_char(from, ch);
8364 else if (static_cast<size_t>(pos - from) < to_length)
8365 *write++ = to[pos - from];
8376 unsigned char table[128] = {0};
8380 unsigned int fc =
static_cast<unsigned int>(*from);
8381 unsigned int tc =
static_cast<unsigned int>(*to);
8383 if (fc >= 128 || tc >= 128)
8388 table[fc] =
static_cast<unsigned char>(tc ? tc : 128);
8394 for (
int i = 0; i < 128; ++i)
8396 table[i] =
static_cast<unsigned char>(i);
8402 memcpy(result, table,
sizeof(table));
8405 return static_cast<unsigned char*
>(
result);
8414 char_t ch = *buffer++;
8415 unsigned int index =
static_cast<unsigned int>(ch);
8419 unsigned char code = table[
index];
8423 *write =
static_cast<char_t
>(code);
8424 write += 1 - (code >> 7);
8488 static const xpath_node_set dummy_node_set;
8493 unsigned int result = 0;
8497 result +=
static_cast<unsigned int>(*str++);
8498 result += result << 10;
8499 result ^= result >> 6;
8502 result += result << 3;
8503 result ^= result >> 11;
8504 result += result << 15;
8512 if (length == 0)
return 0;
8516 if (!memory)
return 0;
8520 memcpy(result->name, name, (length + 1) *
sizeof(char_t));
8530 return new_xpath_variable<xpath_variable_node_set>(
name);
8533 return new_xpath_variable<xpath_variable_number>(
name);
8536 return new_xpath_variable<xpath_variable_string>(
name);
8539 return new_xpath_variable<xpath_variable_boolean>(
name);
8573 assert(
false &&
"Invalid variable type");
8579 switch (rhs->type())
8582 return lhs->set(static_cast<const xpath_variable_node_set*>(rhs)->value);
8585 return lhs->set(static_cast<const xpath_variable_number*>(rhs)->value);
8588 return lhs->set(static_cast<const xpath_variable_string*>(rhs)->value);
8591 return lhs->set(static_cast<const xpath_variable_boolean*>(rhs)->value);
8594 assert(
false &&
"Invalid variable type");
8601 size_t length =
static_cast<size_t>(end -
begin);
8602 char_t* scratch =
buffer;
8604 if (length >=
sizeof(buffer) /
sizeof(buffer[0]))
8608 if (!scratch)
return false;
8612 memcpy(scratch, begin, length *
sizeof(char_t));
8615 *out_result = set->get(scratch);
8628 if (end - begin < 2)
8629 return xpath_node_set::type_sorted;
8633 bool first =
cmp(begin[0], begin[1]);
8635 for (
const xpath_node* it = begin + 1; it + 1 <
end; ++it)
8636 if (
cmp(it[0], it[1]) != first)
8637 return xpath_node_set::type_unsorted;
8639 return first ? xpath_node_set::type_sorted : xpath_node_set::type_sorted_reverse;
8644 xpath_node_set::type_t
order = rev ? xpath_node_set::type_sorted_reverse : xpath_node_set::type_sorted;
8646 if (type == xpath_node_set::type_unsorted)
8650 if (sorted == xpath_node_set::type_unsorted)
8654 type = xpath_node_set::type_sorted;
8660 if (type != order)
reverse(begin, end);
8667 if (begin == end)
return xpath_node();
8671 case xpath_node_set::type_sorted:
8674 case xpath_node_set::type_sorted_reverse:
8677 case xpath_node_set::type_unsorted:
8681 assert(
false &&
"Invalid node set type");
8682 return xpath_node();
8688 xpath_node_set::type_t _type;
8711 return _begin == _end;
8716 return static_cast<size_t>(_end - _begin);
8736 if (begin_ == end_)
return;
8738 size_t size_ =
static_cast<size_t>(_end - _begin);
8739 size_t capacity =
static_cast<size_t>(_eos - _begin);
8740 size_t count =
static_cast<size_t>(end_ - begin_);
8742 if (size_ + count > capacity)
8745 xpath_node* data =
static_cast<xpath_node*
>(alloc->
reallocate(_begin, capacity *
sizeof(xpath_node), (size_ + count) *
sizeof(xpath_node)));
8750 _end = data + size_;
8751 _eos = data + size_ +
count;
8754 memcpy(_end, begin_, count *
sizeof(xpath_node));
8760 _type =
xpath_sort(_begin, _end, _type,
false);
8765 assert(_begin <= pos && pos <= _end);
8772 if (_type == xpath_node_set::type_unsorted)
8775 _end =
unique(_begin, _end);
8778 xpath_node_set::type_t
type()
const
8791 size_t capacity =
static_cast<size_t>(_eos - _begin);
8794 size_t new_capacity = capacity + capacity / 2 + 1;
8797 xpath_node* data =
static_cast<xpath_node*
>(alloc->
reallocate(_begin, capacity *
sizeof(xpath_node), new_capacity *
sizeof(xpath_node)));
8802 _end = data + capacity;
8803 _eos = data + new_capacity;
8863 size_t length =
static_cast<size_t>(
end -
begin);
8872 const char_t* _cur_lexeme_pos;
8890 const char_t* cur = _cur;
8895 _cur_lexeme_pos = cur;
8904 if (*(cur+1) ==
'=')
8917 if (*(cur+1) ==
'=')
8930 if (*(cur+1) ==
'=')
8976 _cur_lexeme_contents.
begin = cur;
8987 _cur_lexeme_contents.
end = cur;
9029 if (*(cur+1) ==
'/')
9042 if (*(cur+1) ==
'.')
9049 _cur_lexeme_contents.
begin = cur;
9055 _cur_lexeme_contents.
end = cur;
9075 char_t terminator = *cur;
9079 _cur_lexeme_contents.
begin = cur;
9080 while (*cur && *cur != terminator) cur++;
9081 _cur_lexeme_contents.
end = cur;
9095 if (*(cur+1) ==
':')
9109 _cur_lexeme_contents.
begin = cur;
9120 _cur_lexeme_contents.
end = cur;
9126 _cur_lexeme_contents.
begin = cur;
9144 _cur_lexeme_contents.
end = cur;
9164 return _cur_lexeme_pos;
9171 return _cur_lexeme_contents;
9344 return comp(ls, rs);
9354 for (
const xpath_node* li = ls.
begin(); li != ls.
end(); ++li)
9355 for (
const xpath_node* ri = rs.
begin(); ri != rs.
end(); ++ri)
9382 for (
const xpath_node* ri = rs.
begin(); ri != rs.
end(); ++ri)
9399 for (
const xpath_node* ri = rs.
begin(); ri != rs.
end(); ++ri)
9411 assert(
false &&
"Wrong types");
9433 for (
const xpath_node* li = ls.
begin(); li != ls.
end(); ++li)
9439 for (
const xpath_node* ri = rs.
begin(); ri != rs.
end(); ++ri)
9457 for (
const xpath_node* ri = rs.
begin(); ri != rs.
end(); ++ri)
9474 for (
const xpath_node* li = ls.
begin(); li != ls.
end(); ++li)
9486 assert(
false &&
"Wrong types");
9502 for (xpath_node* it = last; it != ns.
end(); ++it, ++i)
9528 for (xpath_node* it = last; it != ns.
end(); ++it, ++i)
9556 if (er >= 1.0 && er <= size)
9558 size_t eri =
static_cast<size_t>(er);
9562 xpath_node r = last[eri - 1];
9578 apply_predicate_number_const(ns, first, _right, stack);
9580 apply_predicate_number(ns, first, _right, stack, once);
9582 apply_predicate_boolean(ns, first, _right, stack, once);
9589 bool last_once = eval_once(ns.
type(),
eval);
9592 pred->apply_predicate(ns, first, stack, !pred->_next && last_once);
9606 ns.
push_back(xpath_node(xml_attribute(a), xml_node(parent)), alloc);
9615 ns.
push_back(xpath_node(xml_attribute(a), xml_node(parent)), alloc);
9623 ns.
push_back(xpath_node(xml_attribute(a), xml_node(parent)), alloc);
9704 assert(
false &&
"Unknown axis");
9712 const axis_t axis = T::axis;
9718 for (xml_attribute_struct* a = n->first_attribute; a; a = a->next_attribute)
9719 if (step_push(ns, a, n, alloc) & once)
9727 for (xml_node_struct* c = n->first_child; c; c = c->next_sibling)
9728 if (step_push(ns, c, alloc) & once)
9738 if (step_push(ns, n, alloc) & once)
9741 xml_node_struct* cur = n->first_child;
9745 if (step_push(ns, cur, alloc) & once)
9748 if (cur->first_child)
9749 cur = cur->first_child;
9752 while (!cur->next_sibling)
9756 if (cur == n)
return;
9759 cur = cur->next_sibling;
9768 for (xml_node_struct* c = n->next_sibling; c; c = c->next_sibling)
9769 if (step_push(ns, c, alloc) & once)
9777 for (xml_node_struct* c = n->prev_sibling_c; c->next_sibling; c = c->prev_sibling_c)
9778 if (step_push(ns, c, alloc) & once)
9786 xml_node_struct* cur =
n;
9789 while (!cur->next_sibling)
9796 cur = cur->next_sibling;
9800 if (step_push(ns, cur, alloc) & once)
9803 if (cur->first_child)
9804 cur = cur->first_child;
9807 while (!cur->next_sibling)
9814 cur = cur->next_sibling;
9823 xml_node_struct* cur =
n;
9826 while (!cur->prev_sibling_c->next_sibling)
9833 cur = cur->prev_sibling_c;
9837 if (cur->first_child)
9838 cur = cur->first_child->prev_sibling_c;
9842 if (step_push(ns, cur, alloc) & once)
9845 while (!cur->prev_sibling_c->next_sibling)
9852 if (step_push(ns, cur, alloc) & once)
9856 cur = cur->prev_sibling_c;
9867 if (step_push(ns, n, alloc) & once)
9870 xml_node_struct* cur = n->parent;
9874 if (step_push(ns, cur, alloc) & once)
9885 step_push(ns, n, alloc);
9893 step_push(ns, n->parent, alloc);
9899 assert(
false &&
"Unimplemented axis");
9905 const axis_t axis = T::axis;
9913 if (step_push(ns, a, p, alloc) & once)
9916 xml_node_struct* cur = p;
9920 if (step_push(ns, cur, alloc) & once)
9933 step_push(ns, a, p, alloc);
9940 xml_node_struct* cur = p;
9944 if (cur->first_child)
9945 cur = cur->first_child;
9948 while (!cur->next_sibling)
9955 cur = cur->next_sibling;
9958 if (step_push(ns, cur, alloc) & once)
9967 step_push(ns, p, alloc);
9975 step_fill(ns, p, alloc, once, v);
9980 assert(
false &&
"Unimplemented axis");
9986 const axis_t axis = T::axis;
9990 step_fill(ns, xn.node().internal_object(), alloc, once,
v);
9991 else if (axis_has_attributes && xn.attribute() && xn.parent())
9992 step_fill(ns, xn.attribute().internal_object(), xn.parent().internal_object(), alloc, once,
v);
9997 const axis_t axis = T::axis;
9999 const xpath_node_set::type_t axis_type = axis_reverse ? xpath_node_set::type_sorted_reverse : xpath_node_set::type_sorted;
10003 (!_right && eval_once(axis_type, eval)) ||
10016 for (
const xpath_node* it = s.
begin(); it != s.
end(); ++it)
10018 size_t size = ns.
size();
10021 if (axis !=
axis_self && size != 0) ns.
set_type(xpath_node_set::type_unsorted);
10023 step_fill(ns, *it, stack.
result, once, v);
10024 if (_right) apply_predicates(ns, size, stack, eval);
10029 step_fill(ns, c.
n, stack.
result, once, v);
10030 if (_right) apply_predicates(ns, 0, stack, eval);
10043 _type(static_cast<char>(type)), _rettype(static_cast<char>(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0)
10046 _data.string =
value;
10050 _type(static_cast<char>(type)), _rettype(static_cast<char>(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0)
10053 _data.number =
value;
10057 _type(static_cast<char>(type)), _rettype(static_cast<char>(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0)
10060 _data.variable =
value;
10064 _type(static_cast<char>(type)), _rettype(static_cast<char>(rettype_)), _axis(0), _test(0), _left(
left), _right(
right), _next(0)
10069 _type(static_cast<char>(type)), _rettype(
xpath_type_node_set), _axis(static_cast<char>(axis)), _test(static_cast<char>(test)), _left(left), _right(0), _next(0)
10072 _data.nodetest = contents;
10076 _type(static_cast<char>(type)), _rettype(
xpath_type_node_set), _axis(0), _test(static_cast<char>(test)), _left(left), _right(right), _next(0)
10102 return compare_eq(_left, _right, c, stack,
equal_to());
10105 return compare_eq(_left, _right, c, stack,
not_equal_to());
10108 return compare_rel(_left, _right, c, stack,
less());
10111 return compare_rel(_right, _left, c, stack,
less());
10114 return compare_rel(_left, _right, c, stack,
less_equal());
10117 return compare_rel(_right, _left, c, stack,
less_equal());
10153 if (c.
n.attribute())
return false;
10159 for (xml_node n = c.
n.node();
n; n = n.parent())
10161 xml_attribute a = n.attribute(
PUGIXML_TEXT(
"xml:lang"));
10165 const char_t* value = a.value();
10168 for (
const char_t* lit = lang.
c_str(); *lit; ++lit)
10174 return *value == 0 || *value ==
'-';
10185 xml_attribute attr = c.
n.node().attribute(_left->_data.
nodetest);
10192 assert(_rettype == _data.variable->type());
10195 return _data.variable->get_boolean();
10222 assert(
false &&
"Wrong expression for return type boolean");
10252 return _data.number;
10255 return static_cast<double>(c.
size);
10258 return static_cast<double>(c.
position);
10299 for (
const xpath_node* it = ns.
begin(); it != ns.
end(); ++it)
10313 return r == r ?
floor(r) :
r;
10320 return r == r ?
ceil(r) :
r;
10328 assert(_rettype == _data.variable->type());
10331 return _data.variable->get_number();
10358 assert(
false &&
"Wrong expression for return type number");
10381 if (count >
sizeof(static_buffer) /
sizeof(static_buffer[0]))
10390 buffer[0] = _left->
eval_string(c, swapped_stack);
10393 for (
xpath_ast_node* n = _right;
n; n = n->_next, ++pos) buffer[pos] = n->eval_string(c, swapped_stack);
10394 assert(pos == count);
10398 for (
size_t i = 0; i <
count; ++i) length += buffer[i].
length();
10401 char_t* result =
static_cast<char_t*
>(stack.
result->
allocate((length + 1) *
sizeof(char_t)));
10406 for (
size_t j = 0;
j <
count; ++
j)
10407 for (
const char_t* bi = buffer[
j].c_str(); *bi; ++bi)
10424 xpath_node na = c.
n;
10434 xpath_node na = ns.
first();
10441 xpath_node na = c.
n;
10451 xpath_node na = ns.
first();
10458 xpath_node na = c.
n;
10468 xpath_node na = ns.
first();
10508 const char_t* rbegin = pos + p.
length();
10521 size_t s_length = s.
length();
10526 else if (first >= s_length + 1)
return xpath_string();
10529 assert(1 <= pos && pos <= s_length + 1);
10531 const char_t* rbegin = s.
c_str() + (pos - 1);
10544 size_t s_length = s.
length();
10550 else if (first >= s_length + 1)
return xpath_string();
10555 size_t end = last >= s_length + 1 ? s_length + 1 :
static_cast<size_t>(
last);
10557 assert(1 <= pos && pos <= end && end <= s_length + 1);
10558 const char_t* rbegin = s.
c_str() + (pos - 1);
10559 const char_t* rend = s.
c_str() + (end - 1);
10612 assert(_rettype == _data.variable->type());
10641 assert(
false &&
"Wrong expression for return type string");
10662 rs.
set_type(xpath_node_set::type_unsorted);
10677 bool once = eval_once(set.
type(),
eval);
10679 apply_predicate(set, 0, stack, once);
10732 assert(
false &&
"Unknown axis");
10743 ns.
set_type(xpath_node_set::type_sorted);
10753 assert(_rettype == _data.variable->type());
10757 const xpath_node_set& s = _data.variable->get_node_set();
10771 assert(
false &&
"Wrong expression for return type node set");
10797 _right = _right->_right;
10826 _left = _left->_left;
10837 _data.table =
table;
10875 if (!n->is_posinv_expr())
return false;
10914 #ifdef PUGIXML_NO_EXCEPTIONS
10915 jmp_buf _error_handler;
10923 #ifdef PUGIXML_NO_EXCEPTIONS
10924 longjmp(_error_handler, 1);
10926 throw xpath_exception(*
_result);
10932 #ifdef PUGIXML_NO_EXCEPTIONS
10935 throw std::bad_alloc();
10952 size_t length =
static_cast<size_t>(value.
end - value.
begin);
10958 memcpy(c, value.
begin, length *
sizeof(char_t));
10971 throw_error(
"Function has to be applied to node set");
10978 switch (name.
begin[0])
10990 throw_error(
"Function has to be applied to node set");
10994 else if (name ==
PUGIXML_TEXT(
"contains") && argc == 2)
10998 else if (name ==
PUGIXML_TEXT(
"ceiling") && argc == 1)
11022 else if (name ==
PUGIXML_TEXT(
"local-name") && argc <= 1)
11030 else if (name ==
PUGIXML_TEXT(
"namespace-uri") && argc <= 1)
11032 else if (name ==
PUGIXML_TEXT(
"normalize-space") && argc <= 1)
11056 else if (name ==
PUGIXML_TEXT(
"string-length") && argc <= 1)
11058 else if (name ==
PUGIXML_TEXT(
"starts-with") && argc == 2)
11060 else if (name ==
PUGIXML_TEXT(
"substring-before") && argc == 2)
11062 else if (name ==
PUGIXML_TEXT(
"substring-after") && argc == 2)
11064 else if (name ==
PUGIXML_TEXT(
"substring") && (argc == 2 || argc == 3))
11086 throw_error(
"Unrecognized function or wrong parameter count");
11095 switch (name.
begin[0])
11161 switch (name.
begin[0])
11204 throw_error(
"Unknown variable: variable set is not provided");
11206 xpath_variable* var = 0;
11211 throw_error(
"Unknown variable: variable set does not contain the given name");
11275 throw_error(
"No comma between function arguments");
11280 if (argc < 2) args[argc] =
n;
11293 throw_error(
"Unrecognizable primary expression");
11313 throw_error(
"Predicate has to be applied to node set");
11334 throw_error(
"Step has to be applied to node set");
11336 bool axis_specified =
false;
11342 axis_specified =
true;
11372 if (axis_specified)
11377 if (!axis_specified)
11415 else if (nt_name ==
PUGIXML_TEXT(
"processing-instruction"))
11418 throw_error(
"Only literals are allowed as arguments to processing-instruction()");
11425 throw_error(
"Unmatched brace near processing-instruction()");
11430 throw_error(
"Unmatched brace near node type test");
11436 if (nt_name.
end - nt_name.
begin > 2 && nt_name.
end[-2] ==
':' && nt_name.
end[-1] ==
'*')
11579 throw_error(
"Step has to be applied to node set");
11691 throw_error(
"Union operator has to be applied to node sets");
11743 #ifdef PUGIXML_NO_EXCEPTIONS
11744 int error = setjmp(parser._error_handler);
11746 return (error == 0) ? parser.
parse() : 0;
11748 return parser.
parse();
11758 if (!memory)
return 0;
11787 #ifdef PUGIXML_NO_EXCEPTIONS
11798 if (!impl)
return 0;
11802 #ifdef PUGIXML_NO_EXCEPTIONS
11805 xpath_parse_result res;
11806 res.error =
"Expression does not evaluate to node set";
11808 throw xpath_exception(res);
11818 #ifndef PUGIXML_NO_EXCEPTIONS
11821 assert(_result.
error);
11826 return _result.
error;
11849 return _attribute ?
xml_node() : _node;
11859 return _attribute ? _node : _node.
parent();
11866 PUGI__FN xpath_node::operator xpath_node::unspecified_bool_type()
const
11868 return (_node || _attribute) ? unspecified_bool_xpath_node : 0;
11873 return !(_node || _attribute);
11878 return _node == n._node && _attribute == n._attribute;
11883 return _node != n._node || _attribute != n._attribute;
11886 #ifdef __BORLANDC__
11889 return (
bool)lhs && rhs;
11894 return (
bool)lhs || rhs;
11898 PUGI__FN void xpath_node_set::_assign(const_iterator begin_, const_iterator end_, type_t type_)
11900 assert(begin_ <= end_);
11902 size_t size_ =
static_cast<size_t>(end_ - begin_);
11907 if (_begin != &_storage) impl::xml_memory::deallocate(_begin);
11910 if (begin_ != end_) _storage = *begin_;
11912 _begin = &_storage;
11913 _end = &_storage + size_;
11919 xpath_node*
storage =
static_cast<xpath_node*
>(impl::xml_memory::allocate(size_ *
sizeof(xpath_node)));
11923 #ifdef PUGIXML_NO_EXCEPTIONS
11926 throw std::bad_alloc();
11930 memcpy(storage, begin_, size_ *
sizeof(xpath_node));
11933 if (_begin != &_storage) impl::xml_memory::deallocate(_begin);
11937 _end = storage + size_;
11942 #ifdef PUGIXML_HAS_MOVE
11943 PUGI__FN void xpath_node_set::_move(xpath_node_set& rhs)
11946 _storage = rhs._storage;
11947 _begin = (rhs._begin == &rhs._storage) ? &_storage : rhs._begin;
11948 _end = _begin + (rhs._end - rhs._begin);
11951 rhs._begin = &rhs._storage;
11952 rhs._end = rhs._begin;
11962 _assign(begin_, end_, type_);
11967 if (_begin != &_storage)
11968 impl::xml_memory::deallocate(_begin);
11973 _assign(ns._begin, ns._end, ns._type);
11978 if (
this == &ns)
return *
this;
11980 _assign(ns._begin, ns._end, ns._type);
11985 #ifdef PUGIXML_HAS_MOVE
11993 if (
this == &rhs)
return *
this;
11995 if (_begin != &_storage)
11996 impl::xml_memory::deallocate(_begin);
12011 return _end - _begin;
12016 return _begin == _end;
12021 assert(index <
size());
12022 return _begin[index];
12068 return static_cast<const impl::xpath_variable_node_set*
>(
this)->name;
12071 return static_cast<const impl::xpath_variable_number*
>(
this)->name;
12074 return static_cast<const impl::xpath_variable_string*
>(
this)->name;
12077 return static_cast<const impl::xpath_variable_boolean*
>(
this)->name;
12080 assert(
false &&
"Invalid variable type");
12092 return (
_type ==
xpath_type_boolean) ?
static_cast<const impl::xpath_variable_boolean*
>(
this)->value :
false;
12102 const char_t* value = (
_type ==
xpath_type_string) ? static_cast<const impl::xpath_variable_string*>(
this)->value : 0;
12108 return (
_type ==
xpath_type_node_set) ?
static_cast<const impl::xpath_variable_node_set*
>(
this)->value : impl::dummy_node_set;
12115 static_cast<impl::xpath_variable_boolean*
>(
this)->value = value;
12123 static_cast<impl::xpath_variable_number*
>(
this)->value = value;
12131 impl::xpath_variable_string* var =
static_cast<impl::xpath_variable_string*
>(
this);
12136 char_t*
copy =
static_cast<char_t*
>(impl::xml_memory::allocate(size));
12137 if (!copy)
return false;
12139 memcpy(copy, value, size);
12142 if (var->value) impl::xml_memory::deallocate(var->value);
12152 static_cast<impl::xpath_variable_node_set*
>(
this)->value = value;
12158 for (
size_t i = 0; i <
sizeof(_data) /
sizeof(_data[0]); ++i)
12164 for (
size_t i = 0; i <
sizeof(_data) /
sizeof(_data[0]); ++i)
12165 _destroy(_data[i]);
12170 for (
size_t i = 0; i <
sizeof(_data) /
sizeof(_data[0]); ++i)
12178 if (
this == &rhs)
return *
this;
12185 #ifdef PUGIXML_HAS_MOVE
12188 for (
size_t i = 0; i <
sizeof(_data) /
sizeof(_data[0]); ++i)
12190 _data[i] = rhs._data[i];
12197 for (
size_t i = 0; i <
sizeof(_data) /
sizeof(_data[0]); ++i)
12199 _destroy(_data[i]);
12201 _data[i] = rhs._data[i];
12209 PUGI__FN void xpath_variable_set::_assign(
const xpath_variable_set& rhs)
12213 for (
size_t i = 0; i <
sizeof(_data) /
sizeof(_data[0]); ++i)
12214 if (rhs._data[i] && !_clone(rhs._data[i], &temp._data[i]))
12220 PUGI__FN void xpath_variable_set::_swap(xpath_variable_set& rhs)
12222 for (
size_t i = 0; i <
sizeof(_data) /
sizeof(_data[0]); ++i)
12224 xpath_variable* chain = _data[i];
12226 _data[i] = rhs._data[i];
12227 rhs._data[i] = chain;
12231 PUGI__FN xpath_variable* xpath_variable_set::_find(
const char_t* name)
const
12233 const size_t hash_size =
sizeof(_data) /
sizeof(_data[0]);
12237 for (xpath_variable* var = _data[hash]; var; var = var->_next)
12244 PUGI__FN bool xpath_variable_set::_clone(xpath_variable* var, xpath_variable** out_result)
12246 xpath_variable* last = 0;
12252 if (!nvar)
return false;
12256 last->_next = nvar;
12258 *out_result = nvar;
12271 PUGI__FN void xpath_variable_set::_destroy(xpath_variable* var)
12275 xpath_variable* next = var->_next;
12285 const size_t hash_size =
sizeof(_data) /
sizeof(_data[0]);
12291 return var->type() == type ? var : 0;
12298 result->
_next = _data[hash];
12309 return var ? var->
set(value) :
false;
12315 return var ? var->
set(value) :
false;
12321 return var ? var->
set(value) :
false;
12327 return var ? var->
set(value) :
false;
12332 return _find(name);
12337 return _find(name);
12342 impl::xpath_query_impl* qimpl = impl::xpath_query_impl::create();
12346 #ifdef PUGIXML_NO_EXCEPTIONS
12347 _result.
error =
"Out of memory";
12349 throw std::bad_alloc();
12354 using impl::auto_deleter;
12357 qimpl->root = impl::xpath_parser::parse(query, variables, &qimpl->alloc, &_result);
12361 qimpl->root->optimize(&qimpl->alloc);
12376 impl::xpath_query_impl::destroy(static_cast<impl::xpath_query_impl*>(_impl));
12379 #ifdef PUGIXML_HAS_MOVE
12383 _result = rhs._result;
12388 PUGI__FN xpath_query& xpath_query::operator=(xpath_query&& rhs)
12390 if (
this == &rhs)
return *
this;
12393 impl::xpath_query_impl::destroy(static_cast<impl::xpath_query_impl*>(_impl));
12396 _result = rhs._result;
12398 rhs._result = xpath_parse_result();
12408 return static_cast<impl::xpath_query_impl*
>(_impl)->root->rettype();
12413 if (!_impl)
return false;
12415 impl::xpath_context
c(n, 1, 1);
12416 impl::xpath_stack_data sd;
12418 #ifdef PUGIXML_NO_EXCEPTIONS
12419 if (setjmp(sd.error_handler))
return false;
12422 return static_cast<impl::xpath_query_impl*
>(_impl)->root->eval_boolean(c, sd.stack);
12429 impl::xpath_context
c(n, 1, 1);
12430 impl::xpath_stack_data sd;
12432 #ifdef PUGIXML_NO_EXCEPTIONS
12436 return static_cast<impl::xpath_query_impl*
>(_impl)->root->eval_number(c, sd.stack);
12439 #ifndef PUGIXML_NO_STL
12442 impl::xpath_stack_data sd;
12446 return string_t(r.c_str(), r.length());
12452 impl::xpath_stack_data sd;
12456 size_t full_size = r.length() + 1;
12460 size_t size = (full_size < capacity) ? full_size : capacity;
12463 memcpy(buffer, r.c_str(), (size - 1) *
sizeof(char_t));
12464 buffer[size - 1] = 0;
12475 impl::xpath_context
c(n, 1, 1);
12476 impl::xpath_stack_data sd;
12478 #ifdef PUGIXML_NO_EXCEPTIONS
12492 impl::xpath_context
c(n, 1, 1);
12493 impl::xpath_stack_data sd;
12495 #ifdef PUGIXML_NO_EXCEPTIONS
12496 if (setjmp(sd.error_handler))
return xpath_node();
12513 PUGI__FN xpath_query::operator xpath_query::unspecified_bool_type()
const
12515 return _impl ? unspecified_bool_xpath_query : 0;
12559 #ifdef __BORLANDC__
12560 # pragma option pop
12565 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
12566 # pragma warning(pop)
12570 #undef PUGI__NO_INLINE
12571 #undef PUGI__UNLIKELY
12572 #undef PUGI__STATIC_ASSERT
12573 #undef PUGI__DMC_VOLATILE
12574 #undef PUGI__MSVC_CRT_VERSION
12575 #undef PUGI__NS_BEGIN
12576 #undef PUGI__NS_END
12578 #undef PUGI__FN_NO_INLINE
12579 #undef PUGI__GETHEADER_IMPL
12580 #undef PUGI__GETPAGE_IMPL
12581 #undef PUGI__GETPAGE
12582 #undef PUGI__NODETYPE
12583 #undef PUGI__IS_CHARTYPE_IMPL
12584 #undef PUGI__IS_CHARTYPE
12585 #undef PUGI__IS_CHARTYPEX
12586 #undef PUGI__ENDSWITH
12587 #undef PUGI__SKIPWS
12588 #undef PUGI__OPTSET
12589 #undef PUGI__PUSHNODE
12590 #undef PUGI__POPNODE
12591 #undef PUGI__SCANFOR
12592 #undef PUGI__SCANWHILE
12593 #undef PUGI__SCANWHILE_UNROLL
12594 #undef PUGI__ENDSEG
12595 #undef PUGI__THROW_ERROR
12596 #undef PUGI__CHECK_ERROR
GLsizei GLenum GLsizei GLsizei GLuint memory
virtual bool for_each(xml_node &node)=0
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
xpath_ast_node * parse_expression()
virtual bool begin(xml_node &node)
bool operator>=(const xml_node &r) const
#define PUGI__NODETYPE(n)
xml_attribute prepend_attribute(const char_t *name)
int as_int(int def=0) const
void throw_error(const char *message)
xpath_variable * get(const char_t *name)
PUGI__FN bool strcpy_insitu(String &dest, Header &header, uintptr_t header_mask, const char_t *source, size_t source_length)
#define PUGI__GETHEADER_IMPL(object, page, flags)
char data[xpath_memory_page_size]
xml_memory_page * allocate_page(size_t data_size)
GLuint GLsizei const GLchar * message
PUGI__FN strconv_pcdata_t get_strconv_pcdata(unsigned int optmask)
float as_float(float def=0) const
xpath_allocator_capture(xpath_allocator *alloc)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
PUGI__FN void text_output_cdata(xml_buffered_writer &writer, const char_t *s)
xpath_node_set_raw eval_node_set(const xpath_context &c, const xpath_stack &stack, nodeset_eval_t eval)
xml_node_iterator iterator
static value_type high(value_type result, uint32_t)
GLenum GLuint GLenum GLsizei const GLchar * buf
bool operator()(const T &lhs, const T &rhs) const
xpath_string eval_string(const xpath_context &c, const xpath_stack &stack)
SYS_API double fmod(double x, double y)
PUGI__FN xml_encoding get_buffer_encoding(xml_encoding encoding, const void *contents, size_t size)
#define PUGI__FN_NO_INLINE
cvex test(vector P=0;int unbound=3;export float s=0;export vector Cf=0;)
xml_attribute append_attribute(const char_t *name)
xml_parse_result make_parse_result(xml_parse_status status, ptrdiff_t offset=0)
wchar_selector< sizeof(wchar_t)>::writer wchar_writer
xml_node last_child() const
static void destroy(xml_stream_chunk *chunk)
GLenum GLuint GLsizei bufsize
bool operator==(const xml_attribute &r) const
void append(const xpath_string &o, xpath_allocator *alloc)
PUGI__FN void node_copy_string(String &dest, Header &header, uintptr_t header_mask, char_t *source, Header &source_header, xml_allocator *alloc)
#define PUGI__SCANCHAR(ch)
OCIOEXPORT ConstColorSpaceSetRcPtr operator&&(const ConstColorSpaceSetRcPtr &lcss, const ConstColorSpaceSetRcPtr &rcss)
Perform the intersection of two sets.
xml_node prepend_child(xml_node_type type=node_element)
static xpath_string from_heap_preallocated(const char_t *begin, const char_t *end)
PUGI__FN const char_t * namespace_uri(xml_node node)
void write_string(const char_t *data)
void insert_node_after(xml_node_struct *child, xml_node_struct *node)
~xpath_allocator_capture()
char_t data_char[bufcapacity]
PUGI__FN size_t get_valid_length(const char_t *data, size_t length)
static value_type low(value_type result, uint32_t ch)
PUGI__FN int get_value_int(const char_t *value)
PUGI__FN bool save_file_impl(const xml_document &doc, FILE *file, const char_t *indent, unsigned int flags, xml_encoding encoding)
bool set_name(const char_t *rhs)
PUGI__FN void text_output_escaped(xml_buffered_writer &writer, const char_t *s, chartypex_t type)
PUGI__FN bool is_nan(double value)
static xml_memory_page * construct(void *memory)
static binary_op_t parse(xpath_lexer &lexer)
bool is_text_node(xml_node_struct *node)
friend class xml_named_node_iterator
void write_direct(const char_t *data, size_t length)
char_t * data(xpath_allocator *alloc)
void deallocate_memory(void *ptr, size_t size, xml_memory_page *page)
xpath_node_set::type_t type() const
PUGI__FN char_t * normalize_space(char_t *buffer)
void append_attribute(xml_attribute_struct *attr, xml_node_struct *node)
char_t * parse_doctype_group(char_t *s, char_t endch)
PUGI__FN allocation_function PUGIXML_FUNCTION get_memory_allocation_function()
utf16_decoder< opt_false > decoder
xpath_value_type type() const
PUGI__FN const char_t * local_name(const xpath_node &node)
void deallocate_string(char_t *string)
bool operator==(const xml_node_iterator &rhs) const
void partition(I begin, I middle, I end, const Pred &pred, I *out_eqbeg, I *out_eqend)
void * allocate(size_t size)
xpath_variable_set & operator=(const xpath_variable_set &rhs)
void remove_attribute(xml_attribute_struct *attr, xml_node_struct *node)
void * allocate_memory_oob(size_t size, xml_memory_page *&out_page)
PUGI__FN void node_output_pi_value(xml_buffered_writer &writer, const char_t *s)
uint32_t data_u32[bufcapacity]
bool operator==(const xpath_string &o) const
IMATH_HOSTDEVICE constexpr int floor(T x) IMATH_NOEXCEPT
T negative(const T &val)
Return the unary negation of the given value.
getFileOption("OpenEXR:storage") storage
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
PUGI__NS_END PUGI__NS_BEGIN uint16_t endian_swap(uint16_t value)
#define PUGI__ENDSWITH(c, e)
virtual const char * what() const PUGIXML_OVERRIDE
bool set_value(const char_t *rhs)
UT_StringArray JOINTS head
xml_node append_move(const xml_node &moved)
float as_float(float def=0) const
static char_t * parse_wconv(char_t *s, char_t end_quote)
bool set(const char_t *rhs)
GLsizei const GLchar *const * string
bool is_posinv_step() const
GLsizei const GLfloat * value
static void deallocate_page(xml_memory_page *page)
xpath_parse_result * _result
const xpath_node & operator[](size_t index) const
size_t hash_value() const
PUGI__FN xml_parse_status get_file_size(FILE *file, size_t &out_result)
double get_number() const
PUGI__FN bool has_declaration(xml_node_struct *node)
xpath_variable_node_set()
xpath_memory_block * next
GLsizei const GLchar *const * path
xpath_ast_node(ast_type_t type, xpath_ast_node *left, xpath_ast_node *right, predicate_t test)
void copy_backwards(I begin, I end, I target)
const char_t * as_string(const char_t *def=PUGIXML_TEXT("")) const
xml_attribute_struct(impl::xml_memory_page *page)
xpath_value_type rettype() const
bool operator==(const xml_named_node_iterator &rhs) const
static value_type high(value_type result, uint32_t ch)
bool traverse(xml_tree_walker &walker)
void revert(const xpath_allocator &state)
const xml_named_node_iterator & operator--()
xml_parse_result load_file(const char *path, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
const char_t * child_value() const
namespace_uri_predicate(const char_t *name)
PUGI__FN char_t * strconv_comment(char_t *s, char_t endch)
bool operator()(const T &lhs, const T &rhs) const
PUGI__FN void text_output_indent(xml_buffered_writer &writer, const char_t *indent, size_t indent_length, unsigned int depth)
xml_node * operator->() const
GLboolean GLboolean GLboolean GLboolean a
xml_node first_child() const
void reverse(I begin, I end)
void swap(T &lhs, T &rhs)
const_iterator end() const
GLuint GLsizei GLsizei * length
PUGI__FN std::string as_utf8_impl(const wchar_t *str, size_t length)
static xpath_string from_const(const char_t *str)
PUGI__FN const void * document_buffer_order(const xpath_node &xnode)
fallback_uintptr uintptr_t
static value_type any(value_type result, uint32_t ch)
xml_attribute prepend_copy(const xml_attribute &proto)
PUGI__FN bool node_is_ancestor(xml_node_struct *parent, xml_node_struct *node)
PUGI__FN bool get_variable_scratch(char_t(&buffer)[32], xpath_variable_set *set, const char_t *begin, const char_t *end, xpath_variable **out_result)
xml_attribute last_attribute() const
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)
PUGI__FN bool check_string_to_number_format(const char_t *string)
virtual ~xml_tree_walker()
xml_document_struct(xml_memory_page *page)
char_t *(* strconv_attribute_t)(char_t *, char_t)
void insert_attribute_before(xml_attribute_struct *attr, xml_attribute_struct *place, xml_node_struct *node)
xml_attribute next_attribute() const
bool evaluate_boolean(const xpath_node &n) const
const char_t * value() const
bool operator!=(const xml_attribute &r) const
xml_node_type type() const
xpath_context(const xpath_node &n_, size_t position_, size_t size_)
union xml_buffered_writer::@221 scratch
**But if you need a result
xpath_variable_set * _variables
bool operator==(const xml_node &r) const
PUGI__FN size_t strlength_wide(const wchar_t *s)
xml_memory_management_function_storage< int > xml_memory
GLdouble GLdouble GLdouble q
xml_parse_result append_buffer(const void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN xpath_node_set::type_t xpath_get_order(const xpath_node *begin, const xpath_node *end)
#define PUGI__STATIC_ASSERT(cond)
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
bool operator<=(const xml_attribute &r) const
#define PUGI__SCANWHILE(X)
double evaluate_number(const xpath_node &n) const
xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_variable *value)
bool set_value(const char_t *rhs)
xpath_ast_node(ast_type_t type, xpath_ast_node *left, axis_t axis, nodetest_t test, const char_t *contents)
static value_type high(value_type result, uint32_t)
xml_attribute_struct * first_attribute
char_t * allocate_string(size_t length)
char_t * flush(char_t *s)
xml_node previous_sibling() const
PUGI__FN bool is_little_endian()
xpath_lexer(const char_t *query)
xml_attribute & operator=(const char_t *rhs)
bool operator>(const xml_node &r) const
static char_t * parse_skip_bom(char_t *s)
PUGI__FN double round_nearest_nzero(double value)
void flush(const char_t *data, size_t size)
PUGI__FN char * convert_path_heap(const wchar_t *str)
bool as_bool(bool def=false) const
void truncate(xpath_node *pos)
const char_t * alloc_string(const xpath_lexer_string &value)
PUGI__FN xpath_string string_value(const xpath_node &na, xpath_allocator *alloc)
void destroy_attribute(xml_attribute_struct *a, xml_allocator &alloc)
bool as_bool(bool def=false) const
PUGI__FN unsigned int hash_string(const char_t *str)
bool remove_attribute(const xml_attribute &a)
bool operator<=(const xml_node &r) const
const xml_node_iterator & operator--()
xml_attribute insert_copy_before(const xml_attribute &proto, const xml_attribute &attr)
PUGI__FN xpath_node_set::type_t xpath_sort(xpath_node *begin, xpath_node *end, xpath_node_set::type_t type, bool rev)
IMATH_HOSTDEVICE constexpr int cmp(T a, T b) IMATH_NOEXCEPT
xpath_ast_node * parse_step(xpath_ast_node *set)
void push(char_t *&s, size_t count)
xml_node insert_move_before(const xml_node &moved, const xml_node &node)
axis_t parse_axis_name(const xpath_lexer_string &name, bool &specified)
void append_node(xml_node_struct *child, xml_node_struct *node)
PUGI__FN bool node_is_before(xml_node_struct *ln, xml_node_struct *rn)
static Traits::value_type process(const wchar_t *data, size_t size, typename Traits::value_type result, Traits traits)
void write(char_t d0, char_t d1, char_t d2, char_t d3, char_t d4)
PUGI__FN xml_encoding guess_buffer_encoding(const uint8_t *data, size_t size)
xpath_node_set select_nodes(const char_t *query, xpath_variable_set *variables=0) const
PUGI__FN deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function()
static value_type high(value_type result, uint32_t)
xpath_ast_node * parse_filter_expression()
T data[xml_memory_page_size/sizeof(T)]
uint8_t data_u8[4 *bufcapacity]
virtual bool end(xml_node &node)
bool operator!=(const xml_named_node_iterator &rhs) const
xml_node find_child_by_attribute(const char_t *name, const char_t *attr_name, const char_t *attr_value) const
utf32_decoder< opt_false > decoder
xml_parse_status error_status
char_t * parse_exclamation(char_t *s, xml_node_struct *cursor, unsigned int optmsk, char_t endch)
PUGI__FN bool set_value_ascii(String &dest, Header &header, uintptr_t header_mask, char *buf)
xml_attribute append_copy(const xml_attribute &proto)
void set_next(xpath_ast_node *value)
#define PUGI__OPTSET(OPT)
bool operator!=(const xml_node_iterator &rhs) const
const xml_named_node_iterator & operator++()
nodetest_t parse_node_test_type(const xpath_lexer_string &name)
xpath_ast_node * parse_location_path()
xml_attribute_struct * prev_attribute_c
OCIOEXPORT ConstColorSpaceSetRcPtr operator||(const ConstColorSpaceSetRcPtr &lcss, const ConstColorSpaceSetRcPtr &rcss)
Perform the union of two sets.
bool is_xpath_attribute(const char_t *name)
PUGI__FN bool parse_declaration_encoding(const uint8_t *data, size_t size, const uint8_t *&out_encoding, size_t &out_length)
PUGI__NS_END PUGI__NS_BEGIN xml_attribute_struct * allocate_attribute(xml_allocator &alloc)
xml_node insert_move_after(const xml_node &moved, const xml_node &node)
xml_parse_result load_buffer(const void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
bool is_posinv_expr() const
PUGI__FN char_t * strconv_escape(char_t *s, gap &g)
bool any(const vbool4 &v)
PUGI__FN char_t tolower_ascii(char_t ch)
xml_node_struct * next_sibling
void write(char_t d0, char_t d1, char_t d2)
PUGI__FN xml_parse_result load_file_impl(xml_document_struct *doc, FILE *file, unsigned int options, xml_encoding encoding, char_t **out_buffer)
xml_attribute attribute(const char_t *name) const
xml_document_struct & get_document(const Object *object)
static value_type any(value_type result, uint32_t ch)
bool strcpy_insitu_allow(size_t length, const Header &header, uintptr_t header_mask, char_t *target)
static Traits::value_type process(const uint32_t *data, size_t size, typename Traits::value_type result, Traits)
xml_attribute & operator*() const
PUGI__FN FILE * open_file_wide(const wchar_t *path, const wchar_t *mode)
PUGI__FN void as_utf8_end(char *buffer, size_t size, const wchar_t *str, size_t length)
xml_node & operator*() const
xml_node append_child(xml_node_type type=node_element)
void * allocate_nothrow(size_t size)
xml_attribute first_attribute() const
OIIO_UTIL_API FILE * fopen(string_view path, string_view mode)
Version of fopen that can handle UTF-8 paths even on Windows.
wchar_selector< sizeof(wchar_t)>::counter wchar_counter
bool operator!=(const xpath_string &o) const
xpath_ast_node(ast_type_t type, xpath_value_type rettype_, double value)
static char_t * parse_simple(char_t *s, char_t end_quote)
PUGI__FN xpath_string convert_number_to_string(double value, xpath_allocator *alloc)
#define PUGI__PUSHNODE(TYPE)
const char_t * get_string() const
#define PUGI__THROW_ERROR(err, m)
#define PUGI__UNLIKELY(cond)
PUGI__FN bool convert_string_to_number_scratch(char_t(&buffer)[32], const char_t *begin, const char_t *end, double *out_result)
xml_parse_result load(std::basic_istream< char, std::char_traits< char > > &stream, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
static Traits::value_type process(const uint16_t *data, size_t size, typename Traits::value_type result, Traits)
xml_node_struct(impl::xml_memory_page *page, xml_node_type type)
I min_element(I begin, I end, const Pred &pred)
xml_object_range< xml_node_iterator > children() const
xpath_variable * add(const char_t *name, xpath_value_type type)
PUGI__FN bool convert_buffer_generic(char_t *&out_buffer, size_t &out_length, const void *contents, size_t size, D)
PUGI__FN unsigned char * translate_table_generate(xpath_allocator *alloc, const char_t *from, const char_t *to)
GLsizei GLsizei GLchar * source
void write(char_t d0, char_t d1, char_t d2, char_t d3, char_t d4, char_t d5)
PUGI__FN std::string PUGIXML_FUNCTION as_utf8(const wchar_t *str)
xml_attribute insert_attribute_after(const char_t *name, const xml_attribute &attr)
PUGI__FN const char_t * find_char(const char_t *s, char_t c)
bool operator()(const xpath_node &lhs, const xpath_node &rhs) const
void median3(I first, I middle, I last, const Pred &pred)
const char_t * as_string(const char_t *def=PUGIXML_TEXT("")) const
const xpath_parse_result & result() const
static value_type low(value_type result, uint32_t ch)
xml_extra_buffer * extra_buffers
void sort(bool reverse=false)
xml_node next_sibling() const
PUGI__FN bool node_output_start(xml_buffered_writer &writer, xml_node_struct *node, const char_t *indent, size_t indent_length, unsigned int flags, unsigned int depth)
xpath_node_set evaluate_node_set(const xpath_node &n) const
static xpath_string from_heap(const char_t *begin, const char_t *end, xpath_allocator *alloc)
xpath_allocator(xpath_memory_block *root, size_t root_size=0)
bool operator>=(const xml_attribute &r) const
double as_double(double def=0) const
xml_node_struct * prev_sibling_c
void set_right(xpath_ast_node *value)
xpath_variable * variable
xpath_node_set & operator=(const xpath_node_set &ns)
GLdouble GLdouble GLint GLint order
#define PUGI__SCANWHILE_UNROLL(X)
PUGI__FN bool is_attribute_of(xml_attribute_struct *attr, xml_node_struct *node)
static value_type any(value_type result, uint32_t ch)
static value_type low(value_type result, uint32_t)
xml_node * operator->() const
PUGI__FN std::basic_string< wchar_t > PUGIXML_FUNCTION as_wide(const char *str)
bool operator!=(const xml_attribute_iterator &rhs) const
PUGI__FN void delete_xpath_variable(T *var)
xml_node & operator*() const
void destroy_node(xml_node_struct *n, xml_allocator &alloc)
void remove_node(xml_node_struct *node)
xml_parse_result load_buffer_inplace(void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
PUGI__FN xpath_node xpath_first(const xpath_node *begin, const xpath_node *end, xpath_node_set::type_t type)
HUSD_API bool eval(VtValue &val, T &ret_val)
xml_node_struct * first_child
xml_attribute insert_attribute_before(const char_t *name, const xml_attribute &attr)
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN bool starts_with(const char_t *string, const char_t *pattern)
xml_attribute_struct * internal_object() const
void push_back_grow(const xpath_node &node, xpath_allocator *alloc)
PUGI__FN_NO_INLINE xml_node_struct * append_new_node(xml_node_struct *node, xml_allocator &alloc, xml_node_type type=node_element)
PUGI__FN size_t convert_buffer_output(char_t *, uint8_t *r_u8, uint16_t *r_u16, uint32_t *r_u32, const char_t *data, size_t length, xml_encoding encoding)
xml_node document_element() const
GLuint const GLchar * name
IMATH_HOSTDEVICE constexpr int sign(T a) IMATH_NOEXCEPT
static value_type high(value_type result, uint32_t ch)
string_t path(char_t delimiter= '/') const
PUGI__FN void close_file(FILE *file)
const char_t * state() const
uint16_t data_u16[2 *bufcapacity]
PUGI__FN const char_t * convert_number_to_string_special(double value)
xpath_string eval_string_concat(const xpath_context &c, const xpath_stack &stack)
bool operator()(const xpath_node &lhs, const xpath_node &rhs) const
void insert_attribute_after(xml_attribute_struct *attr, xml_attribute_struct *place, xml_node_struct *node)
xml_named_node_iterator()
void * reallocate(void *ptr, size_t old_size, size_t new_size)
xml_allocator(xml_memory_page *root)
string_t evaluate_string(const xpath_node &n) const
GLenum GLenum GLsizei void * table
PUGI__FN void convert_number_to_mantissa_exponent(double value, char *buffer, size_t buffer_size, char **out_mantissa, int *out_exponent)
PUGI__FN xml_encoding get_wchar_encoding()
unsigned int as_uint(unsigned int def=0) const
const char_t * name() const
auto_deleter(T *data_, D deleter_)
xpath_node evaluate_node(const xpath_node &n) const
const TypeMask operator&(const TypeMask &m1, const TypeMask &m2)
xml_node prepend_move(const xml_node &moved)
void * allocate_object(size_t size, xml_memory_page *&out_page)
PUGI__FN void truncate_zeros(char *begin, char *end)
char_t *(* strconv_pcdata_t)(char_t *)
PUGI__FN void text_output(xml_buffered_writer &writer, const char_t *s, chartypex_t type, unsigned int flags)
xml_node insert_child_before(xml_node_type type, const xml_node &node)
char_t * parse_doctype_ignore(char_t *s)
const xml_node_iterator & operator++()
GLint GLint GLsizei GLsizei GLsizei depth
PUGI__FN void node_output(xml_buffered_writer &writer, xml_node_struct *root, const char_t *indent, unsigned int flags, unsigned int depth)
static void destroy(xpath_query_impl *impl)
xml_parse_result load_string(const char_t *contents, unsigned int options=parse_default)
static xml_parse_result parse(char_t *buffer, size_t length, xml_document_struct *xmldoc, xml_node_struct *root, unsigned int optmsk)
auto reserve(std::back_insert_iterator< Container > it, size_t n) -> checked_ptr< typename Container::value_type >
const char_t * c_str() const
bool operator!=(const xml_node &r) const
void prepend_node(xml_node_struct *child, xml_node_struct *node)
PUGI__FN T * new_xpath_variable(const char_t *name)
PUGI__FN void node_output_comment(xml_buffered_writer &writer, const char_t *s)
const xpath_node_set & get_node_set() const
void(* unspecified_bool_type)(xml_node ***)
__hostdev__ uint64_t last(uint32_t i) const
#define PUGI__SCANCHARTYPE(ct)
static Traits::value_type process(const uint8_t *data, size_t size, typename Traits::value_type result, Traits)
const char_t * get() const
PUGI__FN xml_parse_result load_buffer_impl(xml_document_struct *doc, xml_node_struct *root, void *contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own, char_t **out_buffer)
OrtDmlDeviceFilter & operator&=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)
void write(char_t d0, char_t d1)
PUGI__FN size_t get_latin1_7bit_prefix_length(const uint8_t *data, size_t size)
GLfloat GLfloat GLfloat GLfloat h
xpath_ast_node * parse_function(const xpath_lexer_string &name, size_t argc, xpath_ast_node *args[2])
IMATH_HOSTDEVICE constexpr int ceil(T x) IMATH_NOEXCEPT
OIIO_UTIL_API int fseek(FILE *file, int64_t offset, int whence)
Version of fseek that works with 64 bit offsets on all systems.
PUGI__FN bool convert_number_to_boolean(double value)
attribute_iterator attributes_begin() const
int as_int(int def=0) const
unsigned int as_uint(unsigned int def=0) const
static allocation_function allocate
PUGI__FN bool get_value_bool(const char_t *value)
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN size_t strlength(const char_t *s)
bool operator>(const xml_attribute &r) const
binary_op_t(ast_type_t asttype_, xpath_value_type rettype_, int precedence_)
bool operator!=(const xpath_node &n) const
bool operator==(const xpath_node &n) const
const xpath_lexer_string & contents() const
static char_t * parse_eol(char_t *s, char_t end_quote)
void print(xml_writer &writer, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto, unsigned int depth=0) const
xml_attribute_iterator attribute_iterator
PUGI__FN double convert_string_to_number(const char_t *string)
PUGI__FN size_t as_utf8_begin(const wchar_t *str, size_t length)
PUGI__FN bool node_is_before_sibling(xml_node_struct *ln, xml_node_struct *rn)
const_iterator begin() const
xpath_ast_node * parse_path_or_unary_expression()
void set_type(xpath_node_set::type_t value)
xml_node child(const char_t *name) const
#define PUGI__IS_CHARTYPEX(c, ct)
PUGIXML_DEPRECATED xpath_node select_single_node(const char_t *query, xpath_variable_set *variables=0) const
static value_type low(value_type result, uint32_t)
xml_attribute * operator->() const
attribute_iterator attributes_end() const
bool operator<(const xml_attribute &r) const
PUGI__FN void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate)
bool operator()(xml_attribute a) const
U string_to_integer(const char_t *value, U minneg, U maxpos)
bool operator<(const xml_node &r) const
void optimize(xpath_allocator *alloc)
PUGI__FN void node_output_attributes(xml_buffered_writer &writer, xml_node_struct *node, const char_t *indent, size_t indent_length, unsigned int flags, unsigned int depth)
PUGI__FN char_t * translate_table(char_t *buffer, const unsigned char *table)
bool operator()(const T &lhs, const T &rhs) const
xpath_variable(xpath_value_type type)
virtual void write(const void *data, size_t size) PUGIXML_OVERRIDE
PUGI__FN xml_parse_status load_stream_data_seek(std::basic_istream< T > &stream, void **out_buffer, size_t *out_size)
xml_node insert_child_after(xml_node_type type, const xml_node &node)
PUGI__FN std::basic_string< wchar_t > as_wide_impl(const char *str, size_t size)
PUGI__FN bool get_mutable_buffer(char_t *&out_buffer, size_t &out_length, const void *contents, size_t size, bool is_mutable)
PUGI__FN size_t zero_terminate_buffer(void *buffer, size_t size, xml_encoding encoding)
PUGI__FN bool set_value_integer(String &dest, Header &header, uintptr_t header_mask, U value, bool negative)
LeafData & operator=(const LeafData &)=delete
PUGI__FN const char_t * qualified_name(const xpath_node &node)
static deallocation_function deallocate
PUGI__FN bool allow_move(xml_node parent, xml_node child)
void * allocate_memory(size_t size, xml_memory_page *&out_page)
static bool has_element_node_siblings(xml_node_struct *node)
void append(const xpath_node *begin_, const xpath_node *end_, xpath_allocator *alloc)
PUGI__NS_BEGIN PUGI__FN void * default_allocate(size_t size)
xml_object_range< xml_attribute_iterator > attributes() const
PUGI__FN float get_value_float(const char_t *value)
xml_writer_file(void *file)
xml_attribute insert_copy_after(const xml_attribute &proto, const xml_attribute &attr)
xpath_ast_node * parse_expression_rec(xpath_ast_node *lhs, int limit)
xpath_ast_node * parse_relative_location_path(xpath_ast_node *set)
void write_buffer(const char_t *data, size_t length)
void optimize_self(xpath_allocator *alloc)
OIIO_UTIL_API int64_t ftell(FILE *file)
Version of ftell that works with 64 bit offsets on all systems.
PUGI__FN unsigned int get_value_uint(const char_t *value)
const char_t * name() const
char_t * parse_tree(char_t *s, xml_node_struct *root, unsigned int optmsk, char_t endch)
xpath_value_type return_type() const
void insertion_sort(I begin, I end, const Pred &pred, T *)
xpath_memory_block blocks[2]
#define PUGI__CHECK_ERROR(err, m)
char_t * parse_doctype_primitive(char_t *s)
GA_API const UT_StringHolder N
xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_ast_node *left=0, xpath_ast_node *right=0)
const char_t * current_pos() const
xml_node_struct * internal_object() const
xml_buffered_writer(xml_writer &writer_, xml_encoding user_encoding)
PUGI__FN xml_parse_status load_stream_data_noseek(std::basic_istream< T > &stream, void **out_buffer, size_t *out_size)
PUGI__FN bool convert_buffer_latin1(char_t *&out_buffer, size_t &out_length, const void *contents, size_t size, bool is_mutable)
const char_t * value() const
**If you just want to fire and args
#define PUGI__DMC_VOLATILE
PUGI__FN bool allow_insert_attribute(xml_node_type parent)
PUGI__FN void node_copy_attribute(xml_attribute_struct *da, xml_attribute_struct *sa)
#define PUGI__IS_CHARTYPE(c, ct)
xml_parse_result load_buffer_inplace_own(void *contents, size_t size, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
xpath_allocator * _target
static xpath_ast_node * parse(const char_t *query, xpath_variable_set *variables, xpath_allocator *alloc, xpath_parse_result *result)
PUGI__FN const char_t * find_substring(const char_t *s, const char_t *p)
static value_type high(value_type result, uint32_t ch)
PUGI__FN size_t convert_buffer_output_generic(typename T::value_type dest, const char_t *data, size_t length, D, T)
PUGI__FN bool copy_xpath_variable(xpath_variable *lhs, const xpath_variable *rhs)
xml_allocator * allocator
static value_type low(value_type result, uint32_t ch)
PUGI__FN void node_output_simple(xml_buffered_writer &writer, xml_node_struct *node, unsigned int flags)
double eval_number(const xpath_context &c, const xpath_stack &stack)
PUGI__FN char_t * strconv_cdata(char_t *s, char_t endch)
xml_node first_element_by_path(const char_t *path, char_t delimiter= '/') const
xml_attribute attribute() const
name_null_sentry(xml_node_struct *node_)
PUGI__FN char_t * integer_to_string(char_t *begin, char_t *end, U value, bool negative)
void insert_node_before(xml_node_struct *child, xml_node_struct *node)
PUGI__FN void node_output_end(xml_buffered_writer &writer, xml_node_struct *node)
PUGI__FN impl::xpath_ast_node * evaluate_node_set_prepare(xpath_query_impl *impl)
bool save_file(const char *path, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto) const
PUGI__FN bool strequal(const char_t *src, const char_t *dst)
static char_t * parse(char_t *s)
bool operator==(const char_t *other) const
const unsigned char * table
static xpath_query_impl * create()
static value_type high(value_type result, uint32_t ch)
PUGI__FN xpath_string evaluate_string_impl(xpath_query_impl *impl, const xpath_node &n, xpath_stack_data &sd)
size_t hash_value() const
PUGI__FN double gen_nan()
PUGI__FN bool allow_insert_child(xml_node_type parent, xml_node_type child)
xpath_ast_node * parse_primary_expression()
PUGI__FN bool strequalrange(const char_t *lhs, const char_t *rhs, size_t count)
char_t * parse_question(char_t *s, xml_node_struct *&ref_cursor, unsigned int optmsk, char_t endch)
PUGI__FN strconv_attribute_t get_strconv_attribute(unsigned int optmask)
void write(char_t d0, char_t d1, char_t d2, char_t d3)
#define OIIO_NAMESPACE_END
PUGI__FN char_t * translate(char_t *buffer, const char_t *from, const char_t *to, size_t to_length)
auto sprintf(const S &fmt, const T &...args) -> std::basic_string< Char >
void prepend_attribute(xml_attribute_struct *attr, xml_node_struct *node)
xml_text & operator=(const char_t *rhs)
static value_type low(value_type result, uint32_t ch)
PUGI__FN xml_encoding get_write_native_encoding()
xpath_node * begin() const
xml_attribute_struct * next_attribute
bool set(const char_t *name, bool value)
ptrdiff_t offset_debug() const
bool operator()(const T &lhs, const T &rhs) const
PUGI__FN bool set_value_bool(String &dest, Header &header, uintptr_t header_mask, bool value)
static xml_stream_chunk * create()
xml_allocator & get_allocator(const Object *object)
ImageBuf OIIO_API zero(ROI roi, int nthreads=0)
bool operator==(const xml_attribute_iterator &rhs) const
static Traits::value_type process(const uint8_t *data, size_t size, typename Traits::value_type result, Traits)
GA_API const UT_StringHolder rest
bool remove_child(const xml_node &n)
const xml_attribute_iterator & operator--()
PUGI__FN double round_nearest(double value)
void median(I first, I middle, I last, const Pred &pred)
static char_t * parse_wnorm(char_t *s, char_t end_quote)
xml_node_struct * allocate_node(xml_allocator &alloc, xml_node_type type)
void sort(I begin, I end, const Pred &pred)
PUGI__FN void node_copy_tree(xml_node_struct *dn, xml_node_struct *sn)
const xml_attribute_iterator & operator++()
xml_parser(xml_allocator *alloc_)
PUGI__FN xml_encoding get_write_encoding(xml_encoding encoding)
double as_double(double def=0) const
xpath_parser(const char_t *query, xpath_variable_set *variables, xpath_allocator *alloc, xpath_parse_result *result)
void push_back(const xpath_node &node, xpath_allocator *alloc)
xpath_node select_node(const char_t *query, xpath_variable_set *variables=0) const
bool set_name(const char_t *rhs)
const char * description() const
static value_type low(value_type result, uint32_t ch)
const char_t * name() const
OrtDmlDeviceFilter & operator|=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)
void save(xml_writer &writer, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto) const
PUGI__FN xml_parse_result load_stream_impl(xml_document_struct *doc, std::basic_istream< T > &stream, unsigned int options, xml_encoding encoding, char_t **out_buffer)
PUGI__FN bool set_value_convert(String &dest, Header &header, uintptr_t header_mask, float value)
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
const char * description() const
xml_attribute previous_attribute() const
const xpath_parse_result & result() const
PUGI__FN double get_value_double(const char_t *value)
bool eval_boolean(const xpath_context &c, const xpath_stack &stack)
#define OIIO_NAMESPACE_BEGIN
PUGI__FN void node_copy_contents(xml_node_struct *dn, xml_node_struct *sn, xml_allocator *shared_alloc)
xpath_exception(const xpath_parse_result &result)
xpath_ast_node * parse_function_helper(ast_type_t type0, ast_type_t type1, size_t argc, xpath_ast_node *args[2])
virtual void write(const void *data, size_t size) PUGIXML_OVERRIDE
PUGI__FN_NO_INLINE xml_attribute_struct * append_new_attribute(xml_node_struct *node, xml_allocator &alloc)
xml_writer_stream(std::basic_ostream< char, std::char_traits< char > > &stream)
PUGI__FN void default_deallocate(void *ptr)
xpath_ast_node(ast_type_t type, xpath_value_type rettype_, const char_t *value)
#define PUGI__GETPAGE_IMPL(header)
double OIIO_UTIL_API strtod(const char *nptr, char **endptr=nullptr) noexcept
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.