)
INCLUDE_DIRECTORIES(
+ ${TEF_SIMULATOR_ROOT_PATH}
${TEE_STUB_PATH}
${TEF_SIMULATOR_INCLUDE_PATH}/include
${OSAL_PATH}
* Include files\r
*-----------------------------------------------------------------------------*/\r
#include <PropertyAccess/TAProperty.h>\r
-#include <PropertyAccess/rapidxml/rapidxml.hpp>\r
#include <PropertyAccess/PropertyUtility.h>\r
+#include <rapidxml/rapidxml.hpp>\r
#include <sstream>\r
#include <fstream>\r
#include <iostream>\r
#include <PropertyAccess/TEEProperty.h>\r
#include <sstream>\r
#include <fstream>\r
-#include <PropertyAccess/rapidxml/rapidxml.hpp>\r
+#include <rapidxml/rapidxml.hpp>\r
#include <iostream>\r
#include <config.h>\r
#include "log.h"\r
+++ /dev/null
-#ifndef RAPIDXML_HPP_INCLUDED\r
-#define RAPIDXML_HPP_INCLUDED\r
-\r
-// Copyright (C) 2006, 2009 Marcin Kalicinski\r
-// Version 1.13\r
-// Revision $DateTime: 2009/05/13 01:46:17 $\r
-//! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation\r
-\r
-// If standard library is disabled, user must provide implementations of required functions and typedefs\r
-#if !defined(RAPIDXML_NO_STDLIB)\r
-#include <cstdlib> // For std::size_t\r
-#include <cassert> // For assert\r
-#include <new> // For placement new\r
-#endif\r
-\r
-// On MSVC, disable "conditional expression is constant" warning (level 4). \r
-// This warning is almost impossible to avoid with certain types of templated code\r
-#ifdef _MSC_VER\r
-#pragma warning(push)\r
-#pragma warning(disable:4127) // Conditional expression is constant\r
-#endif\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// RAPIDXML_PARSE_ERROR\r
-\r
-#if defined(RAPIDXML_NO_EXCEPTIONS)\r
-\r
-#define RAPIDXML_PARSE_ERROR(what, where) { parse_error_handler(what, where); assert(0); }\r
-\r
-namespace rapidxml\r
-{\r
- //! When exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, \r
- //! this function is called to notify user about the error.\r
- //! It must be defined by the user.\r
- //! <br><br>\r
- //! This function cannot return. If it does, the results are undefined.\r
- //! <br><br>\r
- //! A very simple definition might look like that:\r
- //! <pre>\r
- //! void %rapidxml::%parse_error_handler(const char *what, void *where)\r
- //! {\r
- //! LOGE(TEE_STUB, "Parse error: %s", what);\r
- //! std::abort();\r
- //! }\r
- //! </pre>\r
- //! \param what Human readable description of the error.\r
- //! \param where Pointer to character data where error was detected.\r
- void parse_error_handler(const char *what, void *where);\r
-}\r
-\r
-#else\r
-\r
-#include <exception> // For std::exception\r
-\r
-#define RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where)\r
-\r
-namespace rapidxml {\r
-\r
-//! Parse error exception. \r
-//! This exception is thrown by the parser when an error occurs. \r
-//! Use what() function to get human-readable error message. \r
-//! Use where() function to get a pointer to position within source text where error was detected.\r
-//! <br><br>\r
-//! If throwing exceptions by the parser is undesirable, \r
-//! it can be disabled by defining RAPIDXML_NO_EXCEPTIONS macro before rapidxml.hpp is included.\r
-//! This will cause the parser to call rapidxml::parse_error_handler() function instead of throwing an exception.\r
-//! This function must be defined by the user.\r
-//! <br><br>\r
-//! This class derives from <code>std::exception</code> class.\r
-class parse_error:\r
- public std::exception {\r
-\r
-public:\r
-\r
- //! Constructs parse error\r
- parse_error(const char *what, void *where) :\r
- m_what(what), m_where(where) {\r
- }\r
-\r
- //! Gets human readable description of error.\r
- //! \return Pointer to null terminated description of the error.\r
- virtual const char *what() const throw () {\r
- return m_what;\r
- }\r
-\r
- //! Gets pointer to character data where error happened.\r
- //! Ch should be the same as char type of xml_document that produced the error.\r
- //! \return Pointer to location within the parsed string where error occured.\r
- template<class Ch>\r
- Ch *where() const {\r
- return reinterpret_cast<Ch *>(m_where);\r
- }\r
-\r
-private:\r
-\r
- const char *m_what;\r
- void *m_where;\r
-\r
-};\r
-}\r
-\r
-#endif\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// Pool sizes\r
-\r
-#ifndef RAPIDXML_STATIC_POOL_SIZE\r
-// Size of static memory block of memory_pool.\r
-// Define RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.\r
-// No dynamic memory allocations are performed by memory_pool until static memory is exhausted.\r
-#define RAPIDXML_STATIC_POOL_SIZE (64 * 1024)\r
-#endif\r
-\r
-#ifndef RAPIDXML_DYNAMIC_POOL_SIZE\r
-// Size of dynamic memory block of memory_pool.\r
-// Define RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.\r
-// After the static block is exhausted, dynamic blocks with approximately this size are allocated by memory_pool.\r
-#define RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024)\r
-#endif\r
-\r
-#ifndef RAPIDXML_ALIGNMENT\r
-// Memory allocation alignment.\r
-// Define RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer.\r
-// All memory allocations for nodes, attributes and strings will be aligned to this value.\r
-// This must be a power of 2 and at least 1, otherwise memory_pool will not work.\r
-#define RAPIDXML_ALIGNMENT sizeof(void *)\r
-#endif\r
-\r
-namespace rapidxml {\r
-// Forward declarations\r
-template<class Ch> class xml_node;\r
-template<class Ch> class xml_attribute;\r
-template<class Ch> class xml_document;\r
-\r
-//! Enumeration listing all node types produced by the parser.\r
-//! Use xml_node::type() function to query node type.\r
-enum node_type {\r
- node_document, //!< A document node. Name and value are empty.\r
- node_element, //!< An element node. Name contains element name. Value contains text of first data node.\r
- node_data, //!< A data node. Name is empty. Value contains data text.\r
- node_cdata, //!< A CDATA node. Name is empty. Value contains data text.\r
- node_comment, //!< A comment node. Name is empty. Value contains comment text.\r
- node_declaration, //!< A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes.\r
- node_doctype, //!< A DOCTYPE node. Name is empty. Value contains DOCTYPE text.\r
- node_pi //!< A PI node. Name contains target. Value contains instructions.\r
-};\r
-\r
-///////////////////////////////////////////////////////////////////////\r
-// Parsing flags\r
-\r
-//! Parse flag instructing the parser to not create data nodes. \r
-//! Text of first data node will still be placed in value of parent element, unless rapidxml::parse_no_element_values flag is also specified.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_no_data_nodes = 0x1;\r
-\r
-//! Parse flag instructing the parser to not use text of first data node as a value of parent element.\r
-//! Can be combined with other flags by use of | operator.\r
-//! Note that child data nodes of element node take precendence over its value when printing. \r
-//! That is, if element has one or more child data nodes <em>and</em> a value, the value will be ignored.\r
-//! Use rapidxml::parse_no_data_nodes flag to prevent creation of data nodes if you want to manipulate data using values of elements.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_no_element_values = 0x2;\r
-\r
-//! Parse flag instructing the parser to not place zero terminators after strings in the source text.\r
-//! By default zero terminators are placed, modifying source text.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_no_string_terminators = 0x4;\r
-\r
-//! Parse flag instructing the parser to not translate entities in the source text.\r
-//! By default entities are translated, modifying source text.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_no_entity_translation = 0x8;\r
-\r
-//! Parse flag instructing the parser to disable UTF-8 handling and assume plain 8 bit characters.\r
-//! By default, UTF-8 handling is enabled.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_no_utf8 = 0x10;\r
-\r
-//! Parse flag instructing the parser to create XML declaration node.\r
-//! By default, declaration node is not created.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_declaration_node = 0x20;\r
-\r
-//! Parse flag instructing the parser to create comments nodes.\r
-//! By default, comment nodes are not created.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_comment_nodes = 0x40;\r
-\r
-//! Parse flag instructing the parser to create DOCTYPE node.\r
-//! By default, doctype node is not created.\r
-//! Although W3C specification allows at most one DOCTYPE node, RapidXml will silently accept documents with more than one.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_doctype_node = 0x80;\r
-\r
-//! Parse flag instructing the parser to create PI nodes.\r
-//! By default, PI nodes are not created.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_pi_nodes = 0x100;\r
-\r
-//! Parse flag instructing the parser to validate closing tag names. \r
-//! If not set, name inside closing tag is irrelevant to the parser.\r
-//! By default, closing tags are not validated.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_validate_closing_tags = 0x200;\r
-\r
-//! Parse flag instructing the parser to trim all leading and trailing whitespace of data nodes.\r
-//! By default, whitespace is not trimmed. \r
-//! This flag does not cause the parser to modify source text.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_trim_whitespace = 0x400;\r
-\r
-//! Parse flag instructing the parser to condense all whitespace runs of data nodes to a single space character.\r
-//! Trimming of leading and trailing whitespace of data is controlled by rapidxml::parse_trim_whitespace flag.\r
-//! By default, whitespace is not normalized. \r
-//! If this flag is specified, source text will be modified.\r
-//! Can be combined with other flags by use of | operator.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_normalize_whitespace = 0x800;\r
-\r
-// Compound flags\r
-\r
-//! Parse flags which represent default behaviour of the parser. \r
-//! This is always equal to 0, so that all other flags can be simply ored together.\r
-//! Normally there is no need to inconveniently disable flags by anding with their negated (~) values.\r
-//! This also means that meaning of each flag is a <i>negation</i> of the default setting. \r
-//! For example, if flag name is rapidxml::parse_no_utf8, it means that utf-8 is <i>enabled</i> by default,\r
-//! and using the flag will disable it.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_default = 0;\r
-\r
-//! A combination of parse flags that forbids any modifications of the source text. \r
-//! This also results in faster parsing. However, note that the following will occur:\r
-//! <ul>\r
-//! <li>names and values of nodes will not be zero terminated, you have to use xml_base::name_size() and xml_base::value_size() functions to determine where name and value ends</li>\r
-//! <li>entities will not be translated</li>\r
-//! <li>whitespace will not be normalized</li>\r
-//! </ul>\r
-//! See xml_document::parse() function.\r
-const int parse_non_destructive = parse_no_string_terminators\r
- | parse_no_entity_translation;\r
-\r
-//! A combination of parse flags resulting in fastest possible parsing, without sacrificing important data.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_fastest = parse_non_destructive | parse_no_data_nodes;\r
-\r
-//! A combination of parse flags resulting in largest amount of data being extracted. \r
-//! This usually results in slowest parsing.\r
-//! <br><br>\r
-//! See xml_document::parse() function.\r
-const int parse_full = parse_declaration_node | parse_comment_nodes\r
- | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags;\r
-\r
-///////////////////////////////////////////////////////////////////////\r
-// Internals\r
-\r
-//! \cond internal\r
-namespace internal {\r
-\r
-// Struct that contains lookup tables for the parser\r
-// It must be a template to allow correct linking (because it has static data members, which are defined in a header file).\r
-template<int Dummy>\r
-struct lookup_tables {\r
- static const unsigned char lookup_whitespace[256]; // Whitespace table\r
- static const unsigned char lookup_node_name[256]; // Node name table\r
- static const unsigned char lookup_text[256]; // Text table\r
- static const unsigned char lookup_text_pure_no_ws[256]; // Text table\r
- static const unsigned char lookup_text_pure_with_ws[256]; // Text table\r
- static const unsigned char lookup_attribute_name[256]; // Attribute name table\r
- static const unsigned char lookup_attribute_data_1[256]; // Attribute data table with single quote\r
- static const unsigned char lookup_attribute_data_1_pure[256]; // Attribute data table with single quote\r
- static const unsigned char lookup_attribute_data_2[256]; // Attribute data table with double quotes\r
- static const unsigned char lookup_attribute_data_2_pure[256]; // Attribute data table with double quotes\r
- static const unsigned char lookup_digits[256]; // Digits\r
- static const unsigned char lookup_upcase[256]; // To uppercase conversion table for ASCII characters\r
-};\r
-\r
-// Find length of the string\r
-template<class Ch>\r
-inline std::size_t measure(const Ch *p) {\r
- const Ch *tmp = p;\r
- while (*tmp)\r
- ++tmp;\r
- return tmp - p;\r
-}\r
-\r
-// Compare strings for equality\r
-template<class Ch>\r
-inline bool compare(const Ch *p1, std::size_t size1, const Ch *p2,\r
- std::size_t size2, bool case_sensitive) {\r
- if (size1 != size2) return false;\r
- if (case_sensitive) {\r
- for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)\r
- if (*p1 != *p2) return false;\r
- } else {\r
- for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)\r
- if (lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p1)]\r
- != lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p2)])\r
- return false;\r
- }\r
- return true;\r
-}\r
-}\r
-//! \endcond\r
-\r
-///////////////////////////////////////////////////////////////////////\r
-// Memory pool\r
-\r
-//! This class is used by the parser to create new nodes and attributes, without overheads of dynamic memory allocation.\r
-//! In most cases, you will not need to use this class directly. \r
-//! However, if you need to create nodes manually or modify names/values of nodes, \r
-//! you are encouraged to use memory_pool of relevant xml_document to allocate the memory. \r
-//! Not only is this faster than allocating them by using <code>new</code> operator, \r
-//! but also their lifetime will be tied to the lifetime of document, \r
-//! possibly simplyfing memory management. \r
-//! <br><br>\r
-//! Call allocate_node() or allocate_attribute() functions to obtain new nodes or attributes from the pool. \r
-//! You can also call allocate_string() function to allocate strings.\r
-//! Such strings can then be used as names or values of nodes without worrying about their lifetime.\r
-//! Note that there is no <code>free()</code> function -- all allocations are freed at once when clear() function is called, \r
-//! or when the pool is destroyed.\r
-//! <br><br>\r
-//! It is also possible to create a standalone memory_pool, and use it \r
-//! to allocate nodes, whose lifetime will not be tied to any document.\r
-//! <br><br>\r
-//! Pool maintains <code>RAPIDXML_STATIC_POOL_SIZE</code> bytes of statically allocated memory. \r
-//! Until static memory is exhausted, no dynamic memory allocations are done.\r
-//! When static memory is exhausted, pool allocates additional blocks of memory of size <code>RAPIDXML_DYNAMIC_POOL_SIZE</code> each,\r
-//! by using global <code>new[]</code> and <code>delete[]</code> operators. \r
-//! This behaviour can be changed by setting custom allocation routines. \r
-//! Use set_allocator() function to set them.\r
-//! <br><br>\r
-//! Allocations for nodes, attributes and strings are aligned at <code>RAPIDXML_ALIGNMENT</code> bytes.\r
-//! This value defaults to the size of pointer on target architecture.\r
-//! <br><br>\r
-//! To obtain absolutely top performance from the parser,\r
-//! it is important that all nodes are allocated from a single, contiguous block of memory.\r
-//! Otherwise, cache misses when jumping between two (or more) disjoint blocks of memory can slow down parsing quite considerably.\r
-//! If required, you can tweak <code>RAPIDXML_STATIC_POOL_SIZE</code>, <code>RAPIDXML_DYNAMIC_POOL_SIZE</code> and <code>RAPIDXML_ALIGNMENT</code> \r
-//! to obtain best wasted memory to performance compromise.\r
-//! To do it, define their values before rapidxml.hpp file is included.\r
-//! \param Ch Character type of created nodes. \r
-template<class Ch = char>\r
-class memory_pool {\r
-\r
-public:\r
-\r
- //! \cond internal\r
- typedef void *(alloc_func)(std::size_t); // Type of user-defined function used to allocate memory\r
- typedef void (free_func)(void *); // Type of user-defined function used to free memory\r
- //! \endcond\r
-\r
- //! Constructs empty pool with default allocator functions.\r
- memory_pool() :\r
- m_alloc_func(0), m_free_func(0) {\r
- init();\r
- }\r
-\r
- //! Destroys pool and frees all the memory. \r
- //! This causes memory occupied by nodes allocated by the pool to be freed.\r
- //! Nodes allocated from the pool are no longer valid.\r
- ~memory_pool() {\r
- clear();\r
- }\r
-\r
- //! Allocates a new node from the pool, and optionally assigns name and value to it. \r
- //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.\r
- //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function\r
- //! will call rapidxml::parse_error_handler() function.\r
- //! \param type Type of node to create.\r
- //! \param name Name to assign to the node, or 0 to assign no name.\r
- //! \param value Value to assign to the node, or 0 to assign no value.\r
- //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.\r
- //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.\r
- //! \return Pointer to allocated node. This pointer will never be NULL.\r
- xml_node<Ch> *allocate_node(node_type type, const Ch *name = 0,\r
- const Ch *value = 0, std::size_t name_size = 0,\r
- std::size_t value_size = 0) {\r
- void *memory = allocate_aligned(sizeof(xml_node<Ch> ));\r
- xml_node<Ch> *node = new (memory) xml_node<Ch>(type);\r
- if (name) {\r
- if (name_size > 0)\r
- node->name(name, name_size);\r
- else node->name(name);\r
- }\r
- if (value) {\r
- if (value_size > 0)\r
- node->value(value, value_size);\r
- else node->value(value);\r
- }\r
- return node;\r
- }\r
-\r
- //! Allocates a new attribute from the pool, and optionally assigns name and value to it.\r
- //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.\r
- //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function\r
- //! will call rapidxml::parse_error_handler() function.\r
- //! \param name Name to assign to the attribute, or 0 to assign no name.\r
- //! \param value Value to assign to the attribute, or 0 to assign no value.\r
- //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.\r
- //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.\r
- //! \return Pointer to allocated attribute. This pointer will never be NULL.\r
- xml_attribute<Ch> *allocate_attribute(const Ch *name = 0, const Ch *value = 0,\r
- std::size_t name_size = 0, std::size_t value_size = 0) {\r
- void *memory = allocate_aligned(sizeof(xml_attribute<Ch> ));\r
- xml_attribute<Ch> *attribute = new (memory) xml_attribute<Ch>;\r
- if (name) {\r
- if (name_size > 0)\r
- attribute->name(name, name_size);\r
- else attribute->name(name);\r
- }\r
- if (value) {\r
- if (value_size > 0)\r
- attribute->value(value, value_size);\r
- else attribute->value(value);\r
- }\r
- return attribute;\r
- }\r
-\r
- //! Allocates a char array of given size from the pool, and optionally copies a given string to it.\r
- //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.\r
- //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function\r
- //! will call rapidxml::parse_error_handler() function.\r
- //! \param source String to initialize the allocated memory with, or 0 to not initialize it.\r
- //! \param size Number of characters to allocate, or zero to calculate it automatically from source string length; if size is 0, source string must be specified and null terminated.\r
- //! \return Pointer to allocated char array. This pointer will never be NULL.\r
- Ch *allocate_string(const Ch *source = 0, std::size_t size = 0) {\r
- assert(source || size); // Either source or size (or both) must be specified\r
- if (size == 0) size = internal::measure(source) + 1;\r
- Ch *result = static_cast<Ch *>(allocate_aligned(size * sizeof(Ch)));\r
- if (source) for (std::size_t i = 0; i < size; ++i)\r
- result[i] = source[i];\r
- return result;\r
- }\r
-\r
- //! Clones an xml_node and its hierarchy of child nodes and attributes.\r
- //! Nodes and attributes are allocated from this memory pool.\r
- //! Names and values are not cloned, they are shared between the clone and the source.\r
- //! Result node can be optionally specified as a second parameter, \r
- //! in which case its contents will be replaced with cloned source node.\r
- //! This is useful when you want to clone entire document.\r
- //! \param source Node to clone.\r
- //! \param result Node to put results in, or 0 to automatically allocate result node\r
- //! \return Pointer to cloned node. This pointer will never be NULL.\r
- xml_node<Ch> *clone_node(const xml_node<Ch> *source,\r
- xml_node<Ch> *result = 0) {\r
- // Prepare result node\r
- if (result) {\r
- result->remove_all_attributes();\r
- result->remove_all_nodes();\r
- result->type(source->type());\r
- } else result = allocate_node(source->type());\r
-\r
- // Clone name and value\r
- result->name(source->name(), source->name_size());\r
- result->value(source->value(), source->value_size());\r
-\r
- // Clone child nodes and attributes\r
- for (xml_node<Ch> *child = source->first_node(); child;\r
- child = child->next_sibling())\r
- result->append_node(clone_node(child));\r
- for (xml_attribute<Ch> *attr = source->first_attribute(); attr;\r
- attr = attr->next_attribute())\r
- result->append_attribute(\r
- allocate_attribute(attr->name(), attr->value(), attr->name_size(),\r
- attr->value_size()));\r
-\r
- return result;\r
- }\r
-\r
- //! Clears the pool. \r
- //! This causes memory occupied by nodes allocated by the pool to be freed.\r
- //! Any nodes or strings allocated from the pool will no longer be valid.\r
- void clear() {\r
- while (m_begin != m_static_memory) {\r
- char *previous_begin = reinterpret_cast<header *>(align(m_begin))\r
- ->previous_begin;\r
- if (m_free_func)\r
- m_free_func(m_begin);\r
- else delete[] m_begin;\r
- m_begin = previous_begin;\r
- }\r
- init();\r
- }\r
-\r
- //! Sets or resets the user-defined memory allocation functions for the pool.\r
- //! This can only be called when no memory is allocated from the pool yet, otherwise results are undefined.\r
- //! Allocation function must not return invalid pointer on failure. It should either throw,\r
- //! stop the program, or use <code>longjmp()</code> function to pass control to other place of program. \r
- //! If it returns invalid pointer, results are undefined.\r
- //! <br><br>\r
- //! User defined allocation functions must have the following forms:\r
- //! <br><code>\r
- //! <br>void *allocate(std::size_t size);\r
- //! <br>void free(void *pointer);\r
- //! </code><br>\r
- //! \param af Allocation function, or 0 to restore default function\r
- //! \param ff Free function, or 0 to restore default function\r
- void set_allocator(alloc_func *af, free_func *ff) {\r
- assert(m_begin == m_static_memory && m_ptr == align(m_begin)); // Verify that no memory is allocated yet\r
- m_alloc_func = af;\r
- m_free_func = ff;\r
- }\r
-\r
-private:\r
-\r
- struct header {\r
- char *previous_begin;\r
- };\r
-\r
- void init() {\r
- m_begin = m_static_memory;\r
- m_ptr = align(m_begin);\r
- m_end = m_static_memory + sizeof(m_static_memory);\r
- }\r
-\r
- char *align(char *ptr) {\r
- std::size_t alignment = ((RAPIDXML_ALIGNMENT\r
- - (std::size_t(ptr) & (RAPIDXML_ALIGNMENT - 1)))\r
- & (RAPIDXML_ALIGNMENT - 1));\r
- return ptr + alignment;\r
- }\r
-\r
- char *allocate_raw(std::size_t size) {\r
- // Allocate\r
- void *memory;\r
- if (m_alloc_func) // Allocate memory using either user-specified allocation function or global operator new[]\r
- {\r
- memory = m_alloc_func(size);\r
- assert(memory); // Allocator is not allowed to return 0, on failure it must either throw, stop the program or use longjmp\r
- } else {\r
- memory = new char[size];\r
-#ifdef RAPIDXML_NO_EXCEPTIONS\r
- if (!memory) // If exceptions are disabled, verify memory allocation, because new will not be able to throw bad_alloc\r
- RAPIDXML_PARSE_ERROR("out of memory", 0);\r
-#endif\r
- }\r
- return static_cast<char *>(memory);\r
- }\r
-\r
- void *allocate_aligned(std::size_t size) {\r
- // Calculate aligned pointer\r
- char *result = align(m_ptr);\r
-\r
- // If not enough memory left in current pool, allocate a new pool\r
- if (result + size > m_end) {\r
- // Calculate required pool size (may be bigger than RAPIDXML_DYNAMIC_POOL_SIZE)\r
- std::size_t pool_size = RAPIDXML_DYNAMIC_POOL_SIZE;\r
- if (pool_size < size) pool_size = size;\r
-\r
- // Allocate\r
- std::size_t alloc_size = sizeof(header) + (2 * RAPIDXML_ALIGNMENT - 2)\r
- + pool_size; // 2 alignments required in worst case: one for header, one for actual allocation\r
- char *raw_memory = allocate_raw(alloc_size);\r
-\r
- // Setup new pool in allocated memory\r
- char *pool = align(raw_memory);\r
- header *new_header = reinterpret_cast<header *>(pool);\r
- new_header->previous_begin = m_begin;\r
- m_begin = raw_memory;\r
- m_ptr = pool + sizeof(header);\r
- m_end = raw_memory + alloc_size;\r
-\r
- // Calculate aligned pointer again using new pool\r
- result = align(m_ptr);\r
- }\r
-\r
- // Update pool and return aligned pointer\r
- m_ptr = result + size;\r
- return result;\r
- }\r
-\r
- char *m_begin; // Start of raw memory making up current pool\r
- char *m_ptr; // First free byte in current pool\r
- char *m_end; // One past last available byte in current pool\r
- char m_static_memory[RAPIDXML_STATIC_POOL_SIZE]; // Static raw memory\r
- alloc_func *m_alloc_func; // Allocator function, or 0 if default is to be used\r
- free_func *m_free_func; // Free function, or 0 if default is to be used\r
-};\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// XML base\r
-\r
-//! Base class for xml_node and xml_attribute implementing common functions: \r
-//! name(), name_size(), value(), value_size() and parent().\r
-//! \param Ch Character type to use\r
-template<class Ch = char>\r
-class xml_base {\r
-\r
-public:\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Construction & destruction\r
-\r
- // Construct a base with empty name, value and parent\r
- xml_base() :\r
- m_name(0), m_value(0), m_name_size(0), m_value_size(0), m_parent(0) {\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Node data access\r
-\r
- //! Gets name of the node. \r
- //! Interpretation of name depends on type of node.\r
- //! Note that name will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.\r
- //! <br><br>\r
- //! Use name_size() function to determine length of the name.\r
- //! \return Name of node, or empty string if node has no name.\r
- Ch *name() const {\r
- return m_name ? m_name : nullstr();\r
- }\r
-\r
- //! Gets size of node name, not including terminator character.\r
- //! This function works correctly irrespective of whether name is or is not zero terminated.\r
- //! \return Size of node name, in characters.\r
- std::size_t name_size() const {\r
- return m_name ? m_name_size : 0;\r
- }\r
-\r
- //! Gets value of node. \r
- //! Interpretation of value depends on type of node.\r
- //! Note that value will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.\r
- //! <br><br>\r
- //! Use value_size() function to determine length of the value.\r
- //! \return Value of node, or empty string if node has no value.\r
- Ch *value() const {\r
- return m_value ? m_value : nullstr();\r
- }\r
-\r
- //! Gets size of node value, not including terminator character.\r
- //! This function works correctly irrespective of whether value is or is not zero terminated.\r
- //! \return Size of node value, in characters.\r
- std::size_t value_size() const {\r
- return m_value ? m_value_size : 0;\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Node modification\r
-\r
- //! Sets name of node to a non zero-terminated string.\r
- //! See \ref ownership_of_strings.\r
- //! <br><br>\r
- //! Note that node does not own its name or value, it only stores a pointer to it. \r
- //! It will not delete or otherwise free the pointer on destruction.\r
- //! It is reponsibility of the user to properly manage lifetime of the string.\r
- //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -\r
- //! on destruction of the document the string will be automatically freed.\r
- //! <br><br>\r
- //! Size of name must be specified separately, because name does not have to be zero terminated.\r
- //! Use name(const Ch *) function to have the length automatically calculated (string must be zero terminated).\r
- //! \param name Name of node to set. Does not have to be zero terminated.\r
- //! \param size Size of name, in characters. This does not include zero terminator, if one is present.\r
- void name(const Ch *name, std::size_t size) {\r
- m_name = const_cast<Ch *>(name);\r
- m_name_size = size;\r
- }\r
-\r
- //! Sets name of node to a zero-terminated string.\r
- //! See also \ref ownership_of_strings and xml_node::name(const Ch *, std::size_t).\r
- //! \param name Name of node to set. Must be zero terminated.\r
- void name(const Ch *name) {\r
- this->name(name, internal::measure(name));\r
- }\r
-\r
- //! Sets value of node to a non zero-terminated string.\r
- //! See \ref ownership_of_strings.\r
- //! <br><br>\r
- //! Note that node does not own its name or value, it only stores a pointer to it. \r
- //! It will not delete or otherwise free the pointer on destruction.\r
- //! It is reponsibility of the user to properly manage lifetime of the string.\r
- //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -\r
- //! on destruction of the document the string will be automatically freed.\r
- //! <br><br>\r
- //! Size of value must be specified separately, because it does not have to be zero terminated.\r
- //! Use value(const Ch *) function to have the length automatically calculated (string must be zero terminated).\r
- //! <br><br>\r
- //! If an element has a child node of type node_data, it will take precedence over element value when printing.\r
- //! If you want to manipulate data of elements using values, use parser flag rapidxml::parse_no_data_nodes to prevent creation of data nodes by the parser.\r
- //! \param value value of node to set. Does not have to be zero terminated.\r
- //! \param size Size of value, in characters. This does not include zero terminator, if one is present.\r
- void value(const Ch *value, std::size_t size) {\r
- m_value = const_cast<Ch *>(value);\r
- m_value_size = size;\r
- }\r
-\r
- //! Sets value of node to a zero-terminated string.\r
- //! See also \ref ownership_of_strings and xml_node::value(const Ch *, std::size_t).\r
- //! \param value Vame of node to set. Must be zero terminated.\r
- void value(const Ch *value) {\r
- this->value(value, internal::measure(value));\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Related nodes access\r
-\r
- //! Gets node parent.\r
- //! \return Pointer to parent node, or 0 if there is no parent.\r
- xml_node<Ch> *parent() const {\r
- return m_parent;\r
- }\r
-\r
-protected:\r
-\r
- // Return empty string\r
- static Ch *nullstr() {\r
- static Ch zero = Ch('\0');\r
- return &zero;\r
- }\r
-\r
- Ch *m_name; // Name of node, or 0 if no name\r
- Ch *m_value; // Value of node, or 0 if no value\r
- std::size_t m_name_size; // Length of node name, or undefined of no name\r
- std::size_t m_value_size; // Length of node value, or undefined if no value\r
- xml_node<Ch> *m_parent; // Pointer to parent node, or 0 if none\r
-\r
-};\r
-\r
-//! Class representing attribute node of XML document. \r
-//! Each attribute has name and value strings, which are available through name() and value() functions (inherited from xml_base).\r
-//! Note that after parse, both name and value of attribute will point to interior of source text used for parsing. \r
-//! Thus, this text must persist in memory for the lifetime of attribute.\r
-//! \param Ch Character type to use.\r
-template<class Ch = char>\r
-class xml_attribute:\r
- public xml_base<Ch> {\r
-\r
- friend class xml_node<Ch> ;\r
-\r
-public:\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Construction & destruction\r
-\r
- //! Constructs an empty attribute with the specified type. \r
- //! Consider using memory_pool of appropriate xml_document if allocating attributes manually.\r
- xml_attribute() : m_prev_attribute(0), m_next_attribute(0) {\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Related nodes access\r
-\r
- //! Gets document of which attribute is a child.\r
- //! \return Pointer to document that contains this attribute, or 0 if there is no parent document.\r
- xml_document<Ch> *document() const {\r
- if (xml_node<Ch> *node = this->parent()) {\r
- while (node->parent())\r
- node = node->parent();\r
- return\r
- node->type() == node_document ?\r
- static_cast<xml_document<Ch> *>(node) : 0;\r
- } else return 0;\r
- }\r
-\r
- //! Gets previous attribute, optionally matching attribute name. \r
- //! \param name Name of attribute to find, or 0 to return previous attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero\r
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string\r
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters\r
- //! \return Pointer to found attribute, or 0 if not found.\r
- xml_attribute<Ch> *previous_attribute(const Ch *name = 0,\r
- std::size_t name_size = 0, bool case_sensitive = true) const {\r
- if (name) {\r
- if (name_size == 0) name_size = internal::measure(name);\r
- for (xml_attribute<Ch> *attribute = m_prev_attribute; attribute;\r
- attribute = attribute->m_prev_attribute)\r
- if (internal::compare(attribute->name(), attribute->name_size(), name,\r
- name_size, case_sensitive)) return attribute;\r
- return 0;\r
- } else return this->m_parent ? m_prev_attribute : 0;\r
- }\r
-\r
- //! Gets next attribute, optionally matching attribute name. \r
- //! \param name Name of attribute to find, or 0 to return next attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero\r
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string\r
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters\r
- //! \return Pointer to found attribute, or 0 if not found.\r
- xml_attribute<Ch> *next_attribute(const Ch *name = 0, std::size_t name_size =\r
- 0, bool case_sensitive = true) const {\r
- if (name) {\r
- if (name_size == 0) name_size = internal::measure(name);\r
- for (xml_attribute<Ch> *attribute = m_next_attribute; attribute;\r
- attribute = attribute->m_next_attribute)\r
- if (internal::compare(attribute->name(), attribute->name_size(), name,\r
- name_size, case_sensitive)) return attribute;\r
- return 0;\r
- } else return this->m_parent ? m_next_attribute : 0;\r
- }\r
-\r
-private:\r
-\r
- xml_attribute<Ch> *m_prev_attribute; // Pointer to previous sibling of attribute, or 0 if none; only valid if parent is non-zero\r
- xml_attribute<Ch> *m_next_attribute; // Pointer to next sibling of attribute, or 0 if none; only valid if parent is non-zero\r
-\r
-};\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// XML node\r
-\r
-//! Class representing a node of XML document. \r
-//! Each node may have associated name and value strings, which are available through name() and value() functions. \r
-//! Interpretation of name and value depends on type of the node.\r
-//! Type of node can be determined by using type() function.\r
-//! <br><br>\r
-//! Note that after parse, both name and value of node, if any, will point interior of source text used for parsing. \r
-//! Thus, this text must persist in the memory for the lifetime of node.\r
-//! \param Ch Character type to use.\r
-template<class Ch = char>\r
-class xml_node:\r
- public xml_base<Ch> {\r
-\r
-public:\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Construction & destruction\r
-\r
- //! Constructs an empty node with the specified type. \r
- //! Consider using memory_pool of appropriate document to allocate nodes manually.\r
- //! \param type Type of node to construct.\r
- xml_node(node_type type) :\r
- m_type(type), m_first_node(0), m_last_node(0), m_first_attribute(0), m_last_attribute(0),\r
- m_prev_sibling(0), m_next_sibling(0) {\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Node data access\r
-\r
- //! Gets type of node.\r
- //! \return Type of node.\r
- node_type type() const {\r
- return m_type;\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Related nodes access\r
-\r
- //! Gets document of which node is a child.\r
- //! \return Pointer to document that contains this node, or 0 if there is no parent document.\r
- xml_document<Ch> *document() const {\r
- xml_node<Ch> *node = const_cast<xml_node<Ch> *>(this);\r
- while (node->parent())\r
- node = node->parent();\r
- return\r
- node->type() == node_document ? static_cast<xml_document<Ch> *>(node) :\r
- 0;\r
- }\r
-\r
- //! Gets first child node, optionally matching node name.\r
- //! \param name Name of child to find, or 0 to return first child regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero\r
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string\r
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters\r
- //! \return Pointer to found child, or 0 if not found.\r
- xml_node<Ch> *first_node(const Ch *name = 0, std::size_t name_size = 0,\r
- bool case_sensitive = true) const {\r
- if (name) {\r
- if (name_size == 0) name_size = internal::measure(name);\r
- for (xml_node<Ch> *child = m_first_node; child;\r
- child = child->next_sibling())\r
- if (internal::compare(child->name(), child->name_size(), name,\r
- name_size, case_sensitive)) return child;\r
- return 0;\r
- } else return m_first_node;\r
- }\r
-\r
- //! Gets last child node, optionally matching node name. \r
- //! Behaviour is undefined if node has no children.\r
- //! Use first_node() to test if node has children.\r
- //! \param name Name of child to find, or 0 to return last child regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero\r
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string\r
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters\r
- //! \return Pointer to found child, or 0 if not found.\r
- xml_node<Ch> *last_node(const Ch *name = 0, std::size_t name_size = 0,\r
- bool case_sensitive = true) const {\r
- assert(m_first_node); // Cannot query for last child if node has no children\r
- if (name) {\r
- if (name_size == 0) name_size = internal::measure(name);\r
- for (xml_node<Ch> *child = m_last_node; child;\r
- child = child->previous_sibling())\r
- if (internal::compare(child->name(), child->name_size(), name,\r
- name_size, case_sensitive)) return child;\r
- return 0;\r
- } else return m_last_node;\r
- }\r
-\r
- //! Gets previous sibling node, optionally matching node name. \r
- //! Behaviour is undefined if node has no parent.\r
- //! Use parent() to test if node has a parent.\r
- //! \param name Name of sibling to find, or 0 to return previous sibling regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero\r
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string\r
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters\r
- //! \return Pointer to found sibling, or 0 if not found.\r
- xml_node<Ch> *previous_sibling(const Ch *name = 0, std::size_t name_size = 0,\r
- bool case_sensitive = true) const {\r
- assert(this->m_parent); // Cannot query for siblings if node has no parent\r
- if (name) {\r
- if (name_size == 0) name_size = internal::measure(name);\r
- for (xml_node<Ch> *sibling = m_prev_sibling; sibling;\r
- sibling = sibling->m_prev_sibling)\r
- if (internal::compare(sibling->name(), sibling->name_size(), name,\r
- name_size, case_sensitive)) return sibling;\r
- return 0;\r
- } else return m_prev_sibling;\r
- }\r
-\r
- //! Gets next sibling node, optionally matching node name. \r
- //! Behaviour is undefined if node has no parent.\r
- //! Use parent() to test if node has a parent.\r
- //! \param name Name of sibling to find, or 0 to return next sibling regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero\r
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string\r
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters\r
- //! \return Pointer to found sibling, or 0 if not found.\r
- xml_node<Ch> *next_sibling(const Ch *name = 0, std::size_t name_size = 0,\r
- bool case_sensitive = true) const {\r
- assert(this->m_parent); // Cannot query for siblings if node has no parent\r
- if (name) {\r
- if (name_size == 0) name_size = internal::measure(name);\r
- for (xml_node<Ch> *sibling = m_next_sibling; sibling;\r
- sibling = sibling->m_next_sibling)\r
- if (internal::compare(sibling->name(), sibling->name_size(), name,\r
- name_size, case_sensitive)) return sibling;\r
- return 0;\r
- } else return m_next_sibling;\r
- }\r
-\r
- //! Gets first attribute of node, optionally matching attribute name.\r
- //! \param name Name of attribute to find, or 0 to return first attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero\r
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string\r
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters\r
- //! \return Pointer to found attribute, or 0 if not found.\r
- xml_attribute<Ch> *first_attribute(const Ch *name = 0, std::size_t name_size =\r
- 0, bool case_sensitive = true) const {\r
- if (name) {\r
- if (name_size == 0) name_size = internal::measure(name);\r
- for (xml_attribute<Ch> *attribute = m_first_attribute; attribute;\r
- attribute = attribute->m_next_attribute)\r
- if (internal::compare(attribute->name(), attribute->name_size(), name,\r
- name_size, case_sensitive)) return attribute;\r
- return 0;\r
- } else return m_first_attribute;\r
- }\r
-\r
- //! Gets last attribute of node, optionally matching attribute name.\r
- //! \param name Name of attribute to find, or 0 to return last attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero\r
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string\r
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters\r
- //! \return Pointer to found attribute, or 0 if not found.\r
- xml_attribute<Ch> *last_attribute(const Ch *name = 0, std::size_t name_size =\r
- 0, bool case_sensitive = true) const {\r
- if (name) {\r
- if (name_size == 0) name_size = internal::measure(name);\r
- for (xml_attribute<Ch> *attribute = m_last_attribute; attribute;\r
- attribute = attribute->m_prev_attribute)\r
- if (internal::compare(attribute->name(), attribute->name_size(), name,\r
- name_size, case_sensitive)) return attribute;\r
- return 0;\r
- } else return m_first_attribute ? m_last_attribute : 0;\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Node modification\r
-\r
- //! Sets type of node.\r
- //! \param type Type of node to set.\r
- void type(node_type type) {\r
- m_type = type;\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Node manipulation\r
-\r
- //! Prepends a new child node.\r
- //! The prepended child becomes the first child, and all existing children are moved one position back.\r
- //! \param child Node to prepend.\r
- void prepend_node(xml_node<Ch> *child) {\r
- assert(child && !child->parent() && child->type() != node_document);\r
- if (first_node()) {\r
- child->m_next_sibling = m_first_node;\r
- m_first_node->m_prev_sibling = child;\r
- } else {\r
- child->m_next_sibling = 0;\r
- m_last_node = child;\r
- }\r
- m_first_node = child;\r
- child->m_parent = this;\r
- child->m_prev_sibling = 0;\r
- }\r
-\r
- //! Appends a new child node. \r
- //! The appended child becomes the last child.\r
- //! \param child Node to append.\r
- void append_node(xml_node<Ch> *child) {\r
- assert(child && !child->parent() && child->type() != node_document);\r
- if (first_node()) {\r
- child->m_prev_sibling = m_last_node;\r
- m_last_node->m_next_sibling = child;\r
- } else {\r
- child->m_prev_sibling = 0;\r
- m_first_node = child;\r
- }\r
- m_last_node = child;\r
- child->m_parent = this;\r
- child->m_next_sibling = 0;\r
- }\r
-\r
- //! Inserts a new child node at specified place inside the node. \r
- //! All children after and including the specified node are moved one position back.\r
- //! \param where Place where to insert the child, or 0 to insert at the back.\r
- //! \param child Node to insert.\r
- void insert_node(xml_node<Ch> *where, xml_node<Ch> *child) {\r
- assert(!where || where->parent() == this);\r
- assert(child && !child->parent() && child->type() != node_document);\r
- if (where == m_first_node)\r
- prepend_node(child);\r
- else if (where == 0)\r
- append_node(child);\r
- else {\r
- child->m_prev_sibling = where->m_prev_sibling;\r
- child->m_next_sibling = where;\r
- where->m_prev_sibling->m_next_sibling = child;\r
- where->m_prev_sibling = child;\r
- child->m_parent = this;\r
- }\r
- }\r
-\r
- //! Removes first child node. \r
- //! If node has no children, behaviour is undefined.\r
- //! Use first_node() to test if node has children.\r
- void remove_first_node() {\r
- assert(first_node());\r
- xml_node<Ch> *child = m_first_node;\r
- m_first_node = child->m_next_sibling;\r
- if (child->m_next_sibling)\r
- child->m_next_sibling->m_prev_sibling = 0;\r
- else m_last_node = 0;\r
- child->m_parent = 0;\r
- }\r
-\r
- //! Removes last child of the node. \r
- //! If node has no children, behaviour is undefined.\r
- //! Use first_node() to test if node has children.\r
- void remove_last_node() {\r
- assert(first_node());\r
- xml_node<Ch> *child = m_last_node;\r
- if (child->m_prev_sibling) {\r
- m_last_node = child->m_prev_sibling;\r
- child->m_prev_sibling->m_next_sibling = 0;\r
- } else m_first_node = 0;\r
- child->m_parent = 0;\r
- }\r
-\r
- //! Removes specified child from the node\r
- // \param where Pointer to child to be removed.\r
- void remove_node(xml_node<Ch> *where) {\r
- assert(where && where->parent() == this);\r
- assert(first_node());\r
- if (where == m_first_node)\r
- remove_first_node();\r
- else if (where == m_last_node)\r
- remove_last_node();\r
- else {\r
- where->m_prev_sibling->m_next_sibling = where->m_next_sibling;\r
- where->m_next_sibling->m_prev_sibling = where->m_prev_sibling;\r
- where->m_parent = 0;\r
- }\r
- }\r
-\r
- //! Removes all child nodes (but not attributes).\r
- void remove_all_nodes() {\r
- for (xml_node<Ch> *node = first_node(); node; node = node->m_next_sibling)\r
- node->m_parent = 0;\r
- m_first_node = 0;\r
- }\r
-\r
- //! Prepends a new attribute to the node.\r
- //! \param attribute Attribute to prepend.\r
- void prepend_attribute(xml_attribute<Ch> *attribute) {\r
- assert(attribute && !attribute->parent());\r
- if (first_attribute()) {\r
- attribute->m_next_attribute = m_first_attribute;\r
- m_first_attribute->m_prev_attribute = attribute;\r
- } else {\r
- attribute->m_next_attribute = 0;\r
- m_last_attribute = attribute;\r
- }\r
- m_first_attribute = attribute;\r
- attribute->m_parent = this;\r
- attribute->m_prev_attribute = 0;\r
- }\r
-\r
- //! Appends a new attribute to the node.\r
- //! \param attribute Attribute to append.\r
- void append_attribute(xml_attribute<Ch> *attribute) {\r
- assert(attribute && !attribute->parent());\r
- if (first_attribute()) {\r
- attribute->m_prev_attribute = m_last_attribute;\r
- m_last_attribute->m_next_attribute = attribute;\r
- } else {\r
- attribute->m_prev_attribute = 0;\r
- m_first_attribute = attribute;\r
- }\r
- m_last_attribute = attribute;\r
- attribute->m_parent = this;\r
- attribute->m_next_attribute = 0;\r
- }\r
-\r
- //! Inserts a new attribute at specified place inside the node. \r
- //! All attributes after and including the specified attribute are moved one position back.\r
- //! \param where Place where to insert the attribute, or 0 to insert at the back.\r
- //! \param attribute Attribute to insert.\r
- void insert_attribute(xml_attribute<Ch> *where,\r
- xml_attribute<Ch> *attribute) {\r
- assert(!where || where->parent() == this);\r
- assert(attribute && !attribute->parent());\r
- if (where == m_first_attribute)\r
- prepend_attribute(attribute);\r
- else if (where == 0)\r
- append_attribute(attribute);\r
- else {\r
- attribute->m_prev_attribute = where->m_prev_attribute;\r
- attribute->m_next_attribute = where;\r
- where->m_prev_attribute->m_next_attribute = attribute;\r
- where->m_prev_attribute = attribute;\r
- attribute->m_parent = this;\r
- }\r
- }\r
-\r
- //! Removes first attribute of the node. \r
- //! If node has no attributes, behaviour is undefined.\r
- //! Use first_attribute() to test if node has attributes.\r
- void remove_first_attribute() {\r
- assert(first_attribute());\r
- xml_attribute<Ch> *attribute = m_first_attribute;\r
- if (attribute->m_next_attribute) {\r
- attribute->m_next_attribute->m_prev_attribute = 0;\r
- } else m_last_attribute = 0;\r
- attribute->m_parent = 0;\r
- m_first_attribute = attribute->m_next_attribute;\r
- }\r
-\r
- //! Removes last attribute of the node. \r
- //! If node has no attributes, behaviour is undefined.\r
- //! Use first_attribute() to test if node has attributes.\r
- void remove_last_attribute() {\r
- assert(first_attribute());\r
- xml_attribute<Ch> *attribute = m_last_attribute;\r
- if (attribute->m_prev_attribute) {\r
- attribute->m_prev_attribute->m_next_attribute = 0;\r
- m_last_attribute = attribute->m_prev_attribute;\r
- } else m_first_attribute = 0;\r
- attribute->m_parent = 0;\r
- }\r
-\r
- //! Removes specified attribute from node.\r
- //! \param where Pointer to attribute to be removed.\r
- void remove_attribute(xml_attribute<Ch> *where) {\r
- assert(first_attribute() && where->parent() == this);\r
- if (where == m_first_attribute)\r
- remove_first_attribute();\r
- else if (where == m_last_attribute)\r
- remove_last_attribute();\r
- else {\r
- where->m_prev_attribute->m_next_attribute = where->m_next_attribute;\r
- where->m_next_attribute->m_prev_attribute = where->m_prev_attribute;\r
- where->m_parent = 0;\r
- }\r
- }\r
-\r
- //! Removes all attributes of node.\r
- void remove_all_attributes() {\r
- for (xml_attribute<Ch> *attribute = first_attribute(); attribute;\r
- attribute = attribute->m_next_attribute)\r
- attribute->m_parent = 0;\r
- m_first_attribute = 0;\r
- }\r
-\r
-private:\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Restrictions\r
-\r
- // No copying\r
- xml_node(const xml_node &);\r
- void operator =(const xml_node &);\r
-\r
- ///////////////////////////////////////////////////////////////////////////\r
- // Data members\r
-\r
- // Note that some of the pointers below have UNDEFINED values if certain other pointers are 0.\r
- // This is required for maximum performance, as it allows the parser to omit initialization of \r
- // unneded/redundant values.\r
- //\r
- // The rules are as follows:\r
- // 1. first_node and first_attribute contain valid pointers, or 0 if node has no children/attributes respectively\r
- // 2. last_node and last_attribute are valid only if node has at least one child/attribute respectively, otherwise they contain garbage\r
- // 3. prev_sibling and next_sibling are valid only if node has a parent, otherwise they contain garbage\r
-\r
- node_type m_type; // Type of node; always valid\r
- xml_node<Ch> *m_first_node; // Pointer to first child node, or 0 if none; always valid\r
- xml_node<Ch> *m_last_node; // Pointer to last child node, or 0 if none; this value is only valid if m_first_node is non-zero\r
- xml_attribute<Ch> *m_first_attribute; // Pointer to first attribute of node, or 0 if none; always valid\r
- xml_attribute<Ch> *m_last_attribute; // Pointer to last attribute of node, or 0 if none; this value is only valid if m_first_attribute is non-zero\r
- xml_node<Ch> *m_prev_sibling; // Pointer to previous sibling of node, or 0 if none; this value is only valid if m_parent is non-zero\r
- xml_node<Ch> *m_next_sibling; // Pointer to next sibling of node, or 0 if none; this value is only valid if m_parent is non-zero\r
-\r
-};\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// XML document\r
-\r
-//! This class represents root of the DOM hierarchy. \r
-//! It is also an xml_node and a memory_pool through public inheritance.\r
-//! Use parse() function to build a DOM tree from a zero-terminated XML text string.\r
-//! parse() function allocates memory for nodes and attributes by using functions of xml_document, \r
-//! which are inherited from memory_pool.\r
-//! To access root node of the document, use the document itself, as if it was an xml_node.\r
-//! \param Ch Character type to use.\r
-template<class Ch = char>\r
-class xml_document:\r
- public xml_node<Ch>, public memory_pool<Ch> {\r
-\r
-public:\r
-\r
- //! Constructs empty XML document\r
- xml_document() :\r
- xml_node<Ch>(node_document) {\r
- }\r
-\r
- //! Parses zero-terminated XML string according to given flags.\r
- //! Passed string will be modified by the parser, unless rapidxml::parse_non_destructive flag is used.\r
- //! The string must persist for the lifetime of the document.\r
- //! In case of error, rapidxml::parse_error exception will be thrown.\r
- //! <br><br>\r
- //! If you want to parse contents of a file, you must first load the file into the memory, and pass pointer to its beginning.\r
- //! Make sure that data is zero-terminated.\r
- //! <br><br>\r
- //! Document can be parsed into multiple times. \r
- //! Each new call to parse removes previous nodes and attributes (if any), but does not clear memory pool.\r
- //! \param text XML data to parse; pointer is non-const to denote fact that this data may be modified by the parser.\r
- template<int Flags>\r
- void parse(Ch *text) {\r
- assert(text);\r
-\r
- // Remove current contents\r
- this->remove_all_nodes();\r
- this->remove_all_attributes();\r
-\r
- // Parse BOM, if any\r
- parse_bom<Flags>(text);\r
-\r
- // Parse children\r
- while (1) {\r
- // Skip whitespace before node\r
- skip<whitespace_pred, Flags>(text);\r
- if (*text == 0) break;\r
-\r
- // Parse and append new child\r
- if (*text == Ch('<')) {\r
- ++text; // Skip '<'\r
- if (xml_node<Ch> *node = parse_node<Flags>(text))\r
- this->append_node(node);\r
- } else\r
- RAPIDXML_PARSE_ERROR("expected <", text);\r
- }\r
-\r
- }\r
-\r
- //! Clears the document by deleting all nodes and clearing the memory pool.\r
- //! All nodes owned by document pool are destroyed.\r
- void clear() {\r
- this->remove_all_nodes();\r
- this->remove_all_attributes();\r
- memory_pool<Ch>::clear();\r
- }\r
-\r
-private:\r
-\r
- ///////////////////////////////////////////////////////////////////////\r
- // Internal character utility functions\r
-\r
- // Detect whitespace character\r
- struct whitespace_pred {\r
- static unsigned char test(Ch ch) {\r
- return internal::lookup_tables<0>::lookup_whitespace[static_cast<unsigned char>(ch)];\r
- }\r
- };\r
-\r
- // Detect node name character\r
- struct node_name_pred {\r
- static unsigned char test(Ch ch) {\r
- return internal::lookup_tables<0>::lookup_node_name[static_cast<unsigned char>(ch)];\r
- }\r
- };\r
-\r
- // Detect attribute name character\r
- struct attribute_name_pred {\r
- static unsigned char test(Ch ch) {\r
- return internal::lookup_tables<0>::lookup_attribute_name[static_cast<unsigned char>(ch)];\r
- }\r
- };\r
-\r
- // Detect text character (PCDATA)\r
- struct text_pred {\r
- static unsigned char test(Ch ch) {\r
- return internal::lookup_tables<0>::lookup_text[static_cast<unsigned char>(ch)];\r
- }\r
- };\r
-\r
- // Detect text character (PCDATA) that does not require processing\r
- struct text_pure_no_ws_pred {\r
- static unsigned char test(Ch ch) {\r
- return internal::lookup_tables<0>::lookup_text_pure_no_ws[static_cast<unsigned char>(ch)];\r
- }\r
- };\r
-\r
- // Detect text character (PCDATA) that does not require processing\r
- struct text_pure_with_ws_pred {\r
- static unsigned char test(Ch ch) {\r
- return internal::lookup_tables<0>::lookup_text_pure_with_ws[static_cast<unsigned char>(ch)];\r
- }\r
- };\r
-\r
- // Detect attribute value character\r
- template<Ch Quote>\r
- struct attribute_value_pred {\r
- static unsigned char test(Ch ch) {\r
- if (Quote == Ch('\''))\r
- return internal::lookup_tables<0>::lookup_attribute_data_1[static_cast<unsigned char>(ch)];\r
- if (Quote == Ch('\"'))\r
- return internal::lookup_tables<0>::lookup_attribute_data_2[static_cast<unsigned char>(ch)];\r
- return 0; // Should never be executed, to avoid warnings on Comeau\r
- }\r
- };\r
-\r
- // Detect attribute value character\r
- template<Ch Quote>\r
- struct attribute_value_pure_pred {\r
- static unsigned char test(Ch ch) {\r
- if (Quote == Ch('\''))\r
- return internal::lookup_tables<0>::lookup_attribute_data_1_pure[static_cast<unsigned char>(ch)];\r
- if (Quote == Ch('\"'))\r
- return internal::lookup_tables<0>::lookup_attribute_data_2_pure[static_cast<unsigned char>(ch)];\r
- return 0; // Should never be executed, to avoid warnings on Comeau\r
- }\r
- };\r
-\r
- // Insert coded character, using UTF8 or 8-bit ASCII\r
- template<int Flags>\r
- static void insert_coded_character(Ch *&text, unsigned long code) {\r
- if (Flags & parse_no_utf8) {\r
- // Insert 8-bit ASCII character\r
- // Todo: possibly verify that code is less than 256 and use replacement char otherwise?\r
- text[0] = static_cast<unsigned char>(code);\r
- text += 1;\r
- } else {\r
- // Insert UTF8 sequence\r
- if (code < 0x80) // 1 byte sequence\r
- {\r
- text[0] = static_cast<unsigned char>(code);\r
- text += 1;\r
- } else if (code < 0x800) // 2 byte sequence\r
- {\r
- text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF);\r
- code >>= 6;\r
- text[0] = static_cast<unsigned char>(code | 0xC0);\r
- text += 2;\r
- } else if (code < 0x10000) // 3 byte sequence\r
- {\r
- text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF);\r
- code >>= 6;\r
- text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF);\r
- code >>= 6;\r
- text[0] = static_cast<unsigned char>(code | 0xE0);\r
- text += 3;\r
- } else if (code < 0x110000) // 4 byte sequence\r
- {\r
- text[3] = static_cast<unsigned char>((code | 0x80) & 0xBF);\r
- code >>= 6;\r
- text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF);\r
- code >>= 6;\r
- text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF);\r
- code >>= 6;\r
- text[0] = static_cast<unsigned char>(code | 0xF0);\r
- text += 4;\r
- } else // Invalid, only codes up to 0x10FFFF are allowed in Unicode\r
- {\r
- RAPIDXML_PARSE_ERROR("invalid numeric character entity", text);\r
- }\r
- }\r
- }\r
-\r
- // Skip characters until predicate evaluates to true\r
- template<class StopPred, int Flags>\r
- static void skip(Ch *&text) {\r
- Ch *tmp = text;\r
- while (StopPred::test(*tmp))\r
- ++tmp;\r
- text = tmp;\r
- }\r
-\r
- // Skip characters until predicate evaluates to true while doing the following:\r
- // - replacing XML character entity references with proper characters (' & " < > &#...;)\r
- // - condensing whitespace sequences to single space character\r
- template<class StopPred, class StopPredPure, int Flags>\r
- static Ch *skip_and_expand_character_refs(Ch *&text) {\r
- // If entity translation, whitespace condense and whitespace trimming is disabled, use plain skip\r
- if (Flags & parse_no_entity_translation\r
- && !(Flags & parse_normalize_whitespace)\r
- && !(Flags & parse_trim_whitespace)) {\r
- skip<StopPred, Flags>(text);\r
- return text;\r
- }\r
-\r
- // Use simple skip until first modification is detected\r
- skip<StopPredPure, Flags>(text);\r
-\r
- // Use translation skip\r
- Ch *src = text;\r
- Ch *dest = src;\r
- while (StopPred::test(*src)) {\r
- // If entity translation is enabled \r
- if (!(Flags & parse_no_entity_translation)) {\r
- // Test if replacement is needed\r
- if (src[0] == Ch('&')) {\r
- switch (src[1]) {\r
-\r
- // & '\r
- case Ch('a'):\r
- if (src[2] == Ch('m') && src[3] == Ch('p') && src[4] == Ch(';')) {\r
- *dest = Ch('&');\r
- ++dest;\r
- src += 5;\r
- continue;\r
- }\r
- if (src[2] == Ch('p') && src[3] == Ch('o') && src[4] == Ch('s')\r
- && src[5] == Ch(';')) {\r
- *dest = Ch('\'');\r
- ++dest;\r
- src += 6;\r
- continue;\r
- }\r
- break;\r
-\r
- // "\r
- case Ch('q'):\r
- if (src[2] == Ch('u') && src[3] == Ch('o') && src[4] == Ch('t')\r
- && src[5] == Ch(';')) {\r
- *dest = Ch('"');\r
- ++dest;\r
- src += 6;\r
- continue;\r
- }\r
- break;\r
-\r
- // >\r
- case Ch('g'):\r
- if (src[2] == Ch('t') && src[3] == Ch(';')) {\r
- *dest = Ch('>');\r
- ++dest;\r
- src += 4;\r
- continue;\r
- }\r
- break;\r
-\r
- // <\r
- case Ch('l'):\r
- if (src[2] == Ch('t') && src[3] == Ch(';')) {\r
- *dest = Ch('<');\r
- ++dest;\r
- src += 4;\r
- continue;\r
- }\r
- break;\r
-\r
- // &#...; - assumes ASCII\r
- case Ch('#'):\r
- if (src[2] == Ch('x')) {\r
- unsigned long code = 0;\r
- src += 3; // Skip &#x\r
- while (1) {\r
- unsigned char digit =\r
- internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];\r
- if (digit == 0xFF) break;\r
- code = code * 16 + digit;\r
- ++src;\r
- }\r
- insert_coded_character<Flags>(dest, code); // Put character in output\r
- } else {\r
- unsigned long code = 0;\r
- src += 2; // Skip &#\r
- while (1) {\r
- unsigned char digit =\r
- internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];\r
- if (digit == 0xFF) break;\r
- code = code * 10 + digit;\r
- ++src;\r
- }\r
- insert_coded_character<Flags>(dest, code); // Put character in output\r
- }\r
- if (*src == Ch(';'))\r
- ++src;\r
- else\r
- RAPIDXML_PARSE_ERROR("expected ;", src);\r
- continue;\r
-\r
- // Something else\r
- default:\r
- // Ignore, just copy '&' verbatim\r
- break;\r
-\r
- }\r
- }\r
- }\r
-\r
- // If whitespace condensing is enabled\r
- if (Flags & parse_normalize_whitespace) {\r
- // Test if condensing is needed \r
- if (whitespace_pred::test(*src)) {\r
- *dest = Ch(' ');\r
- ++dest; // Put single space in dest\r
- ++src; // Skip first whitespace char\r
- // Skip remaining whitespace chars\r
- while (whitespace_pred::test(*src))\r
- ++src;\r
- continue;\r
- }\r
- }\r
-\r
- // No replacement, only copy character\r
- *dest++ = *src++;\r
-\r
- }\r
-\r
- // Return new end\r
- text = src;\r
- return dest;\r
-\r
- }\r
-\r
- ///////////////////////////////////////////////////////////////////////\r
- // Internal parsing functions\r
-\r
- // Parse BOM, if any\r
- template<int Flags>\r
- void parse_bom(Ch *&text) {\r
- // UTF-8?\r
- if (static_cast<unsigned char>(text[0]) == 0xEF\r
- && static_cast<unsigned char>(text[1]) == 0xBB\r
- && static_cast<unsigned char>(text[2]) == 0xBF) {\r
- text += 3; // Skup utf-8 bom\r
- }\r
- }\r
-\r
- // Parse XML declaration (<?xml...)\r
- template<int Flags>\r
- xml_node<Ch> *parse_xml_declaration(Ch *&text) {\r
- // If parsing of declaration is disabled\r
- if (!(Flags & parse_declaration_node)) {\r
- // Skip until end of declaration\r
- while (text[0] != Ch('?') || text[1] != Ch('>')) {\r
- if (!text[0])\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- ++text;\r
- }\r
- text += 2; // Skip '?>'\r
- return 0;\r
- }\r
-\r
- // Create declaration\r
- xml_node<Ch> *declaration = this->allocate_node(node_declaration);\r
-\r
- // Skip whitespace before attributes or ?>\r
- skip<whitespace_pred, Flags>(text);\r
-\r
- // Parse declaration attributes\r
- parse_node_attributes<Flags>(text, declaration);\r
-\r
- // Skip ?>\r
- if (text[0] != Ch('?') || text[1] != Ch('>'))\r
- RAPIDXML_PARSE_ERROR("expected ?>", text);\r
- text += 2;\r
-\r
- return declaration;\r
- }\r
-\r
- // Parse XML comment (<!--...)\r
- template<int Flags>\r
- xml_node<Ch> *parse_comment(Ch *&text) {\r
- // If parsing of comments is disabled\r
- if (!(Flags & parse_comment_nodes)) {\r
- // Skip until end of comment\r
- while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>')) {\r
- if (!text[0])\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- ++text;\r
- }\r
- text += 3; // Skip '-->'\r
- return 0; // Do not produce comment node\r
- }\r
-\r
- // Remember value start\r
- Ch *value = text;\r
-\r
- // Skip until end of comment\r
- while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>')) {\r
- if (!text[0])\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- ++text;\r
- }\r
-\r
- // Create comment node\r
- xml_node<Ch> *comment = this->allocate_node(node_comment);\r
- comment->value(value, text - value);\r
-\r
- // Place zero terminator after comment value\r
- if (!(Flags & parse_no_string_terminators)) *text = Ch('\0');\r
-\r
- text += 3; // Skip '-->'\r
- return comment;\r
- }\r
-\r
- // Parse DOCTYPE\r
- template<int Flags>\r
- xml_node<Ch> *parse_doctype(Ch *&text) {\r
- // Remember value start\r
- Ch *value = text;\r
-\r
- // Skip to >\r
- while (*text != Ch('>')) {\r
- // Determine character type\r
- switch (*text) {\r
-\r
- // If '[' encountered, scan for matching ending ']' using naive algorithm with depth\r
- // This works for all W3C test files except for 2 most wicked\r
- case Ch('['): {\r
- ++text; // Skip '['\r
- int depth = 1;\r
- while (depth > 0) {\r
- switch (*text) {\r
- case Ch('['):\r
- ++depth;\r
- break;\r
- case Ch(']'):\r
- --depth;\r
- break;\r
- case 0:\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- }\r
- ++text;\r
- }\r
- break;\r
- }\r
-\r
- // Error on end of text\r
- case Ch('\0'):\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
-\r
- // Other character, skip it\r
- default:\r
- ++text;\r
-\r
- }\r
- }\r
-\r
- // If DOCTYPE nodes enabled\r
- if (Flags & parse_doctype_node) {\r
- // Create a new doctype node\r
- xml_node<Ch> *doctype = this->allocate_node(node_doctype);\r
- doctype->value(value, text - value);\r
-\r
- // Place zero terminator after value\r
- if (!(Flags & parse_no_string_terminators)) *text = Ch('\0');\r
-\r
- text += 1; // skip '>'\r
- return doctype;\r
- } else {\r
- text += 1; // skip '>'\r
- return 0;\r
- }\r
-\r
- }\r
-\r
- // Parse PI\r
- template<int Flags>\r
- xml_node<Ch> *parse_pi(Ch *&text) {\r
- // If creation of PI nodes is enabled\r
- if (Flags & parse_pi_nodes) {\r
- // Create pi node\r
- xml_node<Ch> *pi = this->allocate_node(node_pi);\r
-\r
- // Extract PI target name\r
- Ch *name = text;\r
- skip<node_name_pred, Flags>(text);\r
- if (text == name)\r
- RAPIDXML_PARSE_ERROR("expected PI target", text);\r
- pi->name(name, text - name);\r
-\r
- // Skip whitespace between pi target and pi\r
- skip<whitespace_pred, Flags>(text);\r
-\r
- // Remember start of pi\r
- Ch *value = text;\r
-\r
- // Skip to '?>'\r
- while (text[0] != Ch('?') || text[1] != Ch('>')) {\r
- if (*text == Ch('\0'))\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- ++text;\r
- }\r
-\r
- // Set pi value (verbatim, no entity expansion or whitespace normalization)\r
- pi->value(value, text - value);\r
-\r
- // Place zero terminator after name and value\r
- if (!(Flags & parse_no_string_terminators)) {\r
- pi->name()[pi->name_size()] = Ch('\0');\r
- pi->value()[pi->value_size()] = Ch('\0');\r
- }\r
-\r
- text += 2; // Skip '?>'\r
- return pi;\r
- } else {\r
- // Skip to '?>'\r
- while (text[0] != Ch('?') || text[1] != Ch('>')) {\r
- if (*text == Ch('\0'))\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- ++text;\r
- }\r
- text += 2; // Skip '?>'\r
- return 0;\r
- }\r
- }\r
-\r
- // Parse and append data\r
- // Return character that ends data.\r
- // This is necessary because this character might have been overwritten by a terminating 0\r
- template<int Flags>\r
- Ch parse_and_append_data(xml_node<Ch> *node, Ch *&text, Ch *contents_start) {\r
- // Backup to contents start if whitespace trimming is disabled\r
- if (!(Flags & parse_trim_whitespace)) text = contents_start;\r
-\r
- // Skip until end of data\r
- Ch *value = text, *end;\r
- if (Flags & parse_normalize_whitespace)\r
- end = skip_and_expand_character_refs<text_pred, text_pure_with_ws_pred,\r
- Flags>(text);\r
- else end = skip_and_expand_character_refs<text_pred, text_pure_no_ws_pred,\r
- Flags>(text);\r
-\r
- // Trim trailing whitespace if flag is set; leading was already trimmed by whitespace skip after >\r
- if (Flags & parse_trim_whitespace) {\r
- if (Flags & parse_normalize_whitespace) {\r
- // Whitespace is already condensed to single space characters by skipping function, so just trim 1 char off the end\r
- if (*(end - 1) == Ch(' ')) --end;\r
- } else {\r
- // Backup until non-whitespace character is found\r
- while (whitespace_pred::test(*(end - 1)))\r
- --end;\r
- }\r
- }\r
-\r
- // If characters are still left between end and value (this test is only necessary if normalization is enabled)\r
- // Create new data node\r
- if (!(Flags & parse_no_data_nodes)) {\r
- xml_node<Ch> *data = this->allocate_node(node_data);\r
- data->value(value, end - value);\r
- node->append_node(data);\r
- }\r
-\r
- // Add data to parent node if no data exists yet\r
- if (!(Flags & parse_no_element_values))\r
- if (*node->value() == Ch('\0')) node->value(value, end - value);\r
-\r
- // Place zero terminator after value\r
- if (!(Flags & parse_no_string_terminators)) {\r
- Ch ch = *text;\r
- *end = Ch('\0');\r
- return ch; // Return character that ends data; this is required because zero terminator overwritten it\r
- }\r
-\r
- // Return character that ends data\r
- return *text;\r
- }\r
-\r
- // Parse CDATA\r
- template<int Flags>\r
- xml_node<Ch> *parse_cdata(Ch *&text) {\r
- // If CDATA is disabled\r
- if (Flags & parse_no_data_nodes) {\r
- // Skip until end of cdata\r
- while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) {\r
- if (!text[0])\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- ++text;\r
- }\r
- text += 3; // Skip ]]>\r
- return 0; // Do not produce CDATA node\r
- }\r
-\r
- // Skip until end of cdata\r
- Ch *value = text;\r
- while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) {\r
- if (!text[0])\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- ++text;\r
- }\r
-\r
- // Create new cdata node\r
- xml_node<Ch> *cdata = this->allocate_node(node_cdata);\r
- cdata->value(value, text - value);\r
-\r
- // Place zero terminator after value\r
- if (!(Flags & parse_no_string_terminators)) *text = Ch('\0');\r
-\r
- text += 3; // Skip ]]>\r
- return cdata;\r
- }\r
-\r
- // Parse element node\r
- template<int Flags>\r
- xml_node<Ch> *parse_element(Ch *&text) {\r
- // Create element node\r
- xml_node<Ch> *element = this->allocate_node(node_element);\r
-\r
- // Extract element name\r
- Ch *name = text;\r
- skip<node_name_pred, Flags>(text);\r
- if (text == name)\r
- RAPIDXML_PARSE_ERROR("expected element name", text);\r
- element->name(name, text - name);\r
-\r
- // Skip whitespace between element name and attributes or >\r
- skip<whitespace_pred, Flags>(text);\r
-\r
- // Parse attributes, if any\r
- parse_node_attributes<Flags>(text, element);\r
-\r
- // Determine ending type\r
- if (*text == Ch('>')) {\r
- ++text;\r
- parse_node_contents<Flags>(text, element);\r
- } else if (*text == Ch('/')) {\r
- ++text;\r
- if (*text != Ch('>'))\r
- RAPIDXML_PARSE_ERROR("expected >", text);\r
- ++text;\r
- } else\r
- RAPIDXML_PARSE_ERROR("expected >", text);\r
-\r
- // Place zero terminator after name\r
- if (!(Flags & parse_no_string_terminators))\r
- element->name()[element->name_size()] = Ch('\0');\r
-\r
- // Return parsed element\r
- return element;\r
- }\r
-\r
- // Determine node type, and parse it\r
- template<int Flags>\r
- xml_node<Ch> *parse_node(Ch *&text) {\r
- // Parse proper node type\r
- switch (text[0]) {\r
-\r
- // <...\r
- default:\r
- // Parse and append element node\r
- return parse_element<Flags>(text);\r
-\r
- // <?...\r
- case Ch('?'):\r
- ++text; // Skip ?\r
- if ((text[0] == Ch('x') || text[0] == Ch('X'))\r
- && (text[1] == Ch('m') || text[1] == Ch('M'))\r
- && (text[2] == Ch('l') || text[2] == Ch('L'))\r
- && whitespace_pred::test(text[3])) {\r
- // '<?xml ' - xml declaration\r
- text += 4; // Skip 'xml '\r
- return parse_xml_declaration<Flags>(text);\r
- } else {\r
- // Parse PI\r
- return parse_pi<Flags>(text);\r
- }\r
-\r
- // <!...\r
- case Ch('!'):\r
-\r
- // Parse proper subset of <! node\r
- switch (text[1]) {\r
-\r
- // <!-\r
- case Ch('-'):\r
- if (text[2] == Ch('-')) {\r
- // '<!--' - xml comment\r
- text += 3; // Skip '!--'\r
- return parse_comment<Flags>(text);\r
- }\r
- break;\r
-\r
- // <![\r
- case Ch('['):\r
- if (text[2] == Ch('C') && text[3] == Ch('D') && text[4] == Ch('A')\r
- && text[5] == Ch('T') && text[6] == Ch('A')\r
- && text[7] == Ch('[')) {\r
- // '<![CDATA[' - cdata\r
- text += 8; // Skip '![CDATA['\r
- return parse_cdata<Flags>(text);\r
- }\r
- break;\r
-\r
- // <!D\r
- case Ch('D'):\r
- if (text[2] == Ch('O') && text[3] == Ch('C') && text[4] == Ch('T')\r
- && text[5] == Ch('Y') && text[6] == Ch('P')\r
- && text[7] == Ch('E') && whitespace_pred::test(text[8])) {\r
- // '<!DOCTYPE ' - doctype\r
- text += 9; // skip '!DOCTYPE '\r
- return parse_doctype<Flags>(text);\r
- }\r
-\r
- } // switch\r
-\r
- // Attempt to skip other, unrecognized node types starting with <!\r
- ++text; // Skip !\r
- while (*text != Ch('>')) {\r
- if (*text == 0)\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
- ++text;\r
- }\r
- ++text; // Skip '>'\r
- return 0; // No node recognized\r
-\r
- }\r
- }\r
-\r
- // Parse contents of the node - children, data etc.\r
- template<int Flags>\r
- void parse_node_contents(Ch *&text, xml_node<Ch> *node) {\r
- // For all children and text\r
- while (1) {\r
- // Skip whitespace between > and node contents\r
- Ch *contents_start = text; // Store start of node contents before whitespace is skipped\r
- skip<whitespace_pred, Flags>(text);\r
- Ch next_char = *text;\r
-\r
- // After data nodes, instead of continuing the loop, control jumps here.\r
- // This is because zero termination inside parse_and_append_data() function\r
- // would wreak havoc with the above code.\r
- // Also, skipping whitespace after data nodes is unnecessary.\r
- after_data_node:\r
-\r
- // Determine what comes next: node closing, child node, data node, or 0?\r
- switch (next_char) {\r
-\r
- // Node closing or child node\r
- case Ch('<'):\r
- if (text[1] == Ch('/')) {\r
- // Node closing\r
- text += 2; // Skip '</'\r
- if (Flags & parse_validate_closing_tags) {\r
- // Skip and validate closing tag name\r
- Ch *closing_name = text;\r
- skip<node_name_pred, Flags>(text);\r
- if (!internal::compare(node->name(), node->name_size(),\r
- closing_name, text - closing_name, true))\r
- RAPIDXML_PARSE_ERROR("invalid closing tag name", text);\r
- } else {\r
- // No validation, just skip name\r
- skip<node_name_pred, Flags>(text);\r
- }\r
- // Skip remaining whitespace after node name\r
- skip<whitespace_pred, Flags>(text);\r
- if (*text != Ch('>'))\r
- RAPIDXML_PARSE_ERROR("expected >", text);\r
- ++text; // Skip '>'\r
- return; // Node closed, finished parsing contents\r
- } else {\r
- // Child node\r
- ++text; // Skip '<'\r
- if (xml_node<Ch> *child = parse_node<Flags>(text))\r
- node->append_node(child);\r
- }\r
- break;\r
-\r
- // End of data - error\r
- case Ch('\0'):\r
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);\r
-\r
- // Data node\r
- default:\r
- next_char = parse_and_append_data<Flags>(node, text, contents_start);\r
- goto after_data_node;\r
- // Bypass regular processing after data nodes\r
-\r
- }\r
- }\r
- }\r
-\r
- // Parse XML attributes of the node\r
- template<int Flags>\r
- void parse_node_attributes(Ch *&text, xml_node<Ch> *node) {\r
- // For all attributes \r
- while (attribute_name_pred::test(*text)) {\r
- // Extract attribute name\r
- Ch *name = text;\r
- ++text; // Skip first character of attribute name\r
- skip<attribute_name_pred, Flags>(text);\r
- if (text == name)\r
- RAPIDXML_PARSE_ERROR("expected attribute name", name);\r
-\r
- // Create new attribute\r
- xml_attribute<Ch> *attribute = this->allocate_attribute();\r
- attribute->name(name, text - name);\r
- node->append_attribute(attribute);\r
-\r
- // Skip whitespace after attribute name\r
- skip<whitespace_pred, Flags>(text);\r
-\r
- // Skip =\r
- if (*text != Ch('='))\r
- RAPIDXML_PARSE_ERROR("expected =", text);\r
- ++text;\r
-\r
- // Add terminating zero after name\r
- if (!(Flags & parse_no_string_terminators))\r
- attribute->name()[attribute->name_size()] = 0;\r
-\r
- // Skip whitespace after =\r
- skip<whitespace_pred, Flags>(text);\r
-\r
- // Skip quote and remember if it was ' or "\r
- Ch quote = *text;\r
- if (quote != Ch('\'') && quote != Ch('"'))\r
- RAPIDXML_PARSE_ERROR("expected ' or \"", text);\r
- ++text;\r
-\r
- // Extract attribute value and expand char refs in it\r
- Ch *value = text, *end;\r
- const int AttFlags = Flags & ~parse_normalize_whitespace; // No whitespace normalization in attributes\r
- if (quote == Ch('\''))\r
- end = skip_and_expand_character_refs<attribute_value_pred<Ch('\'')>,\r
- attribute_value_pure_pred<Ch('\'')>, AttFlags>(text);\r
- else end = skip_and_expand_character_refs<attribute_value_pred<Ch('"')>,\r
- attribute_value_pure_pred<Ch('"')>, AttFlags>(text);\r
-\r
- // Set attribute value\r
- attribute->value(value, end - value);\r
-\r
- // Make sure that end quote is present\r
- if (*text != quote)\r
- RAPIDXML_PARSE_ERROR("expected ' or \"", text);\r
- ++text; // Skip quote\r
-\r
- // Add terminating zero after value\r
- if (!(Flags & parse_no_string_terminators))\r
- attribute->value()[attribute->value_size()] = 0;\r
-\r
- // Skip whitespace after attribute value\r
- skip<whitespace_pred, Flags>(text);\r
- }\r
- }\r
-\r
-};\r
-\r
-//! \cond internal\r
-namespace internal {\r
-\r
-// Whitespace (space \n \r \t)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_whitespace[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, // 0\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1\r
- 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 7\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // C\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // D\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // E\r
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // F\r
- };\r
-\r
-// Node name (anything but space \n \r \t / > ? \0)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_node_name[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Text (i.e. PCDATA) (anything but < \0)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_text[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Text (i.e. PCDATA) that does not require processing when ws normalization is disabled \r
-// (anything but < \0 &)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_text_pure_no_ws[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Text (i.e. PCDATA) that does not require processing when ws normalizationis is enabled\r
-// (anything but < \0 & space \n \r \t)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_text_pure_with_ws[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Attribute name (anything but space \n \r \t / < > = ? ! \0)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_attribute_name[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Attribute data with single quote (anything but ' \0)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Attribute data with single quote that does not require processing (anything but ' \0 &)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1_pure[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Attribute data with double quote (anything but " \0)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Attribute data with double quote that does not require processing (anything but " \0 &)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2_pure[256] = {\r
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1\r
- 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E\r
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F\r
- };\r
-\r
-// Digits (dec and hex, 255 denotes end of numeric character reference)\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_digits[256] = {\r
- // 0 1 2 3 4 5 6 7 8 9 A B C D E F\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 0\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 1\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 2\r
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255,\r
- 255, // 3\r
- 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 4\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 5\r
- 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 6\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 7\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 8\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // 9\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // A\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // B\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // C\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // D\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255, // E\r
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\r
- 255 // F\r
- };\r
-\r
-// Upper case conversion\r
-template<int Dummy>\r
-const unsigned char lookup_tables<Dummy>::lookup_upcase[256] = {\r
- // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A B C D E F\r
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,\r
- 15, // 0\r
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,\r
- 31, // 1\r
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,\r
- 47, // 2\r
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,\r
- 63, // 3\r
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,\r
- 79, // 4\r
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,\r
- 95, // 5\r
- 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,\r
- 79, // 6\r
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123, 124, 125, 126,\r
- 127, // 7\r
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,\r
- 143, // 8\r
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158,\r
- 159, // 9\r
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,\r
- 175, // A\r
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,\r
- 191, // B\r
- 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206,\r
- 207, // C\r
- 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222,\r
- 223, // D\r
- 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,\r
- 239, // E\r
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,\r
- 255 // F\r
- };\r
-}\r
-//! \endcond\r
-\r
-}\r
-\r
-// Undefine internal macros\r
-#undef RAPIDXML_PARSE_ERROR\r
-\r
-// On MSVC, restore warnings state\r
-#ifdef _MSC_VER\r
-#pragma warning(pop)\r
-#endif\r
-\r
-#endif\r
+++ /dev/null
-#ifndef RAPIDXML_ITERATORS_HPP_INCLUDED\r
-#define RAPIDXML_ITERATORS_HPP_INCLUDED\r
-\r
-// Copyright (C) 2006, 2009 Marcin Kalicinski\r
-// Version 1.13\r
-// Revision $DateTime: 2009/05/13 01:46:17 $\r
-//! \file rapidxml_iterators.hpp This file contains rapidxml iterators\r
-\r
-#include "rapidxml.hpp"\r
-\r
-namespace rapidxml {\r
-\r
-//! Iterator of child nodes of xml_node\r
-template<class Ch>\r
-class node_iterator {\r
-\r
-public:\r
-\r
- typedef typename xml_node<Ch> value_type;\r
- typedef typename xml_node<Ch> &reference;\r
- typedef typename xml_node<Ch> *pointer;\r
- typedef std::ptrdiff_t difference_type;\r
- typedef std::bidirectional_iterator_tag iterator_category;\r
-\r
- node_iterator() :\r
- m_node(0) {\r
- }\r
-\r
- node_iterator(xml_node<Ch> *node) :\r
- m_node(node->first_node()) {\r
- }\r
-\r
- reference operator *() const {\r
- assert(m_node);\r
- return *m_node;\r
- }\r
-\r
- pointer operator->() const {\r
- assert(m_node);\r
- return m_node;\r
- }\r
-\r
- node_iterator& operator++() {\r
- assert(m_node);\r
- m_node = m_node->next_sibling();\r
- return *this;\r
- }\r
-\r
- node_iterator operator++(int) {\r
- node_iterator tmp = *this;\r
- ++this;\r
- return tmp;\r
- }\r
-\r
- node_iterator& operator--() {\r
- assert(m_node && m_node->previous_sibling());\r
- m_node = m_node->previous_sibling();\r
- return *this;\r
- }\r
-\r
- node_iterator operator--(int) {\r
- node_iterator tmp = *this;\r
- ++this;\r
- return tmp;\r
- }\r
-\r
- bool operator ==(const node_iterator<Ch> &rhs) {\r
- return m_node == rhs.m_node;\r
- }\r
-\r
- bool operator !=(const node_iterator<Ch> &rhs) {\r
- return m_node != rhs.m_node;\r
- }\r
-\r
-private:\r
-\r
- xml_node<Ch> *m_node;\r
-\r
-};\r
-\r
-//! Iterator of child attributes of xml_node\r
-template<class Ch>\r
-class attribute_iterator {\r
-\r
-public:\r
-\r
- typedef typename xml_attribute<Ch> value_type;\r
- typedef typename xml_attribute<Ch> &reference;\r
- typedef typename xml_attribute<Ch> *pointer;\r
- typedef std::ptrdiff_t difference_type;\r
- typedef std::bidirectional_iterator_tag iterator_category;\r
-\r
- attribute_iterator() :\r
- m_attribute(0) {\r
- }\r
-\r
- attribute_iterator(xml_node<Ch> *node) :\r
- m_attribute(node->first_attribute()) {\r
- }\r
-\r
- reference operator *() const {\r
- assert(m_attribute);\r
- return *m_attribute;\r
- }\r
-\r
- pointer operator->() const {\r
- assert(m_attribute);\r
- return m_attribute;\r
- }\r
-\r
- attribute_iterator& operator++() {\r
- assert(m_attribute);\r
- m_attribute = m_attribute->next_attribute();\r
- return *this;\r
- }\r
-\r
- attribute_iterator operator++(int) {\r
- attribute_iterator tmp = *this;\r
- ++this;\r
- return tmp;\r
- }\r
-\r
- attribute_iterator& operator--() {\r
- assert(m_attribute && m_attribute->previous_attribute());\r
- m_attribute = m_attribute->previous_attribute();\r
- return *this;\r
- }\r
-\r
- attribute_iterator operator--(int) {\r
- attribute_iterator tmp = *this;\r
- ++this;\r
- return tmp;\r
- }\r
-\r
- bool operator ==(const attribute_iterator<Ch> &rhs) {\r
- return m_attribute == rhs.m_attribute;\r
- }\r
-\r
- bool operator !=(const attribute_iterator<Ch> &rhs) {\r
- return m_attribute != rhs.m_attribute;\r
- }\r
-\r
-private:\r
-\r
- xml_attribute<Ch> *m_attribute;\r
-\r
-};\r
-\r
-}\r
-\r
-#endif\r
+++ /dev/null
-#ifndef RAPIDXML_PRINT_HPP_INCLUDED\r
-#define RAPIDXML_PRINT_HPP_INCLUDED\r
-\r
-// Copyright (C) 2006, 2009 Marcin Kalicinski\r
-// Version 1.13\r
-// Revision $DateTime: 2009/05/13 01:46:17 $\r
-//! \file rapidxml_print.hpp This file contains rapidxml printer implementation\r
-\r
-#include "rapidxml.hpp"\r
-\r
-// Only include streams if not disabled\r
-#ifndef RAPIDXML_NO_STREAMS\r
-#include <ostream>\r
-#include <iterator>\r
-#endif\r
-\r
-namespace rapidxml {\r
-\r
-///////////////////////////////////////////////////////////////////////\r
-// Printing flags\r
-\r
-const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function.\r
-\r
-///////////////////////////////////////////////////////////////////////\r
-// Internal\r
-\r
-//! \cond internal\r
-namespace internal {\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// Internal character operations\r
-\r
-// Copy characters from given range to given output iterator\r
-template<class OutIt, class Ch>\r
-inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out) {\r
- while (begin != end)\r
- *out++ = *begin++;\r
- return out;\r
-}\r
-\r
-// Copy characters from given range to given output iterator and expand\r
-// characters into references (< > ' " &)\r
-template<class OutIt, class Ch>\r
-inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand,\r
- OutIt out) {\r
- while (begin != end) {\r
- if (*begin == noexpand) {\r
- *out++ = *begin; // No expansion, copy character\r
- } else {\r
- switch (*begin) {\r
- case Ch('<'):\r
- *out++ = Ch('&');\r
- *out++ = Ch('l');\r
- *out++ = Ch('t');\r
- *out++ = Ch(';');\r
- break;\r
- case Ch('>'):\r
- *out++ = Ch('&');\r
- *out++ = Ch('g');\r
- *out++ = Ch('t');\r
- *out++ = Ch(';');\r
- break;\r
- case Ch('\''):\r
- *out++ = Ch('&');\r
- *out++ = Ch('a');\r
- *out++ = Ch('p');\r
- *out++ = Ch('o');\r
- *out++ = Ch('s');\r
- *out++ = Ch(';');\r
- break;\r
- case Ch('"'):\r
- *out++ = Ch('&');\r
- *out++ = Ch('q');\r
- *out++ = Ch('u');\r
- *out++ = Ch('o');\r
- *out++ = Ch('t');\r
- *out++ = Ch(';');\r
- break;\r
- case Ch('&'):\r
- *out++ = Ch('&');\r
- *out++ = Ch('a');\r
- *out++ = Ch('m');\r
- *out++ = Ch('p');\r
- *out++ = Ch(';');\r
- break;\r
- default:\r
- *out++ = *begin; // No expansion, copy character\r
- }\r
- }\r
- ++begin; // Step to next character\r
- }\r
- return out;\r
-}\r
-\r
-// Fill given output iterator with repetitions of the same character\r
-template<class OutIt, class Ch>\r
-inline OutIt fill_chars(OutIt out, int n, Ch ch) {\r
- for (int i = 0; i < n; ++i)\r
- *out++ = ch;\r
- return out;\r
-}\r
-\r
-// Find character\r
-template<class Ch, Ch ch>\r
-inline bool find_char(const Ch *begin, const Ch *end) {\r
- while (begin != end)\r
- if (*begin++ == ch) return true;\r
- return false;\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// Internal printing operations\r
-\r
-// Print node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags,\r
- int indent) {\r
- // Print proper node type\r
- switch (node->type()) {\r
-\r
- // Document\r
- case node_document:\r
- out = print_children(out, node, flags, indent);\r
- break;\r
-\r
- // Element\r
- case node_element:\r
- out = print_element_node(out, node, flags, indent);\r
- break;\r
-\r
- // Data\r
- case node_data:\r
- out = print_data_node(out, node, flags, indent);\r
- break;\r
-\r
- // CDATA\r
- case node_cdata:\r
- out = print_cdata_node(out, node, flags, indent);\r
- break;\r
-\r
- // Declaration\r
- case node_declaration:\r
- out = print_declaration_node(out, node, flags, indent);\r
- break;\r
-\r
- // Comment\r
- case node_comment:\r
- out = print_comment_node(out, node, flags, indent);\r
- break;\r
-\r
- // Doctype\r
- case node_doctype:\r
- out = print_doctype_node(out, node, flags, indent);\r
- break;\r
-\r
- // Pi\r
- case node_pi:\r
- out = print_pi_node(out, node, flags, indent);\r
- break;\r
-\r
- // Unknown\r
- default:\r
- assert(0);\r
- break;\r
- }\r
-\r
- // If indenting not disabled, add line break after node\r
- if (!(flags & print_no_indenting)) *out = Ch('\n'), ++out;\r
-\r
- // Return modified iterator\r
- return out;\r
-}\r
-\r
-// Print children of the node \r
-template<class OutIt, class Ch>\r
-inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags,\r
- int indent) {\r
- for (xml_node<Ch> *child = node->first_node(); child;\r
- child = child->next_sibling())\r
- out = print_node(out, child, flags, indent);\r
- return out;\r
-}\r
-\r
-// Print attributes of the node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags) {\r
- for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute;\r
- attribute = attribute->next_attribute()) {\r
- if (attribute->name() && attribute->value()) {\r
- // Print attribute name\r
- *out = Ch(' '), ++out;\r
- out = copy_chars(attribute->name(),\r
- attribute->name() + attribute->name_size(), out);\r
- *out = Ch('='), ++out;\r
- // Print attribute value using appropriate quote type\r
- if (find_char<Ch, Ch('"')>(attribute->value(),\r
- attribute->value() + attribute->value_size())) {\r
- *out = Ch('\''), ++out;\r
- out = copy_and_expand_chars(attribute->value(),\r
- attribute->value() + attribute->value_size(), Ch('"'), out);\r
- *out = Ch('\''), ++out;\r
- } else {\r
- *out = Ch('"'), ++out;\r
- out = copy_and_expand_chars(attribute->value(),\r
- attribute->value() + attribute->value_size(), Ch('\''), out);\r
- *out = Ch('"'), ++out;\r
- }\r
- }\r
- }\r
- return out;\r
-}\r
-\r
-// Print data node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags,\r
- int indent) {\r
- assert(node->type() == node_data);\r
- if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t'));\r
- out = copy_and_expand_chars(node->value(), node->value() + node->value_size(),\r
- Ch(0), out);\r
- return out;\r
-}\r
-\r
-// Print data node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags,\r
- int indent) {\r
- assert(node->type() == node_cdata);\r
- if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t'));\r
- *out = Ch('<');\r
- ++out;\r
- *out = Ch('!');\r
- ++out;\r
- *out = Ch('[');\r
- ++out;\r
- *out = Ch('C');\r
- ++out;\r
- *out = Ch('D');\r
- ++out;\r
- *out = Ch('A');\r
- ++out;\r
- *out = Ch('T');\r
- ++out;\r
- *out = Ch('A');\r
- ++out;\r
- *out = Ch('[');\r
- ++out;\r
- out = copy_chars(node->value(), node->value() + node->value_size(), out);\r
- *out = Ch(']');\r
- ++out;\r
- *out = Ch(']');\r
- ++out;\r
- *out = Ch('>');\r
- ++out;\r
- return out;\r
-}\r
-\r
-// Print element node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags,\r
- int indent) {\r
- assert(node->type() == node_element);\r
-\r
- // Print element name and attributes, if any\r
- if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t'));\r
- *out = Ch('<'), ++out;\r
- out = copy_chars(node->name(), node->name() + node->name_size(), out);\r
- out = print_attributes(out, node, flags);\r
-\r
- // If node is childless\r
- if (node->value_size() == 0 && !node->first_node()) {\r
- // Print childless node tag ending\r
- *out = Ch('/'), ++out;\r
- *out = Ch('>'), ++out;\r
- } else {\r
- // Print normal node tag ending\r
- *out = Ch('>'), ++out;\r
-\r
- // Test if node contains a single data node only (and no other nodes)\r
- xml_node<Ch> *child = node->first_node();\r
- if (!child) {\r
- // If node has no children, only print its value without indenting\r
- out = copy_and_expand_chars(node->value(),\r
- node->value() + node->value_size(), Ch(0), out);\r
- } else if (child->next_sibling() == 0 && child->type() == node_data) {\r
- // If node has a sole data child, only print its value without indenting\r
- out = copy_and_expand_chars(child->value(),\r
- child->value() + child->value_size(), Ch(0), out);\r
- } else {\r
- // Print all children with full indenting\r
- if (!(flags & print_no_indenting)) *out = Ch('\n'), ++out;\r
- out = print_children(out, node, flags, indent + 1);\r
- if (!(flags & print_no_indenting))\r
- out = fill_chars(out, indent, Ch('\t'));\r
- }\r
-\r
- // Print node end\r
- *out = Ch('<'), ++out;\r
- *out = Ch('/'), ++out;\r
- out = copy_chars(node->name(), node->name() + node->name_size(), out);\r
- *out = Ch('>'), ++out;\r
- }\r
- return out;\r
-}\r
-\r
-// Print declaration node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node,\r
- int flags, int indent) {\r
- // Print declaration start\r
- if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t'));\r
- *out = Ch('<'), ++out;\r
- *out = Ch('?'), ++out;\r
- *out = Ch('x'), ++out;\r
- *out = Ch('m'), ++out;\r
- *out = Ch('l'), ++out;\r
-\r
- // Print attributes\r
- out = print_attributes(out, node, flags);\r
-\r
- // Print declaration end\r
- *out = Ch('?'), ++out;\r
- *out = Ch('>'), ++out;\r
-\r
- return out;\r
-}\r
-\r
-// Print comment node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags,\r
- int indent) {\r
- assert(node->type() == node_comment);\r
- if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t'));\r
- *out = Ch('<'), ++out;\r
- *out = Ch('!'), ++out;\r
- *out = Ch('-'), ++out;\r
- *out = Ch('-'), ++out;\r
- out = copy_chars(node->value(), node->value() + node->value_size(), out);\r
- *out = Ch('-'), ++out;\r
- *out = Ch('-'), ++out;\r
- *out = Ch('>'), ++out;\r
- return out;\r
-}\r
-\r
-// Print doctype node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags,\r
- int indent) {\r
- assert(node->type() == node_doctype);\r
- if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t'));\r
- *out = Ch('<'), ++out;\r
- *out = Ch('!'), ++out;\r
- *out = Ch('D'), ++out;\r
- *out = Ch('O'), ++out;\r
- *out = Ch('C'), ++out;\r
- *out = Ch('T'), ++out;\r
- *out = Ch('Y'), ++out;\r
- *out = Ch('P'), ++out;\r
- *out = Ch('E'), ++out;\r
- *out = Ch(' '), ++out;\r
- out = copy_chars(node->value(), node->value() + node->value_size(), out);\r
- *out = Ch('>'), ++out;\r
- return out;\r
-}\r
-\r
-// Print pi node\r
-template<class OutIt, class Ch>\r
-inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags,\r
- int indent) {\r
- assert(node->type() == node_pi);\r
- if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t'));\r
- *out = Ch('<'), ++out;\r
- *out = Ch('?'), ++out;\r
- out = copy_chars(node->name(), node->name() + node->name_size(), out);\r
- *out = Ch(' '), ++out;\r
- out = copy_chars(node->value(), node->value() + node->value_size(), out);\r
- *out = Ch('?'), ++out;\r
- *out = Ch('>'), ++out;\r
- return out;\r
-}\r
-\r
-}\r
-//! \endcond\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// Printing\r
-\r
-//! Prints XML to given output iterator.\r
-//! \param out Output iterator to print to.\r
-//! \param node Node to be printed. Pass xml_document to print entire document.\r
-//! \param flags Flags controlling how XML is printed.\r
-//! \return Output iterator pointing to position immediately after last character of printed text.\r
-template<class OutIt, class Ch>\r
-inline OutIt print(OutIt out, const xml_node<Ch> &node, int flags = 0) {\r
- return internal::print_node(out, &node, flags, 0);\r
-}\r
-\r
-#ifndef RAPIDXML_NO_STREAMS\r
-\r
-//! Prints XML to given output stream.\r
-//! \param out Output stream to print to.\r
-//! \param node Node to be printed. Pass xml_document to print entire document.\r
-//! \param flags Flags controlling how XML is printed.\r
-//! \return Output stream.\r
-template<class Ch>\r
-inline std::basic_ostream<Ch> &print(std::basic_ostream<Ch> &out,\r
- const xml_node<Ch> &node, int flags = 0) {\r
- print(std::ostream_iterator < Ch > (out), node, flags);\r
- return out;\r
-}\r
-\r
-//! Prints formatted XML to given output stream. Uses default printing flags. Use print() function to customize printing process.\r
-//! \param out Output stream to print to.\r
-//! \param node Node to be printed.\r
-//! \return Output stream.\r
-template<class Ch>\r
-inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out,\r
- const xml_node<Ch> &node) {\r
- return print(out, node);\r
-}\r
-\r
-#endif\r
-\r
-}\r
-\r
-#endif\r
+++ /dev/null
-#ifndef RAPIDXML_UTILS_HPP_INCLUDED\r
-#define RAPIDXML_UTILS_HPP_INCLUDED\r
-\r
-// Copyright (C) 2006, 2009 Marcin Kalicinski\r
-// Version 1.13\r
-// Revision $DateTime: 2009/05/13 01:46:17 $\r
-//! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful\r
-//! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective.\r
-\r
-#include "rapidxml.hpp"\r
-#include <vector>\r
-#include <string>\r
-#include <fstream>\r
-#include <stdexcept>\r
-\r
-namespace rapidxml {\r
-\r
-//! Represents data loaded from a file\r
-template<class Ch = char>\r
-class file {\r
-\r
-public:\r
-\r
- //! Loads file into the memory. Data will be automatically destroyed by the destructor.\r
- //! \param filename Filename to load.\r
- file(const char *filename) {\r
- using namespace std;\r
-\r
- // Open stream\r
- basic_ifstream<Ch> stream(filename, ios::binary);\r
- if (!stream) throw runtime_error(string("cannot open file ") + filename);\r
- stream.unsetf(ios::skipws);\r
-\r
- // Determine stream size\r
- stream.seekg(0, ios::end);\r
- size_t size = stream.tellg();\r
- stream.seekg(0);\r
-\r
- // Load data and add terminating 0\r
- m_data.resize(size + 1);\r
- stream.read(&m_data.front(), static_cast<streamsize>(size));\r
- m_data[size] = 0;\r
- }\r
-\r
- //! Loads file into the memory. Data will be automatically destroyed by the destructor\r
- //! \param stream Stream to load from\r
- file(std::basic_istream<Ch> &stream) {\r
- using namespace std;\r
-\r
- // Load data and add terminating 0\r
- stream.unsetf(ios::skipws);\r
- m_data.assign(istreambuf_iterator < Ch > (stream),\r
- istreambuf_iterator<Ch>());\r
- if (stream.fail() || stream.bad())\r
- throw runtime_error("error reading stream");\r
- m_data.push_back(0);\r
- }\r
-\r
- //! Gets file data.\r
- //! \return Pointer to data of file.\r
- Ch *data() {\r
- return &m_data.front();\r
- }\r
-\r
- //! Gets file data.\r
- //! \return Pointer to data of file.\r
- const Ch *data() const {\r
- return &m_data.front();\r
- }\r
-\r
- //! Gets file data size.\r
- //! \return Size of file data, in characters.\r
- std::size_t size() const {\r
- return m_data.size();\r
- }\r
-\r
-private:\r
-\r
- std::vector<Ch> m_data; // File data\r
-\r
-};\r
-\r
-//! Counts children of node. Time complexity is O(n).\r
-//! \return Number of children of node\r
-template<class Ch>\r
-inline std::size_t count_children(xml_node<Ch> *node) {\r
- xml_node<Ch> *child = node->first_node();\r
- std::size_t count = 0;\r
- while (child) {\r
- ++count;\r
- child = child->next_sibling();\r
- }\r
- return count;\r
-}\r
-\r
-//! Counts attributes of node. Time complexity is O(n).\r
-//! \return Number of attributes of node\r
-template<class Ch>\r
-inline std::size_t count_attributes(xml_node<Ch> *node) {\r
- xml_attribute<Ch> *attr = node->first_attribute();\r
- std::size_t count = 0;\r
- while (attr) {\r
- ++count;\r
- attr = attr->next_attribute();\r
- }\r
- return count;\r
-}\r
-\r
-}\r
-\r
-#endif\r
--- /dev/null
+Unless it has its own copyright/license embedded in its body, each source file
+is subject to the following license terms:
+
+Copyright (c) 2015, Linaro Limited
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+/*
+ * Copyright (c) 2014, STMicroelectronics International N.V.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
/**
* Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved
*
Version: 0.0.1
Release: 1
Group: Security
-License: Apache-2.0 and BSD-3-Clause
+License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
ExcludeArch: armv6l armv7hl armv7l aarch64
BuildRequires: cmake
%postun
%files -n %{name}
+%license LICENSE
%attr(111,security_fw,security_fw) %{bin_dir}/tef-simulator-helloworld
%attr(444,security_fw,security_fw) %{tastore_dir}/00000000000000000000112233445566
Version: 0.0.1
Release: 1
Group: Security
-License: Apache-2.0
+License: Apache-2.0 and MIT and BSD
Source0: %{name}-%{version}.tar.gz
Source1: %{name}.manifest
ExcludeArch: armv6l armv7hl armv7l aarch64
%install
make install
+cp rapidxml/license.txt LICENSE.MIT
+cp include/include/LICENSE LICENSE.BSD
%pre
fi
%files -n %{name}
+%license LICENSE
+%license LICENSE.MIT
%manifest tef-simulator.manifest
%attr(111,security_fw,security_fw) %{bin_dir}/tef-simulator-daemon
%{lib_dir}/libtef-simulator-ssflib.so
%attr(755,security_fw,security_fw) %{lib_dir}/tef/simulator/libteec.so
%files -n %{name}-devkit
+%license LICENSE
+%license LICENSE.MIT
+%license LICENSE.BSD
%{bin_dir}/TA_PackageBuilder.sh
%{bin_dir}/TAPackageMaker
%{lib_dir}/libTEEStub.a
--- /dev/null
+Copyright (c) 2006, 2007 Marcin Kalicinski
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
\ No newline at end of file
//! <pre>
//! void %rapidxml::%parse_error_handler(const char *what, void *where)
//! {
- //! LOGD(SIM_DAEMON, "Parse error: %s", what);
+ //! std::cout << "Parse error: " << what << "\n";
//! std::abort();
//! }
//! </pre>
)
INCLUDE_DIRECTORIES(
+ ${TEF_SIMULATOR_ROOT_PATH}
${DAEMON_PATH}/inc
${DAEMON_PATH}/inc/ClientCommands
${DAEMON_PATH}/inc/ResponseCommands
+++ /dev/null
-#ifndef RAPIDXML_HPP_INCLUDED
-#define RAPIDXML_HPP_INCLUDED
-
-// Copyright (C) 2006, 2009 Marcin Kalicinski
-// Version 1.13
-// Revision $DateTime: 2009/05/13 01:46:17 $
-//! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation
-
-// If standard library is disabled, user must provide implementations of required functions and typedefs
-#if !defined(RAPIDXML_NO_STDLIB)
-#include <cstdlib> // For std::size_t
-#include <cassert> // For assert
-#include <new> // For placement new
-#endif
-
-// On MSVC, disable "conditional expression is constant" warning (level 4).
-// This warning is almost impossible to avoid with certain types of templated code
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable:4127) // Conditional expression is constant
-#endif
-
-///////////////////////////////////////////////////////////////////////////
-// RAPIDXML_PARSE_ERROR
-
-#if defined(RAPIDXML_NO_EXCEPTIONS)
-
-#define RAPIDXML_PARSE_ERROR(what, where) { parse_error_handler(what, where); assert(0); }
-
-namespace rapidxml
-{
- //! When exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS,
- //! this function is called to notify user about the error.
- //! It must be defined by the user.
- //! <br><br>
- //! This function cannot return. If it does, the results are undefined.
- //! <br><br>
- //! A very simple definition might look like that:
- //! <pre>
- //! void %rapidxml::%parse_error_handler(const char *what, void *where)
- //! {
- //! LOGE(SIM_DAEMON, "Parse error: %s", what);
- //! std::abort();
- //! }
- //! </pre>
- //! \param what Human readable description of the error.
- //! \param where Pointer to character data where error was detected.
- void parse_error_handler(const char *what, void *where);
-}
-
-#else
-
-#include <exception> // For std::exception
-
-#define RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where)
-
-namespace rapidxml {
-
-//! Parse error exception.
-//! This exception is thrown by the parser when an error occurs.
-//! Use what() function to get human-readable error message.
-//! Use where() function to get a pointer to position within source text where error was detected.
-//! <br><br>
-//! If throwing exceptions by the parser is undesirable,
-//! it can be disabled by defining RAPIDXML_NO_EXCEPTIONS macro before rapidxml.hpp is included.
-//! This will cause the parser to call rapidxml::parse_error_handler() function instead of throwing an exception.
-//! This function must be defined by the user.
-//! <br><br>
-//! This class derives from <code>std::exception</code> class.
-class parse_error:
- public std::exception {
-
-public:
-
- //! Constructs parse error
- parse_error(const char *what, void *where) :
- m_what(what), m_where(where) {
- }
-
- //! Gets human readable description of error.
- //! \return Pointer to null terminated description of the error.
- virtual const char *what() const throw () {
- return m_what;
- }
-
- //! Gets pointer to character data where error happened.
- //! Ch should be the same as char type of xml_document that produced the error.
- //! \return Pointer to location within the parsed string where error occured.
- template<class Ch>
- Ch *where() const {
- return reinterpret_cast<Ch *>(m_where);
- }
-
-private:
-
- const char *m_what;
- void *m_where;
-
-};
-}
-
-#endif
-
-///////////////////////////////////////////////////////////////////////////
-// Pool sizes
-
-#ifndef RAPIDXML_STATIC_POOL_SIZE
-// Size of static memory block of memory_pool.
-// Define RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
-// No dynamic memory allocations are performed by memory_pool until static memory is exhausted.
-#define RAPIDXML_STATIC_POOL_SIZE (64 * 1024)
-#endif
-
-#ifndef RAPIDXML_DYNAMIC_POOL_SIZE
-// Size of dynamic memory block of memory_pool.
-// Define RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
-// After the static block is exhausted, dynamic blocks with approximately this size are allocated by memory_pool.
-#define RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024)
-#endif
-
-#ifndef RAPIDXML_ALIGNMENT
-// Memory allocation alignment.
-// Define RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer.
-// All memory allocations for nodes, attributes and strings will be aligned to this value.
-// This must be a power of 2 and at least 1, otherwise memory_pool will not work.
-#define RAPIDXML_ALIGNMENT sizeof(void *)
-#endif
-
-namespace rapidxml {
-// Forward declarations
-template<class Ch> class xml_node;
-template<class Ch> class xml_attribute;
-template<class Ch> class xml_document;
-
-//! Enumeration listing all node types produced by the parser.
-//! Use xml_node::type() function to query node type.
-enum node_type {
- node_document, //!< A document node. Name and value are empty.
- node_element, //!< An element node. Name contains element name. Value contains text of first data node.
- node_data, //!< A data node. Name is empty. Value contains data text.
- node_cdata, //!< A CDATA node. Name is empty. Value contains data text.
- node_comment, //!< A comment node. Name is empty. Value contains comment text.
- node_declaration, //!< A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes.
- node_doctype, //!< A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
- node_pi //!< A PI node. Name contains target. Value contains instructions.
-};
-
-///////////////////////////////////////////////////////////////////////
-// Parsing flags
-
-//! Parse flag instructing the parser to not create data nodes.
-//! Text of first data node will still be placed in value of parent element, unless rapidxml::parse_no_element_values flag is also specified.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_no_data_nodes = 0x1;
-
-//! Parse flag instructing the parser to not use text of first data node as a value of parent element.
-//! Can be combined with other flags by use of | operator.
-//! Note that child data nodes of element node take precendence over its value when printing.
-//! That is, if element has one or more child data nodes <em>and</em> a value, the value will be ignored.
-//! Use rapidxml::parse_no_data_nodes flag to prevent creation of data nodes if you want to manipulate data using values of elements.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_no_element_values = 0x2;
-
-//! Parse flag instructing the parser to not place zero terminators after strings in the source text.
-//! By default zero terminators are placed, modifying source text.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_no_string_terminators = 0x4;
-
-//! Parse flag instructing the parser to not translate entities in the source text.
-//! By default entities are translated, modifying source text.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_no_entity_translation = 0x8;
-
-//! Parse flag instructing the parser to disable UTF-8 handling and assume plain 8 bit characters.
-//! By default, UTF-8 handling is enabled.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_no_utf8 = 0x10;
-
-//! Parse flag instructing the parser to create XML declaration node.
-//! By default, declaration node is not created.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_declaration_node = 0x20;
-
-//! Parse flag instructing the parser to create comments nodes.
-//! By default, comment nodes are not created.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_comment_nodes = 0x40;
-
-//! Parse flag instructing the parser to create DOCTYPE node.
-//! By default, doctype node is not created.
-//! Although W3C specification allows at most one DOCTYPE node, RapidXml will silently accept documents with more than one.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_doctype_node = 0x80;
-
-//! Parse flag instructing the parser to create PI nodes.
-//! By default, PI nodes are not created.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_pi_nodes = 0x100;
-
-//! Parse flag instructing the parser to validate closing tag names.
-//! If not set, name inside closing tag is irrelevant to the parser.
-//! By default, closing tags are not validated.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_validate_closing_tags = 0x200;
-
-//! Parse flag instructing the parser to trim all leading and trailing whitespace of data nodes.
-//! By default, whitespace is not trimmed.
-//! This flag does not cause the parser to modify source text.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_trim_whitespace = 0x400;
-
-//! Parse flag instructing the parser to condense all whitespace runs of data nodes to a single space character.
-//! Trimming of leading and trailing whitespace of data is controlled by rapidxml::parse_trim_whitespace flag.
-//! By default, whitespace is not normalized.
-//! If this flag is specified, source text will be modified.
-//! Can be combined with other flags by use of | operator.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_normalize_whitespace = 0x800;
-
-// Compound flags
-
-//! Parse flags which represent default behaviour of the parser.
-//! This is always equal to 0, so that all other flags can be simply ored together.
-//! Normally there is no need to inconveniently disable flags by anding with their negated (~) values.
-//! This also means that meaning of each flag is a <i>negation</i> of the default setting.
-//! For example, if flag name is rapidxml::parse_no_utf8, it means that utf-8 is <i>enabled</i> by default,
-//! and using the flag will disable it.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_default = 0;
-
-//! A combination of parse flags that forbids any modifications of the source text.
-//! This also results in faster parsing. However, note that the following will occur:
-//! <ul>
-//! <li>names and values of nodes will not be zero terminated, you have to use xml_base::name_size() and xml_base::value_size() functions to determine where name and value ends</li>
-//! <li>entities will not be translated</li>
-//! <li>whitespace will not be normalized</li>
-//! </ul>
-//! See xml_document::parse() function.
-const int parse_non_destructive = parse_no_string_terminators
- | parse_no_entity_translation;
-
-//! A combination of parse flags resulting in fastest possible parsing, without sacrificing important data.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_fastest = parse_non_destructive | parse_no_data_nodes;
-
-//! A combination of parse flags resulting in largest amount of data being extracted.
-//! This usually results in slowest parsing.
-//! <br><br>
-//! See xml_document::parse() function.
-const int parse_full = parse_declaration_node | parse_comment_nodes
- | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags;
-
-///////////////////////////////////////////////////////////////////////
-// Internals
-
-//! \cond internal
-namespace internal {
-
-// Struct that contains lookup tables for the parser
-// It must be a template to allow correct linking (because it has static data members, which are defined in a header file).
-template<int Dummy>
-struct lookup_tables {
- static const unsigned char lookup_whitespace[256]; // Whitespace table
- static const unsigned char lookup_node_name[256]; // Node name table
- static const unsigned char lookup_text[256]; // Text table
- static const unsigned char lookup_text_pure_no_ws[256]; // Text table
- static const unsigned char lookup_text_pure_with_ws[256]; // Text table
- static const unsigned char lookup_attribute_name[256]; // Attribute name table
- static const unsigned char lookup_attribute_data_1[256]; // Attribute data table with single quote
- static const unsigned char lookup_attribute_data_1_pure[256]; // Attribute data table with single quote
- static const unsigned char lookup_attribute_data_2[256]; // Attribute data table with double quotes
- static const unsigned char lookup_attribute_data_2_pure[256]; // Attribute data table with double quotes
- static const unsigned char lookup_digits[256]; // Digits
- static const unsigned char lookup_upcase[256]; // To uppercase conversion table for ASCII characters
-};
-
-// Find length of the string
-template<class Ch>
-inline std::size_t measure(const Ch *p) {
- const Ch *tmp = p;
- while (*tmp)
- ++tmp;
- return tmp - p;
-}
-
-// Compare strings for equality
-template<class Ch>
-inline bool compare(const Ch *p1, std::size_t size1, const Ch *p2,
- std::size_t size2, bool case_sensitive) {
- if (size1 != size2) return false;
- if (case_sensitive) {
- for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
- if (*p1 != *p2) return false;
- } else {
- for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
- if (lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p1)]
- != lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p2)])
- return false;
- }
- return true;
-}
-}
-//! \endcond
-
-///////////////////////////////////////////////////////////////////////
-// Memory pool
-
-//! This class is used by the parser to create new nodes and attributes, without overheads of dynamic memory allocation.
-//! In most cases, you will not need to use this class directly.
-//! However, if you need to create nodes manually or modify names/values of nodes,
-//! you are encouraged to use memory_pool of relevant xml_document to allocate the memory.
-//! Not only is this faster than allocating them by using <code>new</code> operator,
-//! but also their lifetime will be tied to the lifetime of document,
-//! possibly simplyfing memory management.
-//! <br><br>
-//! Call allocate_node() or allocate_attribute() functions to obtain new nodes or attributes from the pool.
-//! You can also call allocate_string() function to allocate strings.
-//! Such strings can then be used as names or values of nodes without worrying about their lifetime.
-//! Note that there is no <code>free()</code> function -- all allocations are freed at once when clear() function is called,
-//! or when the pool is destroyed.
-//! <br><br>
-//! It is also possible to create a standalone memory_pool, and use it
-//! to allocate nodes, whose lifetime will not be tied to any document.
-//! <br><br>
-//! Pool maintains <code>RAPIDXML_STATIC_POOL_SIZE</code> bytes of statically allocated memory.
-//! Until static memory is exhausted, no dynamic memory allocations are done.
-//! When static memory is exhausted, pool allocates additional blocks of memory of size <code>RAPIDXML_DYNAMIC_POOL_SIZE</code> each,
-//! by using global <code>new[]</code> and <code>delete[]</code> operators.
-//! This behaviour can be changed by setting custom allocation routines.
-//! Use set_allocator() function to set them.
-//! <br><br>
-//! Allocations for nodes, attributes and strings are aligned at <code>RAPIDXML_ALIGNMENT</code> bytes.
-//! This value defaults to the size of pointer on target architecture.
-//! <br><br>
-//! To obtain absolutely top performance from the parser,
-//! it is important that all nodes are allocated from a single, contiguous block of memory.
-//! Otherwise, cache misses when jumping between two (or more) disjoint blocks of memory can slow down parsing quite considerably.
-//! If required, you can tweak <code>RAPIDXML_STATIC_POOL_SIZE</code>, <code>RAPIDXML_DYNAMIC_POOL_SIZE</code> and <code>RAPIDXML_ALIGNMENT</code>
-//! to obtain best wasted memory to performance compromise.
-//! To do it, define their values before rapidxml.hpp file is included.
-//! \param Ch Character type of created nodes.
-template<class Ch = char>
-class memory_pool {
-
-public:
-
- //! \cond internal
- typedef void *(alloc_func)(std::size_t); // Type of user-defined function used to allocate memory
- typedef void (free_func)(void *); // Type of user-defined function used to free memory
- //! \endcond
-
- //! Constructs empty pool with default allocator functions.
- memory_pool() :
- m_alloc_func(0), m_free_func(0) {
- init();
- }
-
- //! Destroys pool and frees all the memory.
- //! This causes memory occupied by nodes allocated by the pool to be freed.
- //! Nodes allocated from the pool are no longer valid.
- ~memory_pool() {
- clear();
- }
-
- //! Allocates a new node from the pool, and optionally assigns name and value to it.
- //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
- //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
- //! will call rapidxml::parse_error_handler() function.
- //! \param type Type of node to create.
- //! \param name Name to assign to the node, or 0 to assign no name.
- //! \param value Value to assign to the node, or 0 to assign no value.
- //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
- //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
- //! \return Pointer to allocated node. This pointer will never be NULL.
- xml_node<Ch> *allocate_node(node_type type, const Ch *name = 0,
- const Ch *value = 0, std::size_t name_size = 0,
- std::size_t value_size = 0) {
- void *memory = allocate_aligned(sizeof(xml_node<Ch> ));
- xml_node<Ch> *node = new (memory) xml_node<Ch>(type);
- if (name) {
- if (name_size > 0)
- node->name(name, name_size);
- else node->name(name);
- }
- if (value) {
- if (value_size > 0)
- node->value(value, value_size);
- else node->value(value);
- }
- return node;
- }
-
- //! Allocates a new attribute from the pool, and optionally assigns name and value to it.
- //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
- //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
- //! will call rapidxml::parse_error_handler() function.
- //! \param name Name to assign to the attribute, or 0 to assign no name.
- //! \param value Value to assign to the attribute, or 0 to assign no value.
- //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
- //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
- //! \return Pointer to allocated attribute. This pointer will never be NULL.
- xml_attribute<Ch> *allocate_attribute(const Ch *name = 0, const Ch *value = 0,
- std::size_t name_size = 0, std::size_t value_size = 0) {
- void *memory = allocate_aligned(sizeof(xml_attribute<Ch> ));
- xml_attribute<Ch> *attribute = new (memory) xml_attribute<Ch>;
- if (name) {
- if (name_size > 0)
- attribute->name(name, name_size);
- else attribute->name(name);
- }
- if (value) {
- if (value_size > 0)
- attribute->value(value, value_size);
- else attribute->value(value);
- }
- return attribute;
- }
-
- //! Allocates a char array of given size from the pool, and optionally copies a given string to it.
- //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
- //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
- //! will call rapidxml::parse_error_handler() function.
- //! \param source String to initialize the allocated memory with, or 0 to not initialize it.
- //! \param size Number of characters to allocate, or zero to calculate it automatically from source string length; if size is 0, source string must be specified and null terminated.
- //! \return Pointer to allocated char array. This pointer will never be NULL.
- Ch *allocate_string(const Ch *source = 0, std::size_t size = 0) {
- assert(source || size); // Either source or size (or both) must be specified
- if (size == 0) size = internal::measure(source) + 1;
- Ch *result = static_cast<Ch *>(allocate_aligned(size * sizeof(Ch)));
- if (source) for (std::size_t i = 0; i < size; ++i)
- result[i] = source[i];
- return result;
- }
-
- //! Clones an xml_node and its hierarchy of child nodes and attributes.
- //! Nodes and attributes are allocated from this memory pool.
- //! Names and values are not cloned, they are shared between the clone and the source.
- //! Result node can be optionally specified as a second parameter,
- //! in which case its contents will be replaced with cloned source node.
- //! This is useful when you want to clone entire document.
- //! \param source Node to clone.
- //! \param result Node to put results in, or 0 to automatically allocate result node
- //! \return Pointer to cloned node. This pointer will never be NULL.
- xml_node<Ch> *clone_node(const xml_node<Ch> *source,
- xml_node<Ch> *result = 0) {
- // Prepare result node
- if (result) {
- result->remove_all_attributes();
- result->remove_all_nodes();
- result->type(source->type());
- } else result = allocate_node(source->type());
-
- // Clone name and value
- result->name(source->name(), source->name_size());
- result->value(source->value(), source->value_size());
-
- // Clone child nodes and attributes
- for (xml_node<Ch> *child = source->first_node(); child;
- child = child->next_sibling())
- result->append_node(clone_node(child));
- for (xml_attribute<Ch> *attr = source->first_attribute(); attr;
- attr = attr->next_attribute())
- result->append_attribute(
- allocate_attribute(attr->name(), attr->value(), attr->name_size(),
- attr->value_size()));
-
- return result;
- }
-
- //! Clears the pool.
- //! This causes memory occupied by nodes allocated by the pool to be freed.
- //! Any nodes or strings allocated from the pool will no longer be valid.
- void clear() {
- while (m_begin != m_static_memory) {
- char *previous_begin = reinterpret_cast<header *>(align(m_begin))
- ->previous_begin;
- if (m_free_func)
- m_free_func(m_begin);
- else delete[] m_begin;
- m_begin = previous_begin;
- }
- init();
- }
-
- //! Sets or resets the user-defined memory allocation functions for the pool.
- //! This can only be called when no memory is allocated from the pool yet, otherwise results are undefined.
- //! Allocation function must not return invalid pointer on failure. It should either throw,
- //! stop the program, or use <code>longjmp()</code> function to pass control to other place of program.
- //! If it returns invalid pointer, results are undefined.
- //! <br><br>
- //! User defined allocation functions must have the following forms:
- //! <br><code>
- //! <br>void *allocate(std::size_t size);
- //! <br>void free(void *pointer);
- //! </code><br>
- //! \param af Allocation function, or 0 to restore default function
- //! \param ff Free function, or 0 to restore default function
- void set_allocator(alloc_func *af, free_func *ff) {
- assert(m_begin == m_static_memory && m_ptr == align(m_begin)); // Verify that no memory is allocated yet
- m_alloc_func = af;
- m_free_func = ff;
- }
-
-private:
-
- struct header {
- char *previous_begin;
- };
-
- void init() {
- m_begin = m_static_memory;
- m_ptr = align(m_begin);
- m_end = m_static_memory + sizeof(m_static_memory);
- }
-
- char *align(char *ptr) {
- std::size_t alignment = ((RAPIDXML_ALIGNMENT
- - (std::size_t(ptr) & (RAPIDXML_ALIGNMENT - 1)))
- & (RAPIDXML_ALIGNMENT - 1));
- return ptr + alignment;
- }
-
- char *allocate_raw(std::size_t size) {
- // Allocate
- void *memory;
- if (m_alloc_func) // Allocate memory using either user-specified allocation function or global operator new[]
- {
- memory = m_alloc_func(size);
- assert(memory); // Allocator is not allowed to return 0, on failure it must either throw, stop the program or use longjmp
- } else {
- memory = new char[size];
-#ifdef RAPIDXML_NO_EXCEPTIONS
- if (!memory) // If exceptions are disabled, verify memory allocation, because new will not be able to throw bad_alloc
- RAPIDXML_PARSE_ERROR("out of memory", 0);
-#endif
- }
- return static_cast<char *>(memory);
- }
-
- void *allocate_aligned(std::size_t size) {
- // Calculate aligned pointer
- char *result = align(m_ptr);
-
- // If not enough memory left in current pool, allocate a new pool
- if (result + size > m_end) {
- // Calculate required pool size (may be bigger than RAPIDXML_DYNAMIC_POOL_SIZE)
- std::size_t pool_size = RAPIDXML_DYNAMIC_POOL_SIZE;
- if (pool_size < size) pool_size = size;
-
- // Allocate
- std::size_t alloc_size = sizeof(header) + (2 * RAPIDXML_ALIGNMENT - 2)
- + pool_size; // 2 alignments required in worst case: one for header, one for actual allocation
- char *raw_memory = allocate_raw(alloc_size);
-
- // Setup new pool in allocated memory
- char *pool = align(raw_memory);
- header *new_header = reinterpret_cast<header *>(pool);
- new_header->previous_begin = m_begin;
- m_begin = raw_memory;
- m_ptr = pool + sizeof(header);
- m_end = raw_memory + alloc_size;
-
- // Calculate aligned pointer again using new pool
- result = align(m_ptr);
- }
-
- // Update pool and return aligned pointer
- m_ptr = result + size;
- return result;
- }
-
- char *m_begin; // Start of raw memory making up current pool
- char *m_ptr; // First free byte in current pool
- char *m_end; // One past last available byte in current pool
- char m_static_memory[RAPIDXML_STATIC_POOL_SIZE]; // Static raw memory
- alloc_func *m_alloc_func; // Allocator function, or 0 if default is to be used
- free_func *m_free_func; // Free function, or 0 if default is to be used
-};
-
-///////////////////////////////////////////////////////////////////////////
-// XML base
-
-//! Base class for xml_node and xml_attribute implementing common functions:
-//! name(), name_size(), value(), value_size() and parent().
-//! \param Ch Character type to use
-template<class Ch = char>
-class xml_base {
-
-public:
-
- ///////////////////////////////////////////////////////////////////////////
- // Construction & destruction
-
- // Construct a base with empty name, value and parent
- xml_base() :
- m_name(0), m_value(0), m_parent(0) {
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Node data access
-
- //! Gets name of the node.
- //! Interpretation of name depends on type of node.
- //! Note that name will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
- //! <br><br>
- //! Use name_size() function to determine length of the name.
- //! \return Name of node, or empty string if node has no name.
- Ch *name() const {
- return m_name ? m_name : nullstr();
- }
-
- //! Gets size of node name, not including terminator character.
- //! This function works correctly irrespective of whether name is or is not zero terminated.
- //! \return Size of node name, in characters.
- std::size_t name_size() const {
- return m_name ? m_name_size : 0;
- }
-
- //! Gets value of node.
- //! Interpretation of value depends on type of node.
- //! Note that value will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
- //! <br><br>
- //! Use value_size() function to determine length of the value.
- //! \return Value of node, or empty string if node has no value.
- Ch *value() const {
- return m_value ? m_value : nullstr();
- }
-
- //! Gets size of node value, not including terminator character.
- //! This function works correctly irrespective of whether value is or is not zero terminated.
- //! \return Size of node value, in characters.
- std::size_t value_size() const {
- return m_value ? m_value_size : 0;
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Node modification
-
- //! Sets name of node to a non zero-terminated string.
- //! See \ref ownership_of_strings.
- //! <br><br>
- //! Note that node does not own its name or value, it only stores a pointer to it.
- //! It will not delete or otherwise free the pointer on destruction.
- //! It is reponsibility of the user to properly manage lifetime of the string.
- //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
- //! on destruction of the document the string will be automatically freed.
- //! <br><br>
- //! Size of name must be specified separately, because name does not have to be zero terminated.
- //! Use name(const Ch *) function to have the length automatically calculated (string must be zero terminated).
- //! \param name Name of node to set. Does not have to be zero terminated.
- //! \param size Size of name, in characters. This does not include zero terminator, if one is present.
- void name(const Ch *name, std::size_t size) {
- m_name = const_cast<Ch *>(name);
- m_name_size = size;
- }
-
- //! Sets name of node to a zero-terminated string.
- //! See also \ref ownership_of_strings and xml_node::name(const Ch *, std::size_t).
- //! \param name Name of node to set. Must be zero terminated.
- void name(const Ch *name) {
- this->name(name, internal::measure(name));
- }
-
- //! Sets value of node to a non zero-terminated string.
- //! See \ref ownership_of_strings.
- //! <br><br>
- //! Note that node does not own its name or value, it only stores a pointer to it.
- //! It will not delete or otherwise free the pointer on destruction.
- //! It is reponsibility of the user to properly manage lifetime of the string.
- //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
- //! on destruction of the document the string will be automatically freed.
- //! <br><br>
- //! Size of value must be specified separately, because it does not have to be zero terminated.
- //! Use value(const Ch *) function to have the length automatically calculated (string must be zero terminated).
- //! <br><br>
- //! If an element has a child node of type node_data, it will take precedence over element value when printing.
- //! If you want to manipulate data of elements using values, use parser flag rapidxml::parse_no_data_nodes to prevent creation of data nodes by the parser.
- //! \param value value of node to set. Does not have to be zero terminated.
- //! \param size Size of value, in characters. This does not include zero terminator, if one is present.
- void value(const Ch *value, std::size_t size) {
- m_value = const_cast<Ch *>(value);
- m_value_size = size;
- }
-
- //! Sets value of node to a zero-terminated string.
- //! See also \ref ownership_of_strings and xml_node::value(const Ch *, std::size_t).
- //! \param value Vame of node to set. Must be zero terminated.
- void value(const Ch *value) {
- this->value(value, internal::measure(value));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Related nodes access
-
- //! Gets node parent.
- //! \return Pointer to parent node, or 0 if there is no parent.
- xml_node<Ch> *parent() const {
- return m_parent;
- }
-
-protected:
-
- // Return empty string
- static Ch *nullstr() {
- static Ch zero = Ch('\0');
- return &zero;
- }
-
- Ch *m_name; // Name of node, or 0 if no name
- Ch *m_value; // Value of node, or 0 if no value
- std::size_t m_name_size; // Length of node name, or undefined of no name
- std::size_t m_value_size; // Length of node value, or undefined if no value
- xml_node<Ch> *m_parent; // Pointer to parent node, or 0 if none
-
-};
-
-//! Class representing attribute node of XML document.
-//! Each attribute has name and value strings, which are available through name() and value() functions (inherited from xml_base).
-//! Note that after parse, both name and value of attribute will point to interior of source text used for parsing.
-//! Thus, this text must persist in memory for the lifetime of attribute.
-//! \param Ch Character type to use.
-template<class Ch = char>
-class xml_attribute:
- public xml_base<Ch> {
-
- friend class xml_node<Ch> ;
-
-public:
-
- ///////////////////////////////////////////////////////////////////////////
- // Construction & destruction
-
- //! Constructs an empty attribute with the specified type.
- //! Consider using memory_pool of appropriate xml_document if allocating attributes manually.
- xml_attribute() {
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Related nodes access
-
- //! Gets document of which attribute is a child.
- //! \return Pointer to document that contains this attribute, or 0 if there is no parent document.
- xml_document<Ch> *document() const {
- if (xml_node<Ch> *node = this->parent()) {
- while (node->parent())
- node = node->parent();
- return
- node->type() == node_document ?
- static_cast<xml_document<Ch> *>(node) : 0;
- } else return 0;
- }
-
- //! Gets previous attribute, optionally matching attribute name.
- //! \param name Name of attribute to find, or 0 to return previous attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
- //! \return Pointer to found attribute, or 0 if not found.
- xml_attribute<Ch> *previous_attribute(const Ch *name = 0,
- std::size_t name_size = 0, bool case_sensitive = true) const {
- if (name) {
- if (name_size == 0) name_size = internal::measure(name);
- for (xml_attribute<Ch> *attribute = m_prev_attribute; attribute;
- attribute = attribute->m_prev_attribute)
- if (internal::compare(attribute->name(), attribute->name_size(), name,
- name_size, case_sensitive)) return attribute;
- return 0;
- } else return this->m_parent ? m_prev_attribute : 0;
- }
-
- //! Gets next attribute, optionally matching attribute name.
- //! \param name Name of attribute to find, or 0 to return next attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
- //! \return Pointer to found attribute, or 0 if not found.
- xml_attribute<Ch> *next_attribute(const Ch *name = 0, std::size_t name_size =
- 0, bool case_sensitive = true) const {
- if (name) {
- if (name_size == 0) name_size = internal::measure(name);
- for (xml_attribute<Ch> *attribute = m_next_attribute; attribute;
- attribute = attribute->m_next_attribute)
- if (internal::compare(attribute->name(), attribute->name_size(), name,
- name_size, case_sensitive)) return attribute;
- return 0;
- } else return this->m_parent ? m_next_attribute : 0;
- }
-
-private:
-
- xml_attribute<Ch> *m_prev_attribute; // Pointer to previous sibling of attribute, or 0 if none; only valid if parent is non-zero
- xml_attribute<Ch> *m_next_attribute; // Pointer to next sibling of attribute, or 0 if none; only valid if parent is non-zero
-
-};
-
-///////////////////////////////////////////////////////////////////////////
-// XML node
-
-//! Class representing a node of XML document.
-//! Each node may have associated name and value strings, which are available through name() and value() functions.
-//! Interpretation of name and value depends on type of the node.
-//! Type of node can be determined by using type() function.
-//! <br><br>
-//! Note that after parse, both name and value of node, if any, will point interior of source text used for parsing.
-//! Thus, this text must persist in the memory for the lifetime of node.
-//! \param Ch Character type to use.
-template<class Ch = char>
-class xml_node:
- public xml_base<Ch> {
-
-public:
-
- ///////////////////////////////////////////////////////////////////////////
- // Construction & destruction
-
- //! Constructs an empty node with the specified type.
- //! Consider using memory_pool of appropriate document to allocate nodes manually.
- //! \param type Type of node to construct.
- xml_node(node_type type) :
- m_type(type), m_first_node(0), m_first_attribute(0) {
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Node data access
-
- //! Gets type of node.
- //! \return Type of node.
- node_type type() const {
- return m_type;
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Related nodes access
-
- //! Gets document of which node is a child.
- //! \return Pointer to document that contains this node, or 0 if there is no parent document.
- xml_document<Ch> *document() const {
- xml_node<Ch> *node = const_cast<xml_node<Ch> *>(this);
- while (node->parent())
- node = node->parent();
- return
- node->type() == node_document ? static_cast<xml_document<Ch> *>(node) :
- 0;
- }
-
- //! Gets first child node, optionally matching node name.
- //! \param name Name of child to find, or 0 to return first child regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
- //! \return Pointer to found child, or 0 if not found.
- xml_node<Ch> *first_node(const Ch *name = 0, std::size_t name_size = 0,
- bool case_sensitive = true) const {
- if (name) {
- if (name_size == 0) name_size = internal::measure(name);
- for (xml_node<Ch> *child = m_first_node; child;
- child = child->next_sibling())
- if (internal::compare(child->name(), child->name_size(), name,
- name_size, case_sensitive)) return child;
- return 0;
- } else return m_first_node;
- }
-
- //! Gets last child node, optionally matching node name.
- //! Behaviour is undefined if node has no children.
- //! Use first_node() to test if node has children.
- //! \param name Name of child to find, or 0 to return last child regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
- //! \return Pointer to found child, or 0 if not found.
- xml_node<Ch> *last_node(const Ch *name = 0, std::size_t name_size = 0,
- bool case_sensitive = true) const {
- assert(m_first_node); // Cannot query for last child if node has no children
- if (name) {
- if (name_size == 0) name_size = internal::measure(name);
- for (xml_node<Ch> *child = m_last_node; child;
- child = child->previous_sibling())
- if (internal::compare(child->name(), child->name_size(), name,
- name_size, case_sensitive)) return child;
- return 0;
- } else return m_last_node;
- }
-
- //! Gets previous sibling node, optionally matching node name.
- //! Behaviour is undefined if node has no parent.
- //! Use parent() to test if node has a parent.
- //! \param name Name of sibling to find, or 0 to return previous sibling regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
- //! \return Pointer to found sibling, or 0 if not found.
- xml_node<Ch> *previous_sibling(const Ch *name = 0, std::size_t name_size = 0,
- bool case_sensitive = true) const {
- assert(this->m_parent); // Cannot query for siblings if node has no parent
- if (name) {
- if (name_size == 0) name_size = internal::measure(name);
- for (xml_node<Ch> *sibling = m_prev_sibling; sibling;
- sibling = sibling->m_prev_sibling)
- if (internal::compare(sibling->name(), sibling->name_size(), name,
- name_size, case_sensitive)) return sibling;
- return 0;
- } else return m_prev_sibling;
- }
-
- //! Gets next sibling node, optionally matching node name.
- //! Behaviour is undefined if node has no parent.
- //! Use parent() to test if node has a parent.
- //! \param name Name of sibling to find, or 0 to return next sibling regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
- //! \return Pointer to found sibling, or 0 if not found.
- xml_node<Ch> *next_sibling(const Ch *name = 0, std::size_t name_size = 0,
- bool case_sensitive = true) const {
- assert(this->m_parent); // Cannot query for siblings if node has no parent
- if (name) {
- if (name_size == 0) name_size = internal::measure(name);
- for (xml_node<Ch> *sibling = m_next_sibling; sibling;
- sibling = sibling->m_next_sibling)
- if (internal::compare(sibling->name(), sibling->name_size(), name,
- name_size, case_sensitive)) return sibling;
- return 0;
- } else return m_next_sibling;
- }
-
- //! Gets first attribute of node, optionally matching attribute name.
- //! \param name Name of attribute to find, or 0 to return first attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
- //! \return Pointer to found attribute, or 0 if not found.
- xml_attribute<Ch> *first_attribute(const Ch *name = 0, std::size_t name_size =
- 0, bool case_sensitive = true) const {
- if (name) {
- if (name_size == 0) name_size = internal::measure(name);
- for (xml_attribute<Ch> *attribute = m_first_attribute; attribute;
- attribute = attribute->m_next_attribute)
- if (internal::compare(attribute->name(), attribute->name_size(), name,
- name_size, case_sensitive)) return attribute;
- return 0;
- } else return m_first_attribute;
- }
-
- //! Gets last attribute of node, optionally matching attribute name.
- //! \param name Name of attribute to find, or 0 to return last attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
- //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
- //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
- //! \return Pointer to found attribute, or 0 if not found.
- xml_attribute<Ch> *last_attribute(const Ch *name = 0, std::size_t name_size =
- 0, bool case_sensitive = true) const {
- if (name) {
- if (name_size == 0) name_size = internal::measure(name);
- for (xml_attribute<Ch> *attribute = m_last_attribute; attribute;
- attribute = attribute->m_prev_attribute)
- if (internal::compare(attribute->name(), attribute->name_size(), name,
- name_size, case_sensitive)) return attribute;
- return 0;
- } else return m_first_attribute ? m_last_attribute : 0;
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Node modification
-
- //! Sets type of node.
- //! \param type Type of node to set.
- void type(node_type type) {
- m_type = type;
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Node manipulation
-
- //! Prepends a new child node.
- //! The prepended child becomes the first child, and all existing children are moved one position back.
- //! \param child Node to prepend.
- void prepend_node(xml_node<Ch> *child) {
- assert(child && !child->parent() && child->type() != node_document);
- if (first_node()) {
- child->m_next_sibling = m_first_node;
- m_first_node->m_prev_sibling = child;
- } else {
- child->m_next_sibling = 0;
- m_last_node = child;
- }
- m_first_node = child;
- child->m_parent = this;
- child->m_prev_sibling = 0;
- }
-
- //! Appends a new child node.
- //! The appended child becomes the last child.
- //! \param child Node to append.
- void append_node(xml_node<Ch> *child) {
- assert(child && !child->parent() && child->type() != node_document);
- if (first_node()) {
- child->m_prev_sibling = m_last_node;
- m_last_node->m_next_sibling = child;
- } else {
- child->m_prev_sibling = 0;
- m_first_node = child;
- }
- m_last_node = child;
- child->m_parent = this;
- child->m_next_sibling = 0;
- }
-
- //! Inserts a new child node at specified place inside the node.
- //! All children after and including the specified node are moved one position back.
- //! \param where Place where to insert the child, or 0 to insert at the back.
- //! \param child Node to insert.
- void insert_node(xml_node<Ch> *where, xml_node<Ch> *child) {
- assert(!where || where->parent() == this);
- assert(child && !child->parent() && child->type() != node_document);
- if (where == m_first_node)
- prepend_node(child);
- else if (where == 0)
- append_node(child);
- else {
- child->m_prev_sibling = where->m_prev_sibling;
- child->m_next_sibling = where;
- where->m_prev_sibling->m_next_sibling = child;
- where->m_prev_sibling = child;
- child->m_parent = this;
- }
- }
-
- //! Removes first child node.
- //! If node has no children, behaviour is undefined.
- //! Use first_node() to test if node has children.
- void remove_first_node() {
- assert(first_node());
- xml_node<Ch> *child = m_first_node;
- m_first_node = child->m_next_sibling;
- if (child->m_next_sibling)
- child->m_next_sibling->m_prev_sibling = 0;
- else m_last_node = 0;
- child->m_parent = 0;
- }
-
- //! Removes last child of the node.
- //! If node has no children, behaviour is undefined.
- //! Use first_node() to test if node has children.
- void remove_last_node() {
- assert(first_node());
- xml_node<Ch> *child = m_last_node;
- if (child->m_prev_sibling) {
- m_last_node = child->m_prev_sibling;
- child->m_prev_sibling->m_next_sibling = 0;
- } else m_first_node = 0;
- child->m_parent = 0;
- }
-
- //! Removes specified child from the node
- // \param where Pointer to child to be removed.
- void remove_node(xml_node<Ch> *where) {
- assert(where && where->parent() == this);
- assert(first_node());
- if (where == m_first_node)
- remove_first_node();
- else if (where == m_last_node)
- remove_last_node();
- else {
- where->m_prev_sibling->m_next_sibling = where->m_next_sibling;
- where->m_next_sibling->m_prev_sibling = where->m_prev_sibling;
- where->m_parent = 0;
- }
- }
-
- //! Removes all child nodes (but not attributes).
- void remove_all_nodes() {
- for (xml_node<Ch> *node = first_node(); node; node = node->m_next_sibling)
- node->m_parent = 0;
- m_first_node = 0;
- }
-
- //! Prepends a new attribute to the node.
- //! \param attribute Attribute to prepend.
- void prepend_attribute(xml_attribute<Ch> *attribute) {
- assert(attribute && !attribute->parent());
- if (first_attribute()) {
- attribute->m_next_attribute = m_first_attribute;
- m_first_attribute->m_prev_attribute = attribute;
- } else {
- attribute->m_next_attribute = 0;
- m_last_attribute = attribute;
- }
- m_first_attribute = attribute;
- attribute->m_parent = this;
- attribute->m_prev_attribute = 0;
- }
-
- //! Appends a new attribute to the node.
- //! \param attribute Attribute to append.
- void append_attribute(xml_attribute<Ch> *attribute) {
- assert(attribute && !attribute->parent());
- if (first_attribute()) {
- attribute->m_prev_attribute = m_last_attribute;
- m_last_attribute->m_next_attribute = attribute;
- } else {
- attribute->m_prev_attribute = 0;
- m_first_attribute = attribute;
- }
- m_last_attribute = attribute;
- attribute->m_parent = this;
- attribute->m_next_attribute = 0;
- }
-
- //! Inserts a new attribute at specified place inside the node.
- //! All attributes after and including the specified attribute are moved one position back.
- //! \param where Place where to insert the attribute, or 0 to insert at the back.
- //! \param attribute Attribute to insert.
- void insert_attribute(xml_attribute<Ch> *where,
- xml_attribute<Ch> *attribute) {
- assert(!where || where->parent() == this);
- assert(attribute && !attribute->parent());
- if (where == m_first_attribute)
- prepend_attribute(attribute);
- else if (where == 0)
- append_attribute(attribute);
- else {
- attribute->m_prev_attribute = where->m_prev_attribute;
- attribute->m_next_attribute = where;
- where->m_prev_attribute->m_next_attribute = attribute;
- where->m_prev_attribute = attribute;
- attribute->m_parent = this;
- }
- }
-
- //! Removes first attribute of the node.
- //! If node has no attributes, behaviour is undefined.
- //! Use first_attribute() to test if node has attributes.
- void remove_first_attribute() {
- assert(first_attribute());
- xml_attribute<Ch> *attribute = m_first_attribute;
- if (attribute->m_next_attribute) {
- attribute->m_next_attribute->m_prev_attribute = 0;
- } else m_last_attribute = 0;
- attribute->m_parent = 0;
- m_first_attribute = attribute->m_next_attribute;
- }
-
- //! Removes last attribute of the node.
- //! If node has no attributes, behaviour is undefined.
- //! Use first_attribute() to test if node has attributes.
- void remove_last_attribute() {
- assert(first_attribute());
- xml_attribute<Ch> *attribute = m_last_attribute;
- if (attribute->m_prev_attribute) {
- attribute->m_prev_attribute->m_next_attribute = 0;
- m_last_attribute = attribute->m_prev_attribute;
- } else m_first_attribute = 0;
- attribute->m_parent = 0;
- }
-
- //! Removes specified attribute from node.
- //! \param where Pointer to attribute to be removed.
- void remove_attribute(xml_attribute<Ch> *where) {
- assert(first_attribute() && where->parent() == this);
- if (where == m_first_attribute)
- remove_first_attribute();
- else if (where == m_last_attribute)
- remove_last_attribute();
- else {
- where->m_prev_attribute->m_next_attribute = where->m_next_attribute;
- where->m_next_attribute->m_prev_attribute = where->m_prev_attribute;
- where->m_parent = 0;
- }
- }
-
- //! Removes all attributes of node.
- void remove_all_attributes() {
- for (xml_attribute<Ch> *attribute = first_attribute(); attribute;
- attribute = attribute->m_next_attribute)
- attribute->m_parent = 0;
- m_first_attribute = 0;
- }
-
-private:
-
- ///////////////////////////////////////////////////////////////////////////
- // Restrictions
-
- // No copying
- xml_node(const xml_node &);
- void operator =(const xml_node &);
-
- ///////////////////////////////////////////////////////////////////////////
- // Data members
-
- // Note that some of the pointers below have UNDEFINED values if certain other pointers are 0.
- // This is required for maximum performance, as it allows the parser to omit initialization of
- // unneded/redundant values.
- //
- // The rules are as follows:
- // 1. first_node and first_attribute contain valid pointers, or 0 if node has no children/attributes respectively
- // 2. last_node and last_attribute are valid only if node has at least one child/attribute respectively, otherwise they contain garbage
- // 3. prev_sibling and next_sibling are valid only if node has a parent, otherwise they contain garbage
-
- node_type m_type; // Type of node; always valid
- xml_node<Ch> *m_first_node; // Pointer to first child node, or 0 if none; always valid
- xml_node<Ch> *m_last_node; // Pointer to last child node, or 0 if none; this value is only valid if m_first_node is non-zero
- xml_attribute<Ch> *m_first_attribute; // Pointer to first attribute of node, or 0 if none; always valid
- xml_attribute<Ch> *m_last_attribute; // Pointer to last attribute of node, or 0 if none; this value is only valid if m_first_attribute is non-zero
- xml_node<Ch> *m_prev_sibling; // Pointer to previous sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
- xml_node<Ch> *m_next_sibling; // Pointer to next sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
-
-};
-
-///////////////////////////////////////////////////////////////////////////
-// XML document
-
-//! This class represents root of the DOM hierarchy.
-//! It is also an xml_node and a memory_pool through public inheritance.
-//! Use parse() function to build a DOM tree from a zero-terminated XML text string.
-//! parse() function allocates memory for nodes and attributes by using functions of xml_document,
-//! which are inherited from memory_pool.
-//! To access root node of the document, use the document itself, as if it was an xml_node.
-//! \param Ch Character type to use.
-template<class Ch = char>
-class xml_document:
- public xml_node<Ch>, public memory_pool<Ch> {
-
-public:
-
- //! Constructs empty XML document
- xml_document() :
- xml_node<Ch>(node_document) {
- }
-
- //! Parses zero-terminated XML string according to given flags.
- //! Passed string will be modified by the parser, unless rapidxml::parse_non_destructive flag is used.
- //! The string must persist for the lifetime of the document.
- //! In case of error, rapidxml::parse_error exception will be thrown.
- //! <br><br>
- //! If you want to parse contents of a file, you must first load the file into the memory, and pass pointer to its beginning.
- //! Make sure that data is zero-terminated.
- //! <br><br>
- //! Document can be parsed into multiple times.
- //! Each new call to parse removes previous nodes and attributes (if any), but does not clear memory pool.
- //! \param text XML data to parse; pointer is non-const to denote fact that this data may be modified by the parser.
- template<int Flags>
- void parse(Ch *text) {
- assert(text);
-
- // Remove current contents
- this->remove_all_nodes();
- this->remove_all_attributes();
-
- // Parse BOM, if any
- parse_bom<Flags>(text);
-
- // Parse children
- while (1) {
- // Skip whitespace before node
- skip<whitespace_pred, Flags>(text);
- if (*text == 0) break;
-
- // Parse and append new child
- if (*text == Ch('<')) {
- ++text; // Skip '<'
- if (xml_node<Ch> *node = parse_node<Flags>(text))
- this->append_node(node);
- } else
- RAPIDXML_PARSE_ERROR("expected <", text);
- }
-
- }
-
- //! Clears the document by deleting all nodes and clearing the memory pool.
- //! All nodes owned by document pool are destroyed.
- void clear() {
- this->remove_all_nodes();
- this->remove_all_attributes();
- memory_pool<Ch>::clear();
- }
-
-private:
-
- ///////////////////////////////////////////////////////////////////////
- // Internal character utility functions
-
- // Detect whitespace character
- struct whitespace_pred {
- static unsigned char test(Ch ch) {
- return internal::lookup_tables<0>::lookup_whitespace[static_cast<unsigned char>(ch)];
- }
- };
-
- // Detect node name character
- struct node_name_pred {
- static unsigned char test(Ch ch) {
- return internal::lookup_tables<0>::lookup_node_name[static_cast<unsigned char>(ch)];
- }
- };
-
- // Detect attribute name character
- struct attribute_name_pred {
- static unsigned char test(Ch ch) {
- return internal::lookup_tables<0>::lookup_attribute_name[static_cast<unsigned char>(ch)];
- }
- };
-
- // Detect text character (PCDATA)
- struct text_pred {
- static unsigned char test(Ch ch) {
- return internal::lookup_tables<0>::lookup_text[static_cast<unsigned char>(ch)];
- }
- };
-
- // Detect text character (PCDATA) that does not require processing
- struct text_pure_no_ws_pred {
- static unsigned char test(Ch ch) {
- return internal::lookup_tables<0>::lookup_text_pure_no_ws[static_cast<unsigned char>(ch)];
- }
- };
-
- // Detect text character (PCDATA) that does not require processing
- struct text_pure_with_ws_pred {
- static unsigned char test(Ch ch) {
- return internal::lookup_tables<0>::lookup_text_pure_with_ws[static_cast<unsigned char>(ch)];
- }
- };
-
- // Detect attribute value character
- template<Ch Quote>
- struct attribute_value_pred {
- static unsigned char test(Ch ch) {
- if (Quote == Ch('\''))
- return internal::lookup_tables<0>::lookup_attribute_data_1[static_cast<unsigned char>(ch)];
- if (Quote == Ch('\"'))
- return internal::lookup_tables<0>::lookup_attribute_data_2[static_cast<unsigned char>(ch)];
- return 0; // Should never be executed, to avoid warnings on Comeau
- }
- };
-
- // Detect attribute value character
- template<Ch Quote>
- struct attribute_value_pure_pred {
- static unsigned char test(Ch ch) {
- if (Quote == Ch('\''))
- return internal::lookup_tables<0>::lookup_attribute_data_1_pure[static_cast<unsigned char>(ch)];
- if (Quote == Ch('\"'))
- return internal::lookup_tables<0>::lookup_attribute_data_2_pure[static_cast<unsigned char>(ch)];
- return 0; // Should never be executed, to avoid warnings on Comeau
- }
- };
-
- // Insert coded character, using UTF8 or 8-bit ASCII
- template<int Flags>
- static void insert_coded_character(Ch *&text, unsigned long code) {
- if (Flags & parse_no_utf8) {
- // Insert 8-bit ASCII character
- // Todo: possibly verify that code is less than 256 and use replacement char otherwise?
- text[0] = static_cast<unsigned char>(code);
- text += 1;
- } else {
- // Insert UTF8 sequence
- if (code < 0x80) // 1 byte sequence
- {
- text[0] = static_cast<unsigned char>(code);
- text += 1;
- } else if (code < 0x800) // 2 byte sequence
- {
- text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF);
- code >>= 6;
- text[0] = static_cast<unsigned char>(code | 0xC0);
- text += 2;
- } else if (code < 0x10000) // 3 byte sequence
- {
- text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF);
- code >>= 6;
- text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF);
- code >>= 6;
- text[0] = static_cast<unsigned char>(code | 0xE0);
- text += 3;
- } else if (code < 0x110000) // 4 byte sequence
- {
- text[3] = static_cast<unsigned char>((code | 0x80) & 0xBF);
- code >>= 6;
- text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF);
- code >>= 6;
- text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF);
- code >>= 6;
- text[0] = static_cast<unsigned char>(code | 0xF0);
- text += 4;
- } else // Invalid, only codes up to 0x10FFFF are allowed in Unicode
- {
- RAPIDXML_PARSE_ERROR("invalid numeric character entity", text);
- }
- }
- }
-
- // Skip characters until predicate evaluates to true
- template<class StopPred, int Flags>
- static void skip(Ch *&text) {
- Ch *tmp = text;
- while (StopPred::test(*tmp))
- ++tmp;
- text = tmp;
- }
-
- // Skip characters until predicate evaluates to true while doing the following:
- // - replacing XML character entity references with proper characters (' & " < > &#...;)
- // - condensing whitespace sequences to single space character
- template<class StopPred, class StopPredPure, int Flags>
- static Ch *skip_and_expand_character_refs(Ch *&text) {
- // If entity translation, whitespace condense and whitespace trimming is disabled, use plain skip
- if (Flags & parse_no_entity_translation
- && !(Flags & parse_normalize_whitespace)
- && !(Flags & parse_trim_whitespace)) {
- skip<StopPred, Flags>(text);
- return text;
- }
-
- // Use simple skip until first modification is detected
- skip<StopPredPure, Flags>(text);
-
- // Use translation skip
- Ch *src = text;
- Ch *dest = src;
- while (StopPred::test(*src)) {
- // If entity translation is enabled
- if (!(Flags & parse_no_entity_translation)) {
- // Test if replacement is needed
- if (src[0] == Ch('&')) {
- switch (src[1]) {
-
- // & '
- case Ch('a'):
- if (src[2] == Ch('m') && src[3] == Ch('p') && src[4] == Ch(';')) {
- *dest = Ch('&');
- ++dest;
- src += 5;
- continue;
- }
- if (src[2] == Ch('p') && src[3] == Ch('o') && src[4] == Ch('s')
- && src[5] == Ch(';')) {
- *dest = Ch('\'');
- ++dest;
- src += 6;
- continue;
- }
- break;
-
- // "
- case Ch('q'):
- if (src[2] == Ch('u') && src[3] == Ch('o') && src[4] == Ch('t')
- && src[5] == Ch(';')) {
- *dest = Ch('"');
- ++dest;
- src += 6;
- continue;
- }
- break;
-
- // >
- case Ch('g'):
- if (src[2] == Ch('t') && src[3] == Ch(';')) {
- *dest = Ch('>');
- ++dest;
- src += 4;
- continue;
- }
- break;
-
- // <
- case Ch('l'):
- if (src[2] == Ch('t') && src[3] == Ch(';')) {
- *dest = Ch('<');
- ++dest;
- src += 4;
- continue;
- }
- break;
-
- // &#...; - assumes ASCII
- case Ch('#'):
- if (src[2] == Ch('x')) {
- unsigned long code = 0;
- src += 3; // Skip &#x
- while (1) {
- unsigned char digit =
- internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
- if (digit == 0xFF) break;
- code = code * 16 + digit;
- ++src;
- }
- insert_coded_character<Flags>(dest, code); // Put character in output
- } else {
- unsigned long code = 0;
- src += 2; // Skip &#
- while (1) {
- unsigned char digit =
- internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
- if (digit == 0xFF) break;
- code = code * 10 + digit;
- ++src;
- }
- insert_coded_character<Flags>(dest, code); // Put character in output
- }
- if (*src == Ch(';'))
- ++src;
- else
- RAPIDXML_PARSE_ERROR("expected ;", src);
- continue;
-
- // Something else
- default:
- // Ignore, just copy '&' verbatim
- break;
-
- }
- }
- }
-
- // If whitespace condensing is enabled
- if (Flags & parse_normalize_whitespace) {
- // Test if condensing is needed
- if (whitespace_pred::test(*src)) {
- *dest = Ch(' ');
- ++dest; // Put single space in dest
- ++src; // Skip first whitespace char
- // Skip remaining whitespace chars
- while (whitespace_pred::test(*src))
- ++src;
- continue;
- }
- }
-
- // No replacement, only copy character
- *dest++ = *src++;
-
- }
-
- // Return new end
- text = src;
- return dest;
-
- }
-
- ///////////////////////////////////////////////////////////////////////
- // Internal parsing functions
-
- // Parse BOM, if any
- template<int Flags>
- void parse_bom(Ch *&text) {
- // UTF-8?
- if (static_cast<unsigned char>(text[0]) == 0xEF
- && static_cast<unsigned char>(text[1]) == 0xBB
- && static_cast<unsigned char>(text[2]) == 0xBF) {
- text += 3; // Skup utf-8 bom
- }
- }
-
- // Parse XML declaration (<?xml...)
- template<int Flags>
- xml_node<Ch> *parse_xml_declaration(Ch *&text) {
- // If parsing of declaration is disabled
- if (!(Flags & parse_declaration_node)) {
- // Skip until end of declaration
- while (text[0] != Ch('?') || text[1] != Ch('>')) {
- if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- ++text;
- }
- text += 2; // Skip '?>'
- return 0;
- }
-
- // Create declaration
- xml_node<Ch> *declaration = this->allocate_node(node_declaration);
-
- // Skip whitespace before attributes or ?>
- skip<whitespace_pred, Flags>(text);
-
- // Parse declaration attributes
- parse_node_attributes<Flags>(text, declaration);
-
- // Skip ?>
- if (text[0] != Ch('?') || text[1] != Ch('>'))
- RAPIDXML_PARSE_ERROR("expected ?>", text);
- text += 2;
-
- return declaration;
- }
-
- // Parse XML comment (<!--...)
- template<int Flags>
- xml_node<Ch> *parse_comment(Ch *&text) {
- // If parsing of comments is disabled
- if (!(Flags & parse_comment_nodes)) {
- // Skip until end of comment
- while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>')) {
- if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- ++text;
- }
- text += 3; // Skip '-->'
- return 0; // Do not produce comment node
- }
-
- // Remember value start
- Ch *value = text;
-
- // Skip until end of comment
- while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>')) {
- if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- ++text;
- }
-
- // Create comment node
- xml_node<Ch> *comment = this->allocate_node(node_comment);
- comment->value(value, text - value);
-
- // Place zero terminator after comment value
- if (!(Flags & parse_no_string_terminators)) *text = Ch('\0');
-
- text += 3; // Skip '-->'
- return comment;
- }
-
- // Parse DOCTYPE
- template<int Flags>
- xml_node<Ch> *parse_doctype(Ch *&text) {
- // Remember value start
- Ch *value = text;
-
- // Skip to >
- while (*text != Ch('>')) {
- // Determine character type
- switch (*text) {
-
- // If '[' encountered, scan for matching ending ']' using naive algorithm with depth
- // This works for all W3C test files except for 2 most wicked
- case Ch('['): {
- ++text; // Skip '['
- int depth = 1;
- while (depth > 0) {
- switch (*text) {
- case Ch('['):
- ++depth;
- break;
- case Ch(']'):
- --depth;
- break;
- case 0:
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- }
- ++text;
- }
- break;
- }
-
- // Error on end of text
- case Ch('\0'):
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-
- // Other character, skip it
- default:
- ++text;
-
- }
- }
-
- // If DOCTYPE nodes enabled
- if (Flags & parse_doctype_node) {
- // Create a new doctype node
- xml_node<Ch> *doctype = this->allocate_node(node_doctype);
- doctype->value(value, text - value);
-
- // Place zero terminator after value
- if (!(Flags & parse_no_string_terminators)) *text = Ch('\0');
-
- text += 1; // skip '>'
- return doctype;
- } else {
- text += 1; // skip '>'
- return 0;
- }
-
- }
-
- // Parse PI
- template<int Flags>
- xml_node<Ch> *parse_pi(Ch *&text) {
- // If creation of PI nodes is enabled
- if (Flags & parse_pi_nodes) {
- // Create pi node
- xml_node<Ch> *pi = this->allocate_node(node_pi);
-
- // Extract PI target name
- Ch *name = text;
- skip<node_name_pred, Flags>(text);
- if (text == name)
- RAPIDXML_PARSE_ERROR("expected PI target", text);
- pi->name(name, text - name);
-
- // Skip whitespace between pi target and pi
- skip<whitespace_pred, Flags>(text);
-
- // Remember start of pi
- Ch *value = text;
-
- // Skip to '?>'
- while (text[0] != Ch('?') || text[1] != Ch('>')) {
- if (*text == Ch('\0'))
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- ++text;
- }
-
- // Set pi value (verbatim, no entity expansion or whitespace normalization)
- pi->value(value, text - value);
-
- // Place zero terminator after name and value
- if (!(Flags & parse_no_string_terminators)) {
- pi->name()[pi->name_size()] = Ch('\0');
- pi->value()[pi->value_size()] = Ch('\0');
- }
-
- text += 2; // Skip '?>'
- return pi;
- } else {
- // Skip to '?>'
- while (text[0] != Ch('?') || text[1] != Ch('>')) {
- if (*text == Ch('\0'))
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- ++text;
- }
- text += 2; // Skip '?>'
- return 0;
- }
- }
-
- // Parse and append data
- // Return character that ends data.
- // This is necessary because this character might have been overwritten by a terminating 0
- template<int Flags>
- Ch parse_and_append_data(xml_node<Ch> *node, Ch *&text, Ch *contents_start) {
- // Backup to contents start if whitespace trimming is disabled
- if (!(Flags & parse_trim_whitespace)) text = contents_start;
-
- // Skip until end of data
- Ch *value = text, *end;
- if (Flags & parse_normalize_whitespace)
- end = skip_and_expand_character_refs<text_pred, text_pure_with_ws_pred,
- Flags>(text);
- else end = skip_and_expand_character_refs<text_pred, text_pure_no_ws_pred,
- Flags>(text);
-
- // Trim trailing whitespace if flag is set; leading was already trimmed by whitespace skip after >
- if (Flags & parse_trim_whitespace) {
- if (Flags & parse_normalize_whitespace) {
- // Whitespace is already condensed to single space characters by skipping function, so just trim 1 char off the end
- if (*(end - 1) == Ch(' ')) --end;
- } else {
- // Backup until non-whitespace character is found
- while (whitespace_pred::test(*(end - 1)))
- --end;
- }
- }
-
- // If characters are still left between end and value (this test is only necessary if normalization is enabled)
- // Create new data node
- if (!(Flags & parse_no_data_nodes)) {
- xml_node<Ch> *data = this->allocate_node(node_data);
- data->value(value, end - value);
- node->append_node(data);
- }
-
- // Add data to parent node if no data exists yet
- if (!(Flags & parse_no_element_values))
- if (*node->value() == Ch('\0')) node->value(value, end - value);
-
- // Place zero terminator after value
- if (!(Flags & parse_no_string_terminators)) {
- Ch ch = *text;
- *end = Ch('\0');
- return ch; // Return character that ends data; this is required because zero terminator overwritten it
- }
-
- // Return character that ends data
- return *text;
- }
-
- // Parse CDATA
- template<int Flags>
- xml_node<Ch> *parse_cdata(Ch *&text) {
- // If CDATA is disabled
- if (Flags & parse_no_data_nodes) {
- // Skip until end of cdata
- while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) {
- if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- ++text;
- }
- text += 3; // Skip ]]>
- return 0; // Do not produce CDATA node
- }
-
- // Skip until end of cdata
- Ch *value = text;
- while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) {
- if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- ++text;
- }
-
- // Create new cdata node
- xml_node<Ch> *cdata = this->allocate_node(node_cdata);
- cdata->value(value, text - value);
-
- // Place zero terminator after value
- if (!(Flags & parse_no_string_terminators)) *text = Ch('\0');
-
- text += 3; // Skip ]]>
- return cdata;
- }
-
- // Parse element node
- template<int Flags>
- xml_node<Ch> *parse_element(Ch *&text) {
- // Create element node
- xml_node<Ch> *element = this->allocate_node(node_element);
-
- // Extract element name
- Ch *name = text;
- skip<node_name_pred, Flags>(text);
- if (text == name)
- RAPIDXML_PARSE_ERROR("expected element name", text);
- element->name(name, text - name);
-
- // Skip whitespace between element name and attributes or >
- skip<whitespace_pred, Flags>(text);
-
- // Parse attributes, if any
- parse_node_attributes<Flags>(text, element);
-
- // Determine ending type
- if (*text == Ch('>')) {
- ++text;
- parse_node_contents<Flags>(text, element);
- } else if (*text == Ch('/')) {
- ++text;
- if (*text != Ch('>'))
- RAPIDXML_PARSE_ERROR("expected >", text);
- ++text;
- } else
- RAPIDXML_PARSE_ERROR("expected >", text);
-
- // Place zero terminator after name
- if (!(Flags & parse_no_string_terminators))
- element->name()[element->name_size()] = Ch('\0');
-
- // Return parsed element
- return element;
- }
-
- // Determine node type, and parse it
- template<int Flags>
- xml_node<Ch> *parse_node(Ch *&text) {
- // Parse proper node type
- switch (text[0]) {
-
- // <...
- default:
- // Parse and append element node
- return parse_element<Flags>(text);
-
- // <?...
- case Ch('?'):
- ++text; // Skip ?
- if ((text[0] == Ch('x') || text[0] == Ch('X'))
- && (text[1] == Ch('m') || text[1] == Ch('M'))
- && (text[2] == Ch('l') || text[2] == Ch('L'))
- && whitespace_pred::test(text[3])) {
- // '<?xml ' - xml declaration
- text += 4; // Skip 'xml '
- return parse_xml_declaration<Flags>(text);
- } else {
- // Parse PI
- return parse_pi<Flags>(text);
- }
-
- // <!...
- case Ch('!'):
-
- // Parse proper subset of <! node
- switch (text[1]) {
-
- // <!-
- case Ch('-'):
- if (text[2] == Ch('-')) {
- // '<!--' - xml comment
- text += 3; // Skip '!--'
- return parse_comment<Flags>(text);
- }
- break;
-
- // <![
- case Ch('['):
- if (text[2] == Ch('C') && text[3] == Ch('D') && text[4] == Ch('A')
- && text[5] == Ch('T') && text[6] == Ch('A')
- && text[7] == Ch('[')) {
- // '<![CDATA[' - cdata
- text += 8; // Skip '![CDATA['
- return parse_cdata<Flags>(text);
- }
- break;
-
- // <!D
- case Ch('D'):
- if (text[2] == Ch('O') && text[3] == Ch('C') && text[4] == Ch('T')
- && text[5] == Ch('Y') && text[6] == Ch('P')
- && text[7] == Ch('E') && whitespace_pred::test(text[8])) {
- // '<!DOCTYPE ' - doctype
- text += 9; // skip '!DOCTYPE '
- return parse_doctype<Flags>(text);
- }
-
- } // switch
-
- // Attempt to skip other, unrecognized node types starting with <!
- ++text; // Skip !
- while (*text != Ch('>')) {
- if (*text == 0)
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
- ++text;
- }
- ++text; // Skip '>'
- return 0; // No node recognized
-
- }
- }
-
- // Parse contents of the node - children, data etc.
- template<int Flags>
- void parse_node_contents(Ch *&text, xml_node<Ch> *node) {
- // For all children and text
- while (1) {
- // Skip whitespace between > and node contents
- Ch *contents_start = text; // Store start of node contents before whitespace is skipped
- skip<whitespace_pred, Flags>(text);
- Ch next_char = *text;
-
- // After data nodes, instead of continuing the loop, control jumps here.
- // This is because zero termination inside parse_and_append_data() function
- // would wreak havoc with the above code.
- // Also, skipping whitespace after data nodes is unnecessary.
- after_data_node:
-
- // Determine what comes next: node closing, child node, data node, or 0?
- switch (next_char) {
-
- // Node closing or child node
- case Ch('<'):
- if (text[1] == Ch('/')) {
- // Node closing
- text += 2; // Skip '</'
- if (Flags & parse_validate_closing_tags) {
- // Skip and validate closing tag name
- Ch *closing_name = text;
- skip<node_name_pred, Flags>(text);
- if (!internal::compare(node->name(), node->name_size(),
- closing_name, text - closing_name, true))
- RAPIDXML_PARSE_ERROR("invalid closing tag name", text);
- } else {
- // No validation, just skip name
- skip<node_name_pred, Flags>(text);
- }
- // Skip remaining whitespace after node name
- skip<whitespace_pred, Flags>(text);
- if (*text != Ch('>'))
- RAPIDXML_PARSE_ERROR("expected >", text);
- ++text; // Skip '>'
- return; // Node closed, finished parsing contents
- } else {
- // Child node
- ++text; // Skip '<'
- if (xml_node<Ch> *child = parse_node<Flags>(text))
- node->append_node(child);
- }
- break;
-
- // End of data - error
- case Ch('\0'):
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
-
- // Data node
- default:
- next_char = parse_and_append_data<Flags>(node, text, contents_start);
- goto after_data_node;
- // Bypass regular processing after data nodes
-
- }
- }
- }
-
- // Parse XML attributes of the node
- template<int Flags>
- void parse_node_attributes(Ch *&text, xml_node<Ch> *node) {
- // For all attributes
- while (attribute_name_pred::test(*text)) {
- // Extract attribute name
- Ch *name = text;
- ++text; // Skip first character of attribute name
- skip<attribute_name_pred, Flags>(text);
- if (text == name)
- RAPIDXML_PARSE_ERROR("expected attribute name", name);
-
- // Create new attribute
- xml_attribute<Ch> *attribute = this->allocate_attribute();
- attribute->name(name, text - name);
- node->append_attribute(attribute);
-
- // Skip whitespace after attribute name
- skip<whitespace_pred, Flags>(text);
-
- // Skip =
- if (*text != Ch('='))
- RAPIDXML_PARSE_ERROR("expected =", text);
- ++text;
-
- // Add terminating zero after name
- if (!(Flags & parse_no_string_terminators))
- attribute->name()[attribute->name_size()] = 0;
-
- // Skip whitespace after =
- skip<whitespace_pred, Flags>(text);
-
- // Skip quote and remember if it was ' or "
- Ch quote = *text;
- if (quote != Ch('\'') && quote != Ch('"'))
- RAPIDXML_PARSE_ERROR("expected ' or \"", text);
- ++text;
-
- // Extract attribute value and expand char refs in it
- Ch *value = text, *end;
- const int AttFlags = Flags & ~parse_normalize_whitespace; // No whitespace normalization in attributes
- if (quote == Ch('\''))
- end = skip_and_expand_character_refs<attribute_value_pred<Ch('\'')>,
- attribute_value_pure_pred<Ch('\'')>, AttFlags>(text);
- else end = skip_and_expand_character_refs<attribute_value_pred<Ch('"')>,
- attribute_value_pure_pred<Ch('"')>, AttFlags>(text);
-
- // Set attribute value
- attribute->value(value, end - value);
-
- // Make sure that end quote is present
- if (*text != quote)
- RAPIDXML_PARSE_ERROR("expected ' or \"", text);
- ++text; // Skip quote
-
- // Add terminating zero after value
- if (!(Flags & parse_no_string_terminators))
- attribute->value()[attribute->value_size()] = 0;
-
- // Skip whitespace after attribute value
- skip<whitespace_pred, Flags>(text);
- }
- }
-
-};
-
-//! \cond internal
-namespace internal {
-
-// Whitespace (space \n \r \t)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_whitespace[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, // 0
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
- 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 7
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // C
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // D
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // E
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // F
- };
-
-// Node name (anything but space \n \r \t / > ? \0)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_node_name[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Text (i.e. PCDATA) (anything but < \0)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_text[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Text (i.e. PCDATA) that does not require processing when ws normalization is disabled
-// (anything but < \0 &)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_text_pure_no_ws[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Text (i.e. PCDATA) that does not require processing when ws normalizationis is enabled
-// (anything but < \0 & space \n \r \t)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_text_pure_with_ws[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Attribute name (anything but space \n \r \t / < > = ? ! \0)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_attribute_name[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Attribute data with single quote (anything but ' \0)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Attribute data with single quote that does not require processing (anything but ' \0 &)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1_pure[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Attribute data with double quote (anything but " \0)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Attribute data with double quote that does not require processing (anything but " \0 &)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2_pure[256] = {
-// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
- 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
- };
-
-// Digits (dec and hex, 255 denotes end of numeric character reference)
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_digits[256] = {
- // 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 0
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 1
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 2
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255,
- 255, // 3
- 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 4
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 5
- 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 6
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 7
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 8
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // 9
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // A
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // B
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // C
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // D
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, // E
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255 // F
- };
-
-// Upper case conversion
-template<int Dummy>
-const unsigned char lookup_tables<Dummy>::lookup_upcase[256] = {
- // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A B C D E F
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, // 0
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
- 31, // 1
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
- 47, // 2
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
- 63, // 3
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
- 79, // 4
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
- 95, // 5
- 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
- 79, // 6
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123, 124, 125, 126,
- 127, // 7
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
- 143, // 8
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158,
- 159, // 9
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
- 175, // A
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
- 191, // B
- 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
- 207, // C
- 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222,
- 223, // D
- 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
- 239, // E
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
- 255 // F
- };
-}
-//! \endcond
-
-}
-
-// Undefine internal macros
-#undef RAPIDXML_PARSE_ERROR
-
-// On MSVC, restore warnings state
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-
-#endif