Chris@16: // ---------------------------------------------------------------------------- Chris@16: // Copyright (C) 2006, 2009 Marcin Kalicinski Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // For more information, see www.boost.org Chris@16: // ---------------------------------------------------------------------------- Chris@16: #ifndef BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED Chris@16: #define BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED Chris@16: Chris@16: //! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation Chris@16: Chris@16: #include Chris@16: #include // For std::size_t Chris@16: #include // For placement new Chris@16: Chris@16: // On MSVC, disable "conditional expression is constant" warning (level 4). Chris@16: // This warning is almost impossible to avoid with certain types of templated code Chris@16: #ifdef _MSC_VER Chris@16: #pragma warning(push) Chris@16: #pragma warning(disable:4127) // Conditional expression is constant Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR Chris@16: Chris@16: #include // For std::exception Chris@16: Chris@16: #define BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where) Chris@16: Chris@16: namespace boost { namespace property_tree { namespace detail {namespace rapidxml Chris@16: { Chris@16: Chris@16: //! Parse error exception. Chris@16: //! This exception is thrown by the parser when an error occurs. Chris@16: //! Use what() function to get human-readable error message. Chris@16: //! Use where() function to get a pointer to position within source text where error was detected. Chris@16: //!

Chris@16: //! If throwing exceptions by the parser is undesirable, Chris@16: //! it can be disabled by defining RAPIDXML_NO_EXCEPTIONS macro before rapidxml.hpp is included. Chris@16: //! This will cause the parser to call rapidxml::parse_error_handler() function instead of throwing an exception. Chris@16: //! This function must be defined by the user. Chris@16: //!

Chris@16: //! This class derives from std::exception class. Chris@16: class parse_error: public std::exception Chris@16: { Chris@16: Chris@16: public: Chris@16: Chris@16: //! Constructs parse error Chris@16: parse_error(const char *wa, void *we) Chris@16: : m_what(wa) Chris@16: , m_where(we) Chris@16: { Chris@16: } Chris@16: Chris@16: //! Gets human readable description of error. Chris@16: //! \return Pointer to null terminated description of the error. Chris@16: virtual const char *what() const throw() Chris@16: { Chris@16: return m_what; Chris@16: } Chris@16: Chris@16: //! Gets pointer to character data where error happened. Chris@16: //! Ch should be the same as char type of xml_document that produced the error. Chris@16: //! \return Pointer to location within the parsed string where error occured. Chris@16: template Chris@16: Ch *where() const Chris@16: { Chris@16: return reinterpret_cast(m_where); Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: const char *m_what; Chris@16: void *m_where; Chris@16: Chris@16: }; Chris@16: }}}} Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Pool sizes Chris@16: Chris@16: #ifndef BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE Chris@16: // Size of static memory block of memory_pool. Chris@16: // Define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value. Chris@16: // No dynamic memory allocations are performed by memory_pool until static memory is exhausted. Chris@16: #define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE (64 * 1024) Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE Chris@16: // Size of dynamic memory block of memory_pool. Chris@16: // Define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value. Chris@16: // After the static block is exhausted, dynamic blocks with approximately this size are allocated by memory_pool. Chris@16: #define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024) Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT Chris@16: // Memory allocation alignment. Chris@16: // Define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer. Chris@16: // All memory allocations for nodes, attributes and strings will be aligned to this value. Chris@16: // This must be a power of 2 and at least 1, otherwise memory_pool will not work. Chris@16: #define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT sizeof(void *) Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace property_tree { namespace detail {namespace rapidxml Chris@16: { Chris@16: // Forward declarations Chris@16: template class xml_node; Chris@16: template class xml_attribute; Chris@16: template class xml_document; Chris@16: Chris@16: //! Enumeration listing all node types produced by the parser. Chris@16: //! Use xml_node::type() function to query node type. Chris@16: enum node_type Chris@16: { Chris@16: node_document, //!< A document node. Name and value are empty. Chris@16: node_element, //!< An element node. Name contains element name. Value contains text of first data node. Chris@16: node_data, //!< A data node. Name is empty. Value contains data text. Chris@16: node_cdata, //!< A CDATA node. Name is empty. Value contains data text. Chris@16: node_comment, //!< A comment node. Name is empty. Value contains comment text. Chris@16: node_declaration, //!< A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes. Chris@16: node_doctype, //!< A DOCTYPE node. Name is empty. Value contains DOCTYPE text. Chris@16: node_pi //!< A PI node. Name contains target. Value contains instructions. Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // Parsing flags Chris@16: Chris@16: //! Parse flag instructing the parser to not create data nodes. Chris@16: //! Text of first data node will still be placed in value of parent element, unless rapidxml::parse_no_element_values flag is also specified. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_no_data_nodes = 0x1; Chris@16: Chris@16: //! Parse flag instructing the parser to not use text of first data node as a value of parent element. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //! Note that child data nodes of element node take precendence over its value when printing. Chris@16: //! That is, if element has one or more child data nodes and a value, the value will be ignored. Chris@16: //! Use rapidxml::parse_no_data_nodes flag to prevent creation of data nodes if you want to manipulate data using values of elements. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_no_element_values = 0x2; Chris@16: Chris@16: //! Parse flag instructing the parser to not place zero terminators after strings in the source text. Chris@16: //! By default zero terminators are placed, modifying source text. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_no_string_terminators = 0x4; Chris@16: Chris@16: //! Parse flag instructing the parser to not translate entities in the source text. Chris@16: //! By default entities are translated, modifying source text. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_no_entity_translation = 0x8; Chris@16: Chris@16: //! Parse flag instructing the parser to disable UTF-8 handling and assume plain 8 bit characters. Chris@16: //! By default, UTF-8 handling is enabled. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_no_utf8 = 0x10; Chris@16: Chris@16: //! Parse flag instructing the parser to create XML declaration node. Chris@16: //! By default, declaration node is not created. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_declaration_node = 0x20; Chris@16: Chris@16: //! Parse flag instructing the parser to create comments nodes. Chris@16: //! By default, comment nodes are not created. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_comment_nodes = 0x40; Chris@16: Chris@16: //! Parse flag instructing the parser to create DOCTYPE node. Chris@16: //! By default, doctype node is not created. Chris@16: //! Although W3C specification allows at most one DOCTYPE node, RapidXml will silently accept documents with more than one. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_doctype_node = 0x80; Chris@16: Chris@16: //! Parse flag instructing the parser to create PI nodes. Chris@16: //! By default, PI nodes are not created. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_pi_nodes = 0x100; Chris@16: Chris@16: //! Parse flag instructing the parser to validate closing tag names. Chris@16: //! If not set, name inside closing tag is irrelevant to the parser. Chris@16: //! By default, closing tags are not validated. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_validate_closing_tags = 0x200; Chris@16: Chris@16: //! Parse flag instructing the parser to trim all leading and trailing whitespace of data nodes. Chris@16: //! By default, whitespace is not trimmed. Chris@16: //! This flag does not cause the parser to modify source text. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_trim_whitespace = 0x400; Chris@16: Chris@16: //! Parse flag instructing the parser to condense all whitespace runs of data nodes to a single space character. Chris@16: //! Trimming of leading and trailing whitespace of data is controlled by rapidxml::parse_trim_whitespace flag. Chris@16: //! By default, whitespace is not normalized. Chris@16: //! If this flag is specified, source text will be modified. Chris@16: //! Can be combined with other flags by use of | operator. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_normalize_whitespace = 0x800; Chris@16: Chris@16: // Compound flags Chris@16: Chris@16: //! Parse flags which represent default behaviour of the parser. Chris@16: //! This is always equal to 0, so that all other flags can be simply ored together. Chris@16: //! Normally there is no need to inconveniently disable flags by anding with their negated (~) values. Chris@16: //! This also means that meaning of each flag is a negation of the default setting. Chris@16: //! For example, if flag name is rapidxml::parse_no_utf8, it means that utf-8 is enabled by default, Chris@16: //! and using the flag will disable it. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_default = 0; Chris@16: Chris@16: //! A combination of parse flags that forbids any modifications of the source text. Chris@16: //! This also results in faster parsing. However, note that the following will occur: Chris@16: //!
    Chris@16: //!
  • 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
  • Chris@16: //!
  • entities will not be translated
  • Chris@16: //!
  • whitespace will not be normalized
  • Chris@16: //!
Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_non_destructive = parse_no_string_terminators | parse_no_entity_translation; Chris@16: Chris@16: //! A combination of parse flags resulting in fastest possible parsing, without sacrificing important data. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_fastest = parse_non_destructive | parse_no_data_nodes; Chris@16: Chris@16: //! A combination of parse flags resulting in largest amount of data being extracted. Chris@16: //! This usually results in slowest parsing. Chris@16: //!

Chris@16: //! See xml_document::parse() function. Chris@16: const int parse_full = parse_declaration_node | parse_comment_nodes | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // Internals Chris@16: Chris@16: //! \cond internal Chris@16: namespace internal Chris@16: { Chris@16: Chris@16: // Struct that contains lookup tables for the parser Chris@16: // It must be a template to allow correct linking (because it has static data members, which are defined in a header file). Chris@16: template Chris@16: struct lookup_tables Chris@16: { Chris@16: static const unsigned char lookup_whitespace[256]; // Whitespace table Chris@16: static const unsigned char lookup_node_name[256]; // Node name table Chris@16: static const unsigned char lookup_text[256]; // Text table Chris@16: static const unsigned char lookup_text_pure_no_ws[256]; // Text table Chris@16: static const unsigned char lookup_text_pure_with_ws[256]; // Text table Chris@16: static const unsigned char lookup_attribute_name[256]; // Attribute name table Chris@16: static const unsigned char lookup_attribute_data_1[256]; // Attribute data table with single quote Chris@16: static const unsigned char lookup_attribute_data_1_pure[256]; // Attribute data table with single quote Chris@16: static const unsigned char lookup_attribute_data_2[256]; // Attribute data table with double quotes Chris@16: static const unsigned char lookup_attribute_data_2_pure[256]; // Attribute data table with double quotes Chris@16: static const unsigned char lookup_digits[256]; // Digits Chris@16: static const unsigned char lookup_upcase[256]; // To uppercase conversion table for ASCII characters Chris@16: }; Chris@16: Chris@16: // Find length of the string Chris@16: template Chris@16: inline std::size_t measure(const Ch *p) Chris@16: { Chris@16: const Ch *tmp = p; Chris@16: while (*tmp) Chris@16: ++tmp; Chris@16: return tmp - p; Chris@16: } Chris@16: Chris@16: // Compare strings for equality Chris@16: template Chris@16: inline bool compare(const Ch *p1, std::size_t size1, const Ch *p2, std::size_t size2, bool case_sensitive) Chris@16: { Chris@16: if (size1 != size2) Chris@16: return false; Chris@16: if (case_sensitive) Chris@16: { Chris@16: for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2) Chris@16: if (*p1 != *p2) Chris@16: return false; Chris@16: } Chris@16: else Chris@16: { Chris@16: for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2) Chris@16: if (lookup_tables<0>::lookup_upcase[static_cast(*p1)] != lookup_tables<0>::lookup_upcase[static_cast(*p2)]) Chris@16: return false; Chris@16: } Chris@16: return true; Chris@16: } Chris@16: Chris@16: template Chris@16: inline size_t get_index(const Ch c) Chris@16: { Chris@16: // If not ASCII char, its semantic is same as plain 'z'. Chris@16: // char could be signed, so first stretch and make unsigned. Chris@16: unsigned n = c; Chris@16: if (n > 127) Chris@16: { Chris@16: return 'z'; Chris@16: } Chris@16: return c; Chris@16: } Chris@16: } Chris@16: //! \endcond Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // Memory pool Chris@16: Chris@16: //! This class is used by the parser to create new nodes and attributes, without overheads of dynamic memory allocation. Chris@16: //! In most cases, you will not need to use this class directly. Chris@16: //! However, if you need to create nodes manually or modify names/values of nodes, Chris@16: //! you are encouraged to use memory_pool of relevant xml_document to allocate the memory. Chris@16: //! Not only is this faster than allocating them by using new operator, Chris@16: //! but also their lifetime will be tied to the lifetime of document, Chris@16: //! possibly simplyfing memory management. Chris@16: //!

Chris@16: //! Call allocate_node() or allocate_attribute() functions to obtain new nodes or attributes from the pool. Chris@16: //! You can also call allocate_string() function to allocate strings. Chris@16: //! Such strings can then be used as names or values of nodes without worrying about their lifetime. Chris@16: //! Note that there is no free() function -- all allocations are freed at once when clear() function is called, Chris@16: //! or when the pool is destroyed. Chris@16: //!

Chris@16: //! It is also possible to create a standalone memory_pool, and use it Chris@16: //! to allocate nodes, whose lifetime will not be tied to any document. Chris@16: //!

Chris@16: //! Pool maintains BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE bytes of statically allocated memory. Chris@16: //! Until static memory is exhausted, no dynamic memory allocations are done. Chris@16: //! When static memory is exhausted, pool allocates additional blocks of memory of size BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE each, Chris@16: //! by using global new[] and delete[] operators. Chris@16: //! This behaviour can be changed by setting custom allocation routines. Chris@16: //! Use set_allocator() function to set them. Chris@16: //!

Chris@16: //! Allocations for nodes, attributes and strings are aligned at BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT bytes. Chris@16: //! This value defaults to the size of pointer on target architecture. Chris@16: //!

Chris@16: //! To obtain absolutely top performance from the parser, Chris@16: //! it is important that all nodes are allocated from a single, contiguous block of memory. Chris@16: //! Otherwise, cache misses when jumping between two (or more) disjoint blocks of memory can slow down parsing quite considerably. Chris@16: //! If required, you can tweak BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE, BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE and BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT Chris@16: //! to obtain best wasted memory to performance compromise. Chris@16: //! To do it, define their values before rapidxml.hpp file is included. Chris@16: //! \param Ch Character type of created nodes. Chris@16: template Chris@16: class memory_pool Chris@16: { Chris@16: Chris@16: public: Chris@16: Chris@16: //! \cond internal Chris@16: // Prefixed names to work around weird MSVC lookup bug. Chris@16: typedef void *(boost_ptree_raw_alloc_func)(std::size_t); // Type of user-defined function used to allocate memory Chris@16: typedef void (boost_ptree_raw_free_func)(void *); // Type of user-defined function used to free memory Chris@16: //! \endcond Chris@16: Chris@16: //! Constructs empty pool with default allocator functions. Chris@16: memory_pool() Chris@16: : m_alloc_func(0) Chris@16: , m_free_func(0) Chris@16: { Chris@16: init(); Chris@16: } Chris@16: Chris@16: //! Destroys pool and frees all the memory. Chris@16: //! This causes memory occupied by nodes allocated by the pool to be freed. Chris@16: //! Nodes allocated from the pool are no longer valid. Chris@16: ~memory_pool() Chris@16: { Chris@16: clear(); Chris@16: } Chris@16: Chris@16: //! Allocates a new node from the pool, and optionally assigns name and value to it. Chris@16: //! If the allocation request cannot be accomodated, this function will throw std::bad_alloc. Chris@16: //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function Chris@16: //! will call rapidxml::parse_error_handler() function. Chris@16: //! \param type Type of node to create. Chris@16: //! \param name Name to assign to the node, or 0 to assign no name. Chris@16: //! \param value Value to assign to the node, or 0 to assign no value. Chris@16: //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string. Chris@16: //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string. Chris@16: //! \return Pointer to allocated node. This pointer will never be NULL. Chris@16: xml_node *allocate_node(node_type type, Chris@16: const Ch *name = 0, const Ch *value = 0, Chris@16: std::size_t name_size = 0, std::size_t value_size = 0) Chris@16: { Chris@16: void *memory = allocate_aligned(sizeof(xml_node)); Chris@16: xml_node *node = new(memory) xml_node(type); Chris@16: if (name) Chris@16: { Chris@16: if (name_size > 0) Chris@16: node->name(name, name_size); Chris@16: else Chris@16: node->name(name); Chris@16: } Chris@16: if (value) Chris@16: { Chris@16: if (value_size > 0) Chris@16: node->value(value, value_size); Chris@16: else Chris@16: node->value(value); Chris@16: } Chris@16: return node; Chris@16: } Chris@16: Chris@16: //! Allocates a new attribute from the pool, and optionally assigns name and value to it. Chris@16: //! If the allocation request cannot be accomodated, this function will throw std::bad_alloc. Chris@16: //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function Chris@16: //! will call rapidxml::parse_error_handler() function. Chris@16: //! \param name Name to assign to the attribute, or 0 to assign no name. Chris@16: //! \param value Value to assign to the attribute, or 0 to assign no value. Chris@16: //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string. Chris@16: //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string. Chris@16: //! \return Pointer to allocated attribute. This pointer will never be NULL. Chris@16: xml_attribute *allocate_attribute(const Ch *name = 0, const Ch *value = 0, Chris@16: std::size_t name_size = 0, std::size_t value_size = 0) Chris@16: { Chris@16: void *memory = allocate_aligned(sizeof(xml_attribute)); Chris@16: xml_attribute *attribute = new(memory) xml_attribute; Chris@16: if (name) Chris@16: { Chris@16: if (name_size > 0) Chris@16: attribute->name(name, name_size); Chris@16: else Chris@16: attribute->name(name); Chris@16: } Chris@16: if (value) Chris@16: { Chris@16: if (value_size > 0) Chris@16: attribute->value(value, value_size); Chris@16: else Chris@16: attribute->value(value); Chris@16: } Chris@16: return attribute; Chris@16: } Chris@16: Chris@16: //! Allocates a char array of given size from the pool, and optionally copies a given string to it. Chris@16: //! If the allocation request cannot be accomodated, this function will throw std::bad_alloc. Chris@16: //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function Chris@16: //! will call rapidxml::parse_error_handler() function. Chris@16: //! \param source String to initialize the allocated memory with, or 0 to not initialize it. Chris@16: //! \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. Chris@16: //! \return Pointer to allocated char array. This pointer will never be NULL. Chris@16: Ch *allocate_string(const Ch *source = 0, std::size_t size = 0) Chris@16: { Chris@16: BOOST_ASSERT(source || size); // Either source or size (or both) must be specified Chris@16: if (size == 0) Chris@16: size = internal::measure(source) + 1; Chris@16: Ch *result = static_cast(allocate_aligned(size * sizeof(Ch))); Chris@16: if (source) Chris@16: for (std::size_t i = 0; i < size; ++i) Chris@16: result[i] = source[i]; Chris@16: return result; Chris@16: } Chris@16: Chris@16: //! Clones an xml_node and its hierarchy of child nodes and attributes. Chris@16: //! Nodes and attributes are allocated from this memory pool. Chris@16: //! Names and values are not cloned, they are shared between the clone and the source. Chris@16: //! Result node can be optionally specified as a second parameter, Chris@16: //! in which case its contents will be replaced with cloned source node. Chris@16: //! This is useful when you want to clone entire document. Chris@16: //! \param source Node to clone. Chris@16: //! \param result Node to put results in, or 0 to automatically allocate result node Chris@16: //! \return Pointer to cloned node. This pointer will never be NULL. Chris@16: xml_node *clone_node(const xml_node *source, xml_node *result = 0) Chris@16: { Chris@16: // Prepare result node Chris@16: if (result) Chris@16: { Chris@16: result->remove_all_attributes(); Chris@16: result->remove_all_nodes(); Chris@16: result->type(source->type()); Chris@16: } Chris@16: else Chris@16: result = allocate_node(source->type()); Chris@16: Chris@16: // Clone name and value Chris@16: result->name(source->name(), source->name_size()); Chris@16: result->value(source->value(), source->value_size()); Chris@16: Chris@16: // Clone child nodes and attributes Chris@16: for (xml_node *child = source->first_node(); child; child = child->next_sibling()) Chris@16: result->append_node(clone_node(child)); Chris@16: for (xml_attribute *attr = source->first_attribute(); attr; attr = attr->next_attribute()) Chris@16: result->append_attribute(allocate_attribute(attr->name(), attr->value(), attr->name_size(), attr->value_size())); Chris@16: Chris@16: return result; Chris@16: } Chris@16: Chris@16: //! Clears the pool. Chris@16: //! This causes memory occupied by nodes allocated by the pool to be freed. Chris@16: //! Any nodes or strings allocated from the pool will no longer be valid. Chris@16: void clear() Chris@16: { Chris@16: while (m_begin != m_static_memory) Chris@16: { Chris@16: char *previous_begin = reinterpret_cast
(align(m_begin))->previous_begin; Chris@16: if (m_free_func) Chris@16: m_free_func(m_begin); Chris@16: else Chris@16: delete[] m_begin; Chris@16: m_begin = previous_begin; Chris@16: } Chris@16: init(); Chris@16: } Chris@16: Chris@16: //! Sets or resets the user-defined memory allocation functions for the pool. Chris@16: //! This can only be called when no memory is allocated from the pool yet, otherwise results are undefined. Chris@16: //! Allocation function must not return invalid pointer on failure. It should either throw, Chris@16: //! stop the program, or use longjmp() function to pass control to other place of program. Chris@16: //! If it returns invalid pointer, results are undefined. Chris@16: //!

Chris@16: //! User defined allocation functions must have the following forms: Chris@16: //!
Chris@16: //!
void *allocate(std::size_t size); Chris@16: //!
void free(void *pointer); Chris@16: //!

Chris@16: //! \param af Allocation function, or 0 to restore default function Chris@16: //! \param ff Free function, or 0 to restore default function Chris@16: void set_allocator(boost_ptree_raw_alloc_func *af, boost_ptree_raw_free_func *ff) Chris@16: { Chris@16: BOOST_ASSERT(m_begin == m_static_memory && m_ptr == align(m_begin)); // Verify that no memory is allocated yet Chris@16: m_alloc_func = af; Chris@16: m_free_func = ff; Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: struct header Chris@16: { Chris@16: char *previous_begin; Chris@16: }; Chris@16: Chris@16: void init() Chris@16: { Chris@16: m_begin = m_static_memory; Chris@16: m_ptr = align(m_begin); Chris@16: m_end = m_static_memory + sizeof(m_static_memory); Chris@16: } Chris@16: Chris@16: char *align(char *ptr) Chris@16: { Chris@16: std::size_t alignment = ((BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - (std::size_t(ptr) & (BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 1))) & (BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 1)); Chris@16: return ptr + alignment; Chris@16: } Chris@16: Chris@16: char *allocate_raw(std::size_t size) Chris@16: { Chris@16: // Allocate Chris@16: void *memory; Chris@16: if (m_alloc_func) // Allocate memory using either user-specified allocation function or global operator new[] Chris@16: { Chris@16: memory = m_alloc_func(size); Chris@16: BOOST_ASSERT(memory); // Allocator is not allowed to return 0, on failure it must either throw, stop the program or use longjmp Chris@16: } Chris@16: else Chris@16: { Chris@16: memory = new char[size]; Chris@16: } Chris@16: return static_cast(memory); Chris@16: } Chris@16: Chris@16: void *allocate_aligned(std::size_t size) Chris@16: { Chris@16: // Calculate aligned pointer Chris@16: char *result = align(m_ptr); Chris@16: Chris@16: // If not enough memory left in current pool, allocate a new pool Chris@16: if (result + size > m_end) Chris@16: { Chris@16: // Calculate required pool size (may be bigger than BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE) Chris@16: std::size_t pool_size = BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE; Chris@16: if (pool_size < size) Chris@16: pool_size = size; Chris@16: Chris@16: // Allocate Chris@16: std::size_t alloc_size = sizeof(header) + (2 * BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 2) + pool_size; // 2 alignments required in worst case: one for header, one for actual allocation Chris@16: char *raw_memory = allocate_raw(alloc_size); Chris@16: Chris@16: // Setup new pool in allocated memory Chris@16: char *pool = align(raw_memory); Chris@16: header *new_header = reinterpret_cast
(pool); Chris@16: new_header->previous_begin = m_begin; Chris@16: m_begin = raw_memory; Chris@16: m_ptr = pool + sizeof(header); Chris@16: m_end = raw_memory + alloc_size; Chris@16: Chris@16: // Calculate aligned pointer again using new pool Chris@16: result = align(m_ptr); Chris@16: } Chris@16: Chris@16: // Update pool and return aligned pointer Chris@16: m_ptr = result + size; Chris@16: return result; Chris@16: } Chris@16: Chris@16: char *m_begin; // Start of raw memory making up current pool Chris@16: char *m_ptr; // First free byte in current pool Chris@16: char *m_end; // One past last available byte in current pool Chris@16: char m_static_memory[BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE]; // Static raw memory Chris@16: boost_ptree_raw_alloc_func *m_alloc_func; // Allocator function, or 0 if default is to be used Chris@16: boost_ptree_raw_free_func *m_free_func; // Free function, or 0 if default is to be used Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // XML base Chris@16: Chris@16: //! Base class for xml_node and xml_attribute implementing common functions: Chris@16: //! name(), name_size(), value(), value_size() and parent(). Chris@16: //! \param Ch Character type to use Chris@16: template Chris@16: class xml_base Chris@16: { Chris@16: Chris@16: public: Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Construction & destruction Chris@16: Chris@16: // Construct a base with empty name, value and parent Chris@16: xml_base() Chris@16: : m_name(0) Chris@16: , m_value(0) Chris@16: , m_parent(0) Chris@16: { Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Node data access Chris@16: Chris@16: //! Gets name of the node. Chris@16: //! Interpretation of name depends on type of node. Chris@16: //! Note that name will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse. Chris@16: //!

Chris@16: //! Use name_size() function to determine length of the name. Chris@16: //! \return Name of node, or empty string if node has no name. Chris@16: Ch *name() const Chris@16: { Chris@16: return m_name ? m_name : nullstr(); Chris@16: } Chris@16: Chris@16: //! Gets size of node name, not including terminator character. Chris@16: //! This function works correctly irrespective of whether name is or is not zero terminated. Chris@16: //! \return Size of node name, in characters. Chris@16: std::size_t name_size() const Chris@16: { Chris@16: return m_name ? m_name_size : 0; Chris@16: } Chris@16: Chris@16: //! Gets value of node. Chris@16: //! Interpretation of value depends on type of node. Chris@16: //! Note that value will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse. Chris@16: //!

Chris@16: //! Use value_size() function to determine length of the value. Chris@16: //! \return Value of node, or empty string if node has no value. Chris@16: Ch *value() const Chris@16: { Chris@16: return m_value ? m_value : nullstr(); Chris@16: } Chris@16: Chris@16: //! Gets size of node value, not including terminator character. Chris@16: //! This function works correctly irrespective of whether value is or is not zero terminated. Chris@16: //! \return Size of node value, in characters. Chris@16: std::size_t value_size() const Chris@16: { Chris@16: return m_value ? m_value_size : 0; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Node modification Chris@16: Chris@16: //! Sets name of node to a non zero-terminated string. Chris@16: //! See \ref ownership_of_strings. Chris@16: //!

Chris@16: //! Note that node does not own its name or value, it only stores a pointer to it. Chris@16: //! It will not delete or otherwise free the pointer on destruction. Chris@16: //! It is reponsibility of the user to properly manage lifetime of the string. Chris@16: //! The easiest way to achieve it is to use memory_pool of the document to allocate the string - Chris@16: //! on destruction of the document the string will be automatically freed. Chris@16: //!

Chris@16: //! Size of name must be specified separately, because name does not have to be zero terminated. Chris@16: //! Use name(const Ch *) function to have the length automatically calculated (string must be zero terminated). Chris@16: //! \param n Name of node to set. Does not have to be zero terminated. Chris@16: //! \param size Size of name, in characters. This does not include zero terminator, if one is present. Chris@16: void name(const Ch *n, std::size_t size) Chris@16: { Chris@16: m_name = const_cast(n); Chris@16: m_name_size = size; Chris@16: } Chris@16: Chris@16: //! Sets name of node to a zero-terminated string. Chris@16: //! See also \ref ownership_of_strings and xml_node::name(const Ch *, std::size_t). Chris@16: //! \param n Name of node to set. Must be zero terminated. Chris@16: void name(const Ch *n) Chris@16: { Chris@16: name(n, internal::measure(n)); Chris@16: } Chris@16: Chris@16: //! Sets value of node to a non zero-terminated string. Chris@16: //! See \ref ownership_of_strings. Chris@16: //!

Chris@16: //! Note that node does not own its name or value, it only stores a pointer to it. Chris@16: //! It will not delete or otherwise free the pointer on destruction. Chris@16: //! It is reponsibility of the user to properly manage lifetime of the string. Chris@16: //! The easiest way to achieve it is to use memory_pool of the document to allocate the string - Chris@16: //! on destruction of the document the string will be automatically freed. Chris@16: //!

Chris@16: //! Size of value must be specified separately, because it does not have to be zero terminated. Chris@16: //! Use value(const Ch *) function to have the length automatically calculated (string must be zero terminated). Chris@16: //!

Chris@16: //! If an element has a child node of type node_data, it will take precedence over element value when printing. Chris@16: //! 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. Chris@16: //! \param val value of node to set. Does not have to be zero terminated. Chris@16: //! \param size Size of value, in characters. This does not include zero terminator, if one is present. Chris@16: void value(const Ch *val, std::size_t size) Chris@16: { Chris@16: m_value = const_cast(val); Chris@16: m_value_size = size; Chris@16: } Chris@16: Chris@16: //! Sets value of node to a zero-terminated string. Chris@16: //! See also \ref ownership_of_strings and xml_node::value(const Ch *, std::size_t). Chris@16: //! \param val Vame of node to set. Must be zero terminated. Chris@16: void value(const Ch *val) Chris@16: { Chris@16: this->value(val, internal::measure(val)); Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Related nodes access Chris@16: Chris@16: //! Gets node parent. Chris@16: //! \return Pointer to parent node, or 0 if there is no parent. Chris@16: xml_node *parent() const Chris@16: { Chris@16: return m_parent; Chris@16: } Chris@16: Chris@16: protected: Chris@16: Chris@16: // Return empty string Chris@16: static Ch *nullstr() Chris@16: { Chris@16: static Ch zero = Ch('\0'); Chris@16: return &zero; Chris@16: } Chris@16: Chris@16: Ch *m_name; // Name of node, or 0 if no name Chris@16: Ch *m_value; // Value of node, or 0 if no value Chris@16: std::size_t m_name_size; // Length of node name, or undefined of no name Chris@16: std::size_t m_value_size; // Length of node value, or undefined if no value Chris@16: xml_node *m_parent; // Pointer to parent node, or 0 if none Chris@16: Chris@16: }; Chris@16: Chris@16: //! Class representing attribute node of XML document. Chris@16: //! Each attribute has name and value strings, which are available through name() and value() functions (inherited from xml_base). Chris@16: //! Note that after parse, both name and value of attribute will point to interior of source text used for parsing. Chris@16: //! Thus, this text must persist in memory for the lifetime of attribute. Chris@16: //! \param Ch Character type to use. Chris@16: template Chris@16: class xml_attribute: public xml_base Chris@16: { Chris@16: Chris@16: friend class xml_node; Chris@16: Chris@16: public: Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Construction & destruction Chris@16: Chris@16: //! Constructs an empty attribute with the specified type. Chris@16: //! Consider using memory_pool of appropriate xml_document if allocating attributes manually. Chris@16: xml_attribute() Chris@16: { Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Related nodes access Chris@16: Chris@16: //! Gets document of which attribute is a child. Chris@16: //! \return Pointer to document that contains this attribute, or 0 if there is no parent document. Chris@16: xml_document *document() const Chris@16: { Chris@16: if (xml_node *node = this->parent()) Chris@16: { Chris@16: while (node->parent()) Chris@16: node = node->parent(); Chris@16: return node->type() == node_document ? static_cast *>(node) : 0; Chris@16: } Chris@16: else Chris@16: return 0; Chris@16: } Chris@16: Chris@16: //! Gets previous attribute, optionally matching attribute name. Chris@16: //! \param n 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 nsize is non-zero Chris@16: //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string Chris@16: //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters Chris@16: //! \return Pointer to found attribute, or 0 if not found. Chris@16: xml_attribute *previous_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const Chris@16: { Chris@16: if (n) Chris@16: { Chris@16: if (nsize == 0) Chris@16: nsize = internal::measure(n); Chris@16: for (xml_attribute *attribute = m_prev_attribute; attribute; attribute = attribute->m_prev_attribute) Chris@16: if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive)) Chris@16: return attribute; Chris@16: return 0; Chris@16: } Chris@16: else Chris@16: return this->m_parent ? m_prev_attribute : 0; Chris@16: } Chris@16: Chris@16: //! Gets next attribute, optionally matching attribute name. Chris@16: //! \param n 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 nsize is non-zero Chris@16: //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string Chris@16: //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters Chris@16: //! \return Pointer to found attribute, or 0 if not found. Chris@16: xml_attribute *next_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const Chris@16: { Chris@16: if (n) Chris@16: { Chris@16: if (nsize == 0) Chris@16: nsize = internal::measure(n); Chris@16: for (xml_attribute *attribute = m_next_attribute; attribute; attribute = attribute->m_next_attribute) Chris@16: if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive)) Chris@16: return attribute; Chris@16: return 0; Chris@16: } Chris@16: else Chris@16: return this->m_parent ? m_next_attribute : 0; Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: xml_attribute *m_prev_attribute; // Pointer to previous sibling of attribute, or 0 if none; only valid if parent is non-zero Chris@16: xml_attribute *m_next_attribute; // Pointer to next sibling of attribute, or 0 if none; only valid if parent is non-zero Chris@16: Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // XML node Chris@16: Chris@16: //! Class representing a node of XML document. Chris@16: //! Each node may have associated name and value strings, which are available through name() and value() functions. Chris@16: //! Interpretation of name and value depends on type of the node. Chris@16: //! Type of node can be determined by using type() function. Chris@16: //!

Chris@16: //! Note that after parse, both name and value of node, if any, will point interior of source text used for parsing. Chris@16: //! Thus, this text must persist in the memory for the lifetime of node. Chris@16: //! \param Ch Character type to use. Chris@16: template Chris@16: class xml_node: public xml_base Chris@16: { Chris@16: Chris@16: public: Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Construction & destruction Chris@16: Chris@16: //! Constructs an empty node with the specified type. Chris@16: //! Consider using memory_pool of appropriate document to allocate nodes manually. Chris@16: //! \param t Type of node to construct. Chris@16: xml_node(node_type t) Chris@16: : m_type(t) Chris@16: , m_first_node(0) Chris@16: , m_first_attribute(0) Chris@16: { Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Node data access Chris@16: Chris@16: //! Gets type of node. Chris@16: //! \return Type of node. Chris@16: node_type type() const Chris@16: { Chris@16: return m_type; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Related nodes access Chris@16: Chris@16: //! Gets document of which node is a child. Chris@16: //! \return Pointer to document that contains this node, or 0 if there is no parent document. Chris@16: xml_document *document() const Chris@16: { Chris@16: xml_node *node = const_cast *>(this); Chris@16: while (node->parent()) Chris@16: node = node->parent(); Chris@16: return node->type() == node_document ? static_cast *>(node) : 0; Chris@16: } Chris@16: Chris@16: //! Gets first child node, optionally matching node name. Chris@16: //! \param n 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 nsize is non-zero Chris@16: //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string Chris@16: //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters Chris@16: //! \return Pointer to found child, or 0 if not found. Chris@16: xml_node *first_node(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const Chris@16: { Chris@16: if (n) Chris@16: { Chris@16: if (nsize == 0) Chris@16: nsize = internal::measure(n); Chris@16: for (xml_node *child = m_first_node; child; child = child->next_sibling()) Chris@16: if (internal::compare(child->name(), child->name_size(), n, nsize, case_sensitive)) Chris@16: return child; Chris@16: return 0; Chris@16: } Chris@16: else Chris@16: return m_first_node; Chris@16: } Chris@16: Chris@16: //! Gets last child node, optionally matching node name. Chris@16: //! Behaviour is undefined if node has no children. Chris@16: //! Use first_node() to test if node has children. Chris@16: //! \param n 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 nsize is non-zero Chris@16: //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string Chris@16: //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters Chris@16: //! \return Pointer to found child, or 0 if not found. Chris@16: xml_node *last_node(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const Chris@16: { Chris@16: BOOST_ASSERT(m_first_node); // Cannot query for last child if node has no children Chris@16: if (n) Chris@16: { Chris@16: if (nsize == 0) Chris@16: nsize = internal::measure(n); Chris@16: for (xml_node *child = m_last_node; child; child = child->previous_sibling()) Chris@16: if (internal::compare(child->name(), child->name_size(), n, nsize, case_sensitive)) Chris@16: return child; Chris@16: return 0; Chris@16: } Chris@16: else Chris@16: return m_last_node; Chris@16: } Chris@16: Chris@16: //! Gets previous sibling node, optionally matching node name. Chris@16: //! Behaviour is undefined if node has no parent. Chris@16: //! Use parent() to test if node has a parent. Chris@16: //! \param n 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 nsize is non-zero Chris@16: //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string Chris@16: //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters Chris@16: //! \return Pointer to found sibling, or 0 if not found. Chris@16: xml_node *previous_sibling(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const Chris@16: { Chris@16: BOOST_ASSERT(this->m_parent); // Cannot query for siblings if node has no parent Chris@16: if (n) Chris@16: { Chris@16: if (nsize == 0) Chris@16: nsize = internal::measure(n); Chris@16: for (xml_node *sibling = m_prev_sibling; sibling; sibling = sibling->m_prev_sibling) Chris@16: if (internal::compare(sibling->name(), sibling->name_size(), n, nsize, case_sensitive)) Chris@16: return sibling; Chris@16: return 0; Chris@16: } Chris@16: else Chris@16: return m_prev_sibling; Chris@16: } Chris@16: Chris@16: //! Gets next sibling node, optionally matching node name. Chris@16: //! Behaviour is undefined if node has no parent. Chris@16: //! Use parent() to test if node has a parent. Chris@16: //! \param n 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 nsize is non-zero Chris@16: //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string Chris@16: //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters Chris@16: //! \return Pointer to found sibling, or 0 if not found. Chris@16: xml_node *next_sibling(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const Chris@16: { Chris@16: BOOST_ASSERT(this->m_parent); // Cannot query for siblings if node has no parent Chris@16: if (n) Chris@16: { Chris@16: if (nsize == 0) Chris@16: nsize = internal::measure(n); Chris@16: for (xml_node *sibling = m_next_sibling; sibling; sibling = sibling->m_next_sibling) Chris@16: if (internal::compare(sibling->name(), sibling->name_size(), n, nsize, case_sensitive)) Chris@16: return sibling; Chris@16: return 0; Chris@16: } Chris@16: else Chris@16: return m_next_sibling; Chris@16: } Chris@16: Chris@16: //! Gets first attribute of node, optionally matching attribute name. Chris@16: //! \param n 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 nsize is non-zero Chris@16: //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string Chris@16: //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters Chris@16: //! \return Pointer to found attribute, or 0 if not found. Chris@16: xml_attribute *first_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const Chris@16: { Chris@16: if (n) Chris@16: { Chris@16: if (nsize == 0) Chris@16: nsize = internal::measure(n); Chris@16: for (xml_attribute *attribute = m_first_attribute; attribute; attribute = attribute->m_next_attribute) Chris@16: if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive)) Chris@16: return attribute; Chris@16: return 0; Chris@16: } Chris@16: else Chris@16: return m_first_attribute; Chris@16: } Chris@16: Chris@16: //! Gets last attribute of node, optionally matching attribute name. Chris@16: //! \param n 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 nsize is non-zero Chris@16: //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string Chris@16: //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters Chris@16: //! \return Pointer to found attribute, or 0 if not found. Chris@16: xml_attribute *last_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const Chris@16: { Chris@16: if (n) Chris@16: { Chris@16: if (nsize == 0) Chris@16: nsize = internal::measure(n); Chris@16: for (xml_attribute *attribute = m_last_attribute; attribute; attribute = attribute->m_prev_attribute) Chris@16: if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive)) Chris@16: return attribute; Chris@16: return 0; Chris@16: } Chris@16: else Chris@16: return m_first_attribute ? m_last_attribute : 0; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Node modification Chris@16: Chris@16: //! Sets type of node. Chris@16: //! \param t Type of node to set. Chris@16: void type(node_type t) Chris@16: { Chris@16: m_type = t; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Node manipulation Chris@16: Chris@16: //! Prepends a new child node. Chris@16: //! The prepended child becomes the first child, and all existing children are moved one position back. Chris@16: //! \param child Node to prepend. Chris@16: void prepend_node(xml_node *child) Chris@16: { Chris@16: BOOST_ASSERT(child && !child->parent() && child->type() != node_document); Chris@16: if (first_node()) Chris@16: { Chris@16: child->m_next_sibling = m_first_node; Chris@16: m_first_node->m_prev_sibling = child; Chris@16: } Chris@16: else Chris@16: { Chris@16: child->m_next_sibling = 0; Chris@16: m_last_node = child; Chris@16: } Chris@16: m_first_node = child; Chris@16: child->m_parent = this; Chris@16: child->m_prev_sibling = 0; Chris@16: } Chris@16: Chris@16: //! Appends a new child node. Chris@16: //! The appended child becomes the last child. Chris@16: //! \param child Node to append. Chris@16: void append_node(xml_node *child) Chris@16: { Chris@16: BOOST_ASSERT(child && !child->parent() && child->type() != node_document); Chris@16: if (first_node()) Chris@16: { Chris@16: child->m_prev_sibling = m_last_node; Chris@16: m_last_node->m_next_sibling = child; Chris@16: } Chris@16: else Chris@16: { Chris@16: child->m_prev_sibling = 0; Chris@16: m_first_node = child; Chris@16: } Chris@16: m_last_node = child; Chris@16: child->m_parent = this; Chris@16: child->m_next_sibling = 0; Chris@16: } Chris@16: Chris@16: //! Inserts a new child node at specified place inside the node. Chris@16: //! All children after and including the specified node are moved one position back. Chris@16: //! \param where Place where to insert the child, or 0 to insert at the back. Chris@16: //! \param child Node to insert. Chris@16: void insert_node(xml_node *where, xml_node *child) Chris@16: { Chris@16: BOOST_ASSERT(!where || where->parent() == this); Chris@16: BOOST_ASSERT(child && !child->parent() && child->type() != node_document); Chris@16: if (where == m_first_node) Chris@16: prepend_node(child); Chris@16: else if (where == 0) Chris@16: append_node(child); Chris@16: else Chris@16: { Chris@16: child->m_prev_sibling = where->m_prev_sibling; Chris@16: child->m_next_sibling = where; Chris@16: where->m_prev_sibling->m_next_sibling = child; Chris@16: where->m_prev_sibling = child; Chris@16: child->m_parent = this; Chris@16: } Chris@16: } Chris@16: Chris@16: //! Removes first child node. Chris@16: //! If node has no children, behaviour is undefined. Chris@16: //! Use first_node() to test if node has children. Chris@16: void remove_first_node() Chris@16: { Chris@16: BOOST_ASSERT(first_node()); Chris@16: xml_node *child = m_first_node; Chris@16: m_first_node = child->m_next_sibling; Chris@16: if (child->m_next_sibling) Chris@16: child->m_next_sibling->m_prev_sibling = 0; Chris@16: else Chris@16: m_last_node = 0; Chris@16: child->m_parent = 0; Chris@16: } Chris@16: Chris@16: //! Removes last child of the node. Chris@16: //! If node has no children, behaviour is undefined. Chris@16: //! Use first_node() to test if node has children. Chris@16: void remove_last_node() Chris@16: { Chris@16: BOOST_ASSERT(first_node()); Chris@16: xml_node *child = m_last_node; Chris@16: if (child->m_prev_sibling) Chris@16: { Chris@16: m_last_node = child->m_prev_sibling; Chris@16: child->m_prev_sibling->m_next_sibling = 0; Chris@16: } Chris@16: else Chris@16: m_first_node = 0; Chris@16: child->m_parent = 0; Chris@16: } Chris@16: Chris@16: //! Removes specified child from the node Chris@16: // \param where Pointer to child to be removed. Chris@16: void remove_node(xml_node *where) Chris@16: { Chris@16: BOOST_ASSERT(where && where->parent() == this); Chris@16: BOOST_ASSERT(first_node()); Chris@16: if (where == m_first_node) Chris@16: remove_first_node(); Chris@16: else if (where == m_last_node) Chris@16: remove_last_node(); Chris@16: else Chris@16: { Chris@16: where->m_prev_sibling->m_next_sibling = where->m_next_sibling; Chris@16: where->m_next_sibling->m_prev_sibling = where->m_prev_sibling; Chris@16: where->m_parent = 0; Chris@16: } Chris@16: } Chris@16: Chris@16: //! Removes all child nodes (but not attributes). Chris@16: void remove_all_nodes() Chris@16: { Chris@16: for (xml_node *node = first_node(); node; node = node->m_next_sibling) Chris@16: node->m_parent = 0; Chris@16: m_first_node = 0; Chris@16: } Chris@16: Chris@16: //! Prepends a new attribute to the node. Chris@16: //! \param attribute Attribute to prepend. Chris@16: void prepend_attribute(xml_attribute *attribute) Chris@16: { Chris@16: BOOST_ASSERT(attribute && !attribute->parent()); Chris@16: if (first_attribute()) Chris@16: { Chris@16: attribute->m_next_attribute = m_first_attribute; Chris@16: m_first_attribute->m_prev_attribute = attribute; Chris@16: } Chris@16: else Chris@16: { Chris@16: attribute->m_next_attribute = 0; Chris@16: m_last_attribute = attribute; Chris@16: } Chris@16: m_first_attribute = attribute; Chris@16: attribute->m_parent = this; Chris@16: attribute->m_prev_attribute = 0; Chris@16: } Chris@16: Chris@16: //! Appends a new attribute to the node. Chris@16: //! \param attribute Attribute to append. Chris@16: void append_attribute(xml_attribute *attribute) Chris@16: { Chris@16: BOOST_ASSERT(attribute && !attribute->parent()); Chris@16: if (first_attribute()) Chris@16: { Chris@16: attribute->m_prev_attribute = m_last_attribute; Chris@16: m_last_attribute->m_next_attribute = attribute; Chris@16: } Chris@16: else Chris@16: { Chris@16: attribute->m_prev_attribute = 0; Chris@16: m_first_attribute = attribute; Chris@16: } Chris@16: m_last_attribute = attribute; Chris@16: attribute->m_parent = this; Chris@16: attribute->m_next_attribute = 0; Chris@16: } Chris@16: Chris@16: //! Inserts a new attribute at specified place inside the node. Chris@16: //! All attributes after and including the specified attribute are moved one position back. Chris@16: //! \param where Place where to insert the attribute, or 0 to insert at the back. Chris@16: //! \param attribute Attribute to insert. Chris@16: void insert_attribute(xml_attribute *where, xml_attribute *attribute) Chris@16: { Chris@16: BOOST_ASSERT(!where || where->parent() == this); Chris@16: BOOST_ASSERT(attribute && !attribute->parent()); Chris@16: if (where == m_first_attribute) Chris@16: prepend_attribute(attribute); Chris@16: else if (where == 0) Chris@16: append_attribute(attribute); Chris@16: else Chris@16: { Chris@16: attribute->m_prev_attribute = where->m_prev_attribute; Chris@16: attribute->m_next_attribute = where; Chris@16: where->m_prev_attribute->m_next_attribute = attribute; Chris@16: where->m_prev_attribute = attribute; Chris@16: attribute->m_parent = this; Chris@16: } Chris@16: } Chris@16: Chris@16: //! Removes first attribute of the node. Chris@16: //! If node has no attributes, behaviour is undefined. Chris@16: //! Use first_attribute() to test if node has attributes. Chris@16: void remove_first_attribute() Chris@16: { Chris@16: BOOST_ASSERT(first_attribute()); Chris@16: xml_attribute *attribute = m_first_attribute; Chris@16: if (attribute->m_next_attribute) Chris@16: { Chris@16: attribute->m_next_attribute->m_prev_attribute = 0; Chris@16: } Chris@16: else Chris@16: m_last_attribute = 0; Chris@16: attribute->m_parent = 0; Chris@16: m_first_attribute = attribute->m_next_attribute; Chris@16: } Chris@16: Chris@16: //! Removes last attribute of the node. Chris@16: //! If node has no attributes, behaviour is undefined. Chris@16: //! Use first_attribute() to test if node has attributes. Chris@16: void remove_last_attribute() Chris@16: { Chris@16: BOOST_ASSERT(first_attribute()); Chris@16: xml_attribute *attribute = m_last_attribute; Chris@16: if (attribute->m_prev_attribute) Chris@16: { Chris@16: attribute->m_prev_attribute->m_next_attribute = 0; Chris@16: m_last_attribute = attribute->m_prev_attribute; Chris@16: } Chris@16: else Chris@16: m_first_attribute = 0; Chris@16: attribute->m_parent = 0; Chris@16: } Chris@16: Chris@16: //! Removes specified attribute from node. Chris@16: //! \param where Pointer to attribute to be removed. Chris@16: void remove_attribute(xml_attribute *where) Chris@16: { Chris@16: BOOST_ASSERT(first_attribute() && where->parent() == this); Chris@16: if (where == m_first_attribute) Chris@16: remove_first_attribute(); Chris@16: else if (where == m_last_attribute) Chris@16: remove_last_attribute(); Chris@16: else Chris@16: { Chris@16: where->m_prev_attribute->m_next_attribute = where->m_next_attribute; Chris@16: where->m_next_attribute->m_prev_attribute = where->m_prev_attribute; Chris@16: where->m_parent = 0; Chris@16: } Chris@16: } Chris@16: Chris@16: //! Removes all attributes of node. Chris@16: void remove_all_attributes() Chris@16: { Chris@16: for (xml_attribute *attribute = first_attribute(); attribute; attribute = attribute->m_next_attribute) Chris@16: attribute->m_parent = 0; Chris@16: m_first_attribute = 0; Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Restrictions Chris@16: Chris@16: // No copying Chris@16: xml_node(const xml_node &); Chris@16: void operator =(const xml_node &); Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Data members Chris@16: Chris@16: // Note that some of the pointers below have UNDEFINED values if certain other pointers are 0. Chris@16: // This is required for maximum performance, as it allows the parser to omit initialization of Chris@16: // unneded/redundant values. Chris@16: // Chris@16: // The rules are as follows: Chris@16: // 1. first_node and first_attribute contain valid pointers, or 0 if node has no children/attributes respectively Chris@16: // 2. last_node and last_attribute are valid only if node has at least one child/attribute respectively, otherwise they contain garbage Chris@16: // 3. prev_sibling and next_sibling are valid only if node has a parent, otherwise they contain garbage Chris@16: Chris@16: node_type m_type; // Type of node; always valid Chris@16: xml_node *m_first_node; // Pointer to first child node, or 0 if none; always valid Chris@16: xml_node *m_last_node; // Pointer to last child node, or 0 if none; this value is only valid if m_first_node is non-zero Chris@16: xml_attribute *m_first_attribute; // Pointer to first attribute of node, or 0 if none; always valid Chris@16: xml_attribute *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 Chris@16: xml_node *m_prev_sibling; // Pointer to previous sibling of node, or 0 if none; this value is only valid if m_parent is non-zero Chris@16: xml_node *m_next_sibling; // Pointer to next sibling of node, or 0 if none; this value is only valid if m_parent is non-zero Chris@16: Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // XML document Chris@16: Chris@16: //! This class represents root of the DOM hierarchy. Chris@16: //! It is also an xml_node and a memory_pool through public inheritance. Chris@16: //! Use parse() function to build a DOM tree from a zero-terminated XML text string. Chris@16: //! parse() function allocates memory for nodes and attributes by using functions of xml_document, Chris@16: //! which are inherited from memory_pool. Chris@16: //! To access root node of the document, use the document itself, as if it was an xml_node. Chris@16: //! \param Ch Character type to use. Chris@16: template Chris@16: class xml_document: public xml_node, public memory_pool Chris@16: { Chris@16: Chris@16: public: Chris@16: Chris@16: //! Constructs empty XML document Chris@16: xml_document() Chris@16: : xml_node(node_document) Chris@16: { Chris@16: } Chris@16: Chris@16: //! Parses zero-terminated XML string according to given flags. Chris@16: //! Passed string will be modified by the parser, unless rapidxml::parse_non_destructive flag is used. Chris@16: //! The string must persist for the lifetime of the document. Chris@16: //! In case of error, rapidxml::parse_error exception will be thrown. Chris@16: //!

Chris@16: //! If you want to parse contents of a file, you must first load the file into the memory, and pass pointer to its beginning. Chris@16: //! Make sure that data is zero-terminated. Chris@16: //!

Chris@16: //! Document can be parsed into multiple times. Chris@16: //! Each new call to parse removes previous nodes and attributes (if any), but does not clear memory pool. Chris@16: //! \param text XML data to parse; pointer is non-const to denote fact that this data may be modified by the parser. Chris@16: template Chris@16: void parse(Ch *text) Chris@16: { Chris@16: BOOST_ASSERT(text); Chris@16: Chris@16: // Remove current contents Chris@16: this->remove_all_nodes(); Chris@16: this->remove_all_attributes(); Chris@16: Chris@16: // Parse BOM, if any Chris@16: parse_bom(text); Chris@16: Chris@16: // Parse children Chris@16: while (1) Chris@16: { Chris@16: // Skip whitespace before node Chris@16: skip(text); Chris@16: if (*text == 0) Chris@16: break; Chris@16: Chris@16: // Parse and append new child Chris@16: if (*text == Ch('<')) Chris@16: { Chris@16: ++text; // Skip '<' Chris@16: if (xml_node *node = parse_node(text)) Chris@16: this->append_node(node); Chris@16: } Chris@16: else Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected <", text); Chris@16: } Chris@16: Chris@16: } Chris@16: Chris@16: //! Clears the document by deleting all nodes and clearing the memory pool. Chris@16: //! All nodes owned by document pool are destroyed. Chris@16: void clear() Chris@16: { Chris@16: this->remove_all_nodes(); Chris@16: this->remove_all_attributes(); Chris@16: memory_pool::clear(); Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // Internal character utility functions Chris@16: Chris@16: // Detect whitespace character Chris@16: struct whitespace_pred Chris@16: { Chris@16: static unsigned char test(Ch ch) Chris@16: { Chris@16: return internal::lookup_tables<0>::lookup_whitespace[internal::get_index(ch)]; Chris@16: } Chris@16: }; Chris@16: Chris@16: // Detect node name character Chris@16: struct node_name_pred Chris@16: { Chris@16: static unsigned char test(Ch ch) Chris@16: { Chris@16: return internal::lookup_tables<0>::lookup_node_name[internal::get_index(ch)]; Chris@16: } Chris@16: }; Chris@16: Chris@16: // Detect attribute name character Chris@16: struct attribute_name_pred Chris@16: { Chris@16: static unsigned char test(Ch ch) Chris@16: { Chris@16: return internal::lookup_tables<0>::lookup_attribute_name[internal::get_index(ch)]; Chris@16: } Chris@16: }; Chris@16: Chris@16: // Detect text character (PCDATA) Chris@16: struct text_pred Chris@16: { Chris@16: static unsigned char test(Ch ch) Chris@16: { Chris@16: return internal::lookup_tables<0>::lookup_text[internal::get_index(ch)]; Chris@16: } Chris@16: }; Chris@16: Chris@16: // Detect text character (PCDATA) that does not require processing Chris@16: struct text_pure_no_ws_pred Chris@16: { Chris@16: static unsigned char test(Ch ch) Chris@16: { Chris@16: return internal::lookup_tables<0>::lookup_text_pure_no_ws[internal::get_index(ch)]; Chris@16: } Chris@16: }; Chris@16: Chris@16: // Detect text character (PCDATA) that does not require processing Chris@16: struct text_pure_with_ws_pred Chris@16: { Chris@16: static unsigned char test(Ch ch) Chris@16: { Chris@16: return internal::lookup_tables<0>::lookup_text_pure_with_ws[internal::get_index(ch)]; Chris@16: } Chris@16: }; Chris@16: Chris@16: // Detect attribute value character Chris@16: template Chris@16: struct attribute_value_pred Chris@16: { Chris@16: static unsigned char test(Ch ch) Chris@16: { Chris@16: if (Quote == Ch('\'')) Chris@16: return internal::lookup_tables<0>::lookup_attribute_data_1[internal::get_index(ch)]; Chris@16: if (Quote == Ch('\"')) Chris@16: return internal::lookup_tables<0>::lookup_attribute_data_2[internal::get_index(ch)]; Chris@16: return 0; // Should never be executed, to avoid warnings on Comeau Chris@16: } Chris@16: }; Chris@16: Chris@16: // Detect attribute value character Chris@16: template Chris@16: struct attribute_value_pure_pred Chris@16: { Chris@16: static unsigned char test(Ch ch) Chris@16: { Chris@16: if (Quote == Ch('\'')) Chris@16: return internal::lookup_tables<0>::lookup_attribute_data_1_pure[internal::get_index(ch)]; Chris@16: if (Quote == Ch('\"')) Chris@16: return internal::lookup_tables<0>::lookup_attribute_data_2_pure[internal::get_index(ch)]; Chris@16: return 0; // Should never be executed, to avoid warnings on Comeau Chris@16: } Chris@16: }; Chris@16: Chris@16: // Insert coded character, using UTF8 or 8-bit ASCII Chris@16: template Chris@16: static void insert_coded_character(Ch *&text, unsigned long code) Chris@16: { Chris@16: if (Flags & parse_no_utf8) Chris@16: { Chris@16: // Insert 8-bit ASCII character Chris@16: // Todo: possibly verify that code is less than 256 and use replacement char otherwise? Chris@16: text[0] = static_cast(code); Chris@16: text += 1; Chris@16: } Chris@16: else Chris@16: { Chris@16: // Insert UTF8 sequence Chris@16: if (code < 0x80) // 1 byte sequence Chris@16: { Chris@16: text[0] = static_cast(code); Chris@16: text += 1; Chris@16: } Chris@16: else if (code < 0x800) // 2 byte sequence Chris@16: { Chris@16: text[1] = static_cast((code | 0x80) & 0xBF); code >>= 6; Chris@16: text[0] = static_cast(code | 0xC0); Chris@16: text += 2; Chris@16: } Chris@16: else if (code < 0x10000) // 3 byte sequence Chris@16: { Chris@16: text[2] = static_cast((code | 0x80) & 0xBF); code >>= 6; Chris@16: text[1] = static_cast((code | 0x80) & 0xBF); code >>= 6; Chris@16: text[0] = static_cast(code | 0xE0); Chris@16: text += 3; Chris@16: } Chris@16: else if (code < 0x110000) // 4 byte sequence Chris@16: { Chris@16: text[3] = static_cast((code | 0x80) & 0xBF); code >>= 6; Chris@16: text[2] = static_cast((code | 0x80) & 0xBF); code >>= 6; Chris@16: text[1] = static_cast((code | 0x80) & 0xBF); code >>= 6; Chris@16: text[0] = static_cast(code | 0xF0); Chris@16: text += 4; Chris@16: } Chris@16: else // Invalid, only codes up to 0x10FFFF are allowed in Unicode Chris@16: { Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid numeric character entity", text); Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: // Skip characters until predicate evaluates to true Chris@16: template Chris@16: static void skip(Ch *&text) Chris@16: { Chris@16: Ch *tmp = text; Chris@16: while (StopPred::test(*tmp)) Chris@16: ++tmp; Chris@16: text = tmp; Chris@16: } Chris@16: Chris@16: // Skip characters until predicate evaluates to true while doing the following: Chris@16: // - replacing XML character entity references with proper characters (' & " < > &#...;) Chris@16: // - condensing whitespace sequences to single space character Chris@16: template Chris@16: static Ch *skip_and_expand_character_refs(Ch *&text) Chris@16: { Chris@16: // If entity translation, whitespace condense and whitespace trimming is disabled, use plain skip Chris@16: if (Flags & parse_no_entity_translation && Chris@16: !(Flags & parse_normalize_whitespace) && Chris@16: !(Flags & parse_trim_whitespace)) Chris@16: { Chris@16: skip(text); Chris@16: return text; Chris@16: } Chris@16: Chris@16: // Use simple skip until first modification is detected Chris@16: skip(text); Chris@16: Chris@16: // Use translation skip Chris@16: Ch *src = text; Chris@16: Ch *dest = src; Chris@16: while (StopPred::test(*src)) Chris@16: { Chris@16: // If entity translation is enabled Chris@16: if (!(Flags & parse_no_entity_translation)) Chris@16: { Chris@16: // Test if replacement is needed Chris@16: if (src[0] == Ch('&')) Chris@16: { Chris@16: switch (src[1]) Chris@16: { Chris@16: Chris@16: // & ' Chris@16: case Ch('a'): Chris@16: if (src[2] == Ch('m') && src[3] == Ch('p') && src[4] == Ch(';')) Chris@16: { Chris@16: *dest = Ch('&'); Chris@16: ++dest; Chris@16: src += 5; Chris@16: continue; Chris@16: } Chris@16: if (src[2] == Ch('p') && src[3] == Ch('o') && src[4] == Ch('s') && src[5] == Ch(';')) Chris@16: { Chris@16: *dest = Ch('\''); Chris@16: ++dest; Chris@16: src += 6; Chris@16: continue; Chris@16: } Chris@16: break; Chris@16: Chris@16: // " Chris@16: case Ch('q'): Chris@16: if (src[2] == Ch('u') && src[3] == Ch('o') && src[4] == Ch('t') && src[5] == Ch(';')) Chris@16: { Chris@16: *dest = Ch('"'); Chris@16: ++dest; Chris@16: src += 6; Chris@16: continue; Chris@16: } Chris@16: break; Chris@16: Chris@16: // > Chris@16: case Ch('g'): Chris@16: if (src[2] == Ch('t') && src[3] == Ch(';')) Chris@16: { Chris@16: *dest = Ch('>'); Chris@16: ++dest; Chris@16: src += 4; Chris@16: continue; Chris@16: } Chris@16: break; Chris@16: Chris@16: // < Chris@16: case Ch('l'): Chris@16: if (src[2] == Ch('t') && src[3] == Ch(';')) Chris@16: { Chris@16: *dest = Ch('<'); Chris@16: ++dest; Chris@16: src += 4; Chris@16: continue; Chris@16: } Chris@16: break; Chris@16: Chris@16: // &#...; - assumes ASCII Chris@16: case Ch('#'): Chris@16: if (src[2] == Ch('x')) Chris@16: { Chris@16: unsigned long code = 0; Chris@16: src += 3; // Skip &#x Chris@16: while (1) Chris@16: { Chris@16: unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast(*src)]; Chris@16: if (digit == 0xFF) Chris@16: break; Chris@16: code = code * 16 + digit; Chris@16: ++src; Chris@16: } Chris@16: insert_coded_character(dest, code); // Put character in output Chris@16: } Chris@16: else Chris@16: { Chris@16: unsigned long code = 0; Chris@16: src += 2; // Skip &# Chris@16: while (1) Chris@16: { Chris@16: unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast(*src)]; Chris@16: if (digit == 0xFF) Chris@16: break; Chris@16: code = code * 10 + digit; Chris@16: ++src; Chris@16: } Chris@16: insert_coded_character(dest, code); // Put character in output Chris@16: } Chris@16: if (*src == Ch(';')) Chris@16: ++src; Chris@16: else Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ;", src); Chris@16: continue; Chris@16: Chris@16: // Something else Chris@16: default: Chris@16: // Ignore, just copy '&' verbatim Chris@16: break; Chris@16: Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: // If whitespace condensing is enabled Chris@16: if (Flags & parse_normalize_whitespace) Chris@16: { Chris@16: // Test if condensing is needed Chris@16: if (whitespace_pred::test(*src)) Chris@16: { Chris@16: *dest = Ch(' '); ++dest; // Put single space in dest Chris@16: ++src; // Skip first whitespace char Chris@16: // Skip remaining whitespace chars Chris@16: while (whitespace_pred::test(*src)) Chris@16: ++src; Chris@16: continue; Chris@16: } Chris@16: } Chris@16: Chris@16: // No replacement, only copy character Chris@16: *dest++ = *src++; Chris@16: Chris@16: } Chris@16: Chris@16: // Return new end Chris@16: text = src; Chris@16: return dest; Chris@16: Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // Internal parsing functions Chris@16: Chris@16: // Parse UTF-8 BOM, if any Chris@16: template Chris@16: void parse_bom(char *&text) Chris@16: { Chris@16: if (static_cast(text[0]) == 0xEF && Chris@16: static_cast(text[1]) == 0xBB && Chris@16: static_cast(text[2]) == 0xBF) Chris@16: { Chris@16: text += 3; Chris@16: } Chris@16: } Chris@16: Chris@16: // Parse UTF-16/32 BOM, if any Chris@16: template Chris@16: void parse_bom(wchar_t *&text) Chris@16: { Chris@16: const wchar_t bom = 0xFEFF; Chris@16: if (text[0] == bom) Chris@16: { Chris@16: ++text; Chris@16: } Chris@16: } Chris@16: Chris@16: // Parse XML declaration ( Chris@16: xml_node *parse_xml_declaration(Ch *&text) Chris@16: { Chris@16: // If parsing of declaration is disabled Chris@16: if (!(Flags & parse_declaration_node)) Chris@16: { Chris@16: // Skip until end of declaration Chris@16: while (text[0] != Ch('?') || text[1] != Ch('>')) Chris@16: { Chris@16: if (!text[0]) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: ++text; Chris@16: } Chris@16: text += 2; // Skip '?>' Chris@16: return 0; Chris@16: } Chris@16: Chris@16: // Create declaration Chris@16: xml_node *declaration = this->allocate_node(node_declaration); Chris@16: Chris@16: // Skip whitespace before attributes or ?> Chris@16: skip(text); Chris@16: Chris@16: // Parse declaration attributes Chris@16: parse_node_attributes(text, declaration); Chris@16: Chris@16: // Skip ?> Chris@16: if (text[0] != Ch('?') || text[1] != Ch('>')) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ?>", text); Chris@16: text += 2; Chris@16: Chris@16: return declaration; Chris@16: } Chris@16: Chris@16: // Parse XML comment (' Chris@16: return 0; // Do not produce comment node Chris@16: } Chris@16: Chris@16: // Remember value start Chris@16: Ch *val = text; Chris@16: Chris@16: // Skip until end of comment Chris@16: while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>')) Chris@16: { Chris@16: if (!text[0]) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: ++text; Chris@16: } Chris@16: Chris@16: // Create comment node Chris@16: xml_node *comment = this->allocate_node(node_comment); Chris@16: comment->value(val, text - val); Chris@16: Chris@16: // Place zero terminator after comment value Chris@16: if (!(Flags & parse_no_string_terminators)) Chris@16: *text = Ch('\0'); Chris@16: Chris@16: text += 3; // Skip '-->' Chris@16: return comment; Chris@16: } Chris@16: Chris@16: // Parse DOCTYPE Chris@16: template Chris@16: xml_node *parse_doctype(Ch *&text) Chris@16: { Chris@16: // Remember value start Chris@16: Ch *val = text; Chris@16: Chris@16: // Skip to > Chris@16: while (*text != Ch('>')) Chris@16: { Chris@16: // Determine character type Chris@16: switch (*text) Chris@16: { Chris@16: Chris@16: // If '[' encountered, scan for matching ending ']' using naive algorithm with depth Chris@16: // This works for all W3C test files except for 2 most wicked Chris@16: case Ch('['): Chris@16: { Chris@16: ++text; // Skip '[' Chris@16: int depth = 1; Chris@16: while (depth > 0) Chris@16: { Chris@16: switch (*text) Chris@16: { Chris@16: case Ch('['): ++depth; break; Chris@16: case Ch(']'): --depth; break; Chris@16: case 0: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: default: break; Chris@16: } Chris@16: ++text; Chris@16: } Chris@16: break; Chris@16: } Chris@16: Chris@16: // Error on end of text Chris@16: case Ch('\0'): Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: Chris@16: // Other character, skip it Chris@16: default: Chris@16: ++text; Chris@16: Chris@16: } Chris@16: } Chris@16: Chris@16: // If DOCTYPE nodes enabled Chris@16: if (Flags & parse_doctype_node) Chris@16: { Chris@16: // Create a new doctype node Chris@16: xml_node *doctype = this->allocate_node(node_doctype); Chris@16: doctype->value(val, text - val); Chris@16: Chris@16: // Place zero terminator after value Chris@16: if (!(Flags & parse_no_string_terminators)) Chris@16: *text = Ch('\0'); Chris@16: Chris@16: text += 1; // skip '>' Chris@16: return doctype; Chris@16: } Chris@16: else Chris@16: { Chris@16: text += 1; // skip '>' Chris@16: return 0; Chris@16: } Chris@16: Chris@16: } Chris@16: Chris@16: // Parse PI Chris@16: template Chris@16: xml_node *parse_pi(Ch *&text) Chris@16: { Chris@16: // If creation of PI nodes is enabled Chris@16: if (Flags & parse_pi_nodes) Chris@16: { Chris@16: // Create pi node Chris@16: xml_node *pi = this->allocate_node(node_pi); Chris@16: Chris@16: // Extract PI target name Chris@16: Ch *n = text; Chris@16: skip(text); Chris@16: if (text == n) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected PI target", text); Chris@16: pi->name(n, text - n); Chris@16: Chris@16: // Skip whitespace between pi target and pi Chris@16: skip(text); Chris@16: Chris@16: // Remember start of pi Chris@16: Ch *val = text; Chris@16: Chris@16: // Skip to '?>' Chris@16: while (text[0] != Ch('?') || text[1] != Ch('>')) Chris@16: { Chris@16: if (*text == Ch('\0')) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: ++text; Chris@16: } Chris@16: Chris@16: // Set pi value (verbatim, no entity expansion or whitespace normalization) Chris@16: pi->value(val, text - val); Chris@16: Chris@16: // Place zero terminator after name and value Chris@16: if (!(Flags & parse_no_string_terminators)) Chris@16: { Chris@16: pi->name()[pi->name_size()] = Ch('\0'); Chris@16: pi->value()[pi->value_size()] = Ch('\0'); Chris@16: } Chris@16: Chris@16: text += 2; // Skip '?>' Chris@16: return pi; Chris@16: } Chris@16: else Chris@16: { Chris@16: // Skip to '?>' Chris@16: while (text[0] != Ch('?') || text[1] != Ch('>')) Chris@16: { Chris@16: if (*text == Ch('\0')) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: ++text; Chris@16: } Chris@16: text += 2; // Skip '?>' Chris@16: return 0; Chris@16: } Chris@16: } Chris@16: Chris@16: // Parse and append data Chris@16: // Return character that ends data. Chris@16: // This is necessary because this character might have been overwritten by a terminating 0 Chris@16: template Chris@16: Ch parse_and_append_data(xml_node *node, Ch *&text, Ch *contents_start) Chris@16: { Chris@16: // Backup to contents start if whitespace trimming is disabled Chris@16: if (!(Flags & parse_trim_whitespace)) Chris@16: text = contents_start; Chris@16: Chris@16: // Skip until end of data Chris@16: Ch *val = text, *end; Chris@16: if (Flags & parse_normalize_whitespace) Chris@16: end = skip_and_expand_character_refs(text); Chris@16: else Chris@16: end = skip_and_expand_character_refs(text); Chris@16: Chris@16: // Trim trailing whitespace if flag is set; leading was already trimmed by whitespace skip after > Chris@16: if (Flags & parse_trim_whitespace) Chris@16: { Chris@16: if (Flags & parse_normalize_whitespace) Chris@16: { Chris@16: // Whitespace is already condensed to single space characters by skipping function, so just trim 1 char off the end Chris@16: if (*(end - 1) == Ch(' ')) Chris@16: --end; Chris@16: } Chris@16: else Chris@16: { Chris@16: // Backup until non-whitespace character is found Chris@16: while (whitespace_pred::test(*(end - 1))) Chris@16: --end; Chris@16: } Chris@16: } Chris@16: Chris@16: // If characters are still left between end and value (this test is only necessary if normalization is enabled) Chris@16: // Create new data node Chris@16: if (!(Flags & parse_no_data_nodes)) Chris@16: { Chris@16: xml_node *data = this->allocate_node(node_data); Chris@16: data->value(val, end - val); Chris@16: node->append_node(data); Chris@16: } Chris@16: Chris@16: // Add data to parent node if no data exists yet Chris@16: if (!(Flags & parse_no_element_values)) Chris@16: if (*node->value() == Ch('\0')) Chris@16: node->value(val, end - val); Chris@16: Chris@16: // Place zero terminator after value Chris@16: if (!(Flags & parse_no_string_terminators)) Chris@16: { Chris@16: Ch ch = *text; Chris@16: *end = Ch('\0'); Chris@16: return ch; // Return character that ends data; this is required because zero terminator overwritten it Chris@16: } Chris@16: Chris@16: // Return character that ends data Chris@16: return *text; Chris@16: } Chris@16: Chris@16: // Parse CDATA Chris@16: template Chris@16: xml_node *parse_cdata(Ch *&text) Chris@16: { Chris@16: // If CDATA is disabled Chris@16: if (Flags & parse_no_data_nodes) Chris@16: { Chris@16: // Skip until end of cdata Chris@16: while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) Chris@16: { Chris@16: if (!text[0]) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: ++text; Chris@16: } Chris@16: text += 3; // Skip ]]> Chris@16: return 0; // Do not produce CDATA node Chris@16: } Chris@16: Chris@16: // Skip until end of cdata Chris@16: Ch *val = text; Chris@16: while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) Chris@16: { Chris@16: if (!text[0]) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: ++text; Chris@16: } Chris@16: Chris@16: // Create new cdata node Chris@16: xml_node *cdata = this->allocate_node(node_cdata); Chris@16: cdata->value(val, text - val); Chris@16: Chris@16: // Place zero terminator after value Chris@16: if (!(Flags & parse_no_string_terminators)) Chris@16: *text = Ch('\0'); Chris@16: Chris@16: text += 3; // Skip ]]> Chris@16: return cdata; Chris@16: } Chris@16: Chris@16: // Parse element node Chris@16: template Chris@16: xml_node *parse_element(Ch *&text) Chris@16: { Chris@16: // Create element node Chris@16: xml_node *element = this->allocate_node(node_element); Chris@16: Chris@16: // Extract element name Chris@16: Ch *n = text; Chris@16: skip(text); Chris@16: if (text == n) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected element name", text); Chris@16: element->name(n, text - n); Chris@16: Chris@16: // Skip whitespace between element name and attributes or > Chris@16: skip(text); Chris@16: Chris@16: // Parse attributes, if any Chris@16: parse_node_attributes(text, element); Chris@16: Chris@16: // Determine ending type Chris@16: if (*text == Ch('>')) Chris@16: { Chris@16: ++text; Chris@16: parse_node_contents(text, element); Chris@16: } Chris@16: else if (*text == Ch('/')) Chris@16: { Chris@16: ++text; Chris@16: if (*text != Ch('>')) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text); Chris@16: ++text; Chris@16: } Chris@16: else Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text); Chris@16: Chris@16: // Place zero terminator after name Chris@16: if (!(Flags & parse_no_string_terminators)) Chris@16: element->name()[element->name_size()] = Ch('\0'); Chris@16: Chris@16: // Return parsed element Chris@16: return element; Chris@16: } Chris@16: Chris@16: // Determine node type, and parse it Chris@16: template Chris@16: xml_node *parse_node(Ch *&text) Chris@16: { Chris@16: // Parse proper node type Chris@16: switch (text[0]) Chris@16: { Chris@16: Chris@16: // <... Chris@16: default: Chris@16: // Parse and append element node Chris@16: return parse_element(text); Chris@16: Chris@16: // (text); Chris@16: } Chris@16: else Chris@16: { Chris@16: // Parse PI Chris@16: return parse_pi(text); Chris@16: } Chris@16: Chris@16: // (text); Chris@16: } Chris@16: break; Chris@16: Chris@16: // (text); Chris@16: } Chris@16: break; Chris@16: Chris@16: // (text); Chris@16: } Chris@16: break; Chris@16: Chris@16: default: break; Chris@16: Chris@16: } // switch Chris@16: Chris@16: // Attempt to skip other, unrecognized node types starting with ')) Chris@16: { Chris@16: if (*text == 0) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: ++text; Chris@16: } Chris@16: ++text; // Skip '>' Chris@16: return 0; // No node recognized Chris@16: Chris@16: } Chris@16: } Chris@16: Chris@16: // Parse contents of the node - children, data etc. Chris@16: template Chris@16: void parse_node_contents(Ch *&text, xml_node *node) Chris@16: { Chris@16: // For all children and text Chris@16: while (1) Chris@16: { Chris@16: // Skip whitespace between > and node contents Chris@16: Ch *contents_start = text; // Store start of node contents before whitespace is skipped Chris@16: if (Flags & parse_trim_whitespace) Chris@16: skip(text); Chris@16: Ch next_char = *text; Chris@16: Chris@16: // After data nodes, instead of continuing the loop, control jumps here. Chris@16: // This is because zero termination inside parse_and_append_data() function Chris@16: // would wreak havoc with the above code. Chris@16: // Also, skipping whitespace after data nodes is unnecessary. Chris@16: after_data_node: Chris@16: Chris@16: // Determine what comes next: node closing, child node, data node, or 0? Chris@16: switch (next_char) Chris@16: { Chris@16: Chris@16: // Node closing or child node Chris@16: case Ch('<'): Chris@16: if (text[1] == Ch('/')) Chris@16: { Chris@16: // Node closing Chris@16: text += 2; // Skip '(text); Chris@16: if (!internal::compare(node->name(), node->name_size(), closing_name, text - closing_name, true)) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid closing tag name", text); Chris@16: } Chris@16: else Chris@16: { Chris@16: // No validation, just skip name Chris@16: skip(text); Chris@16: } Chris@16: // Skip remaining whitespace after node name Chris@16: skip(text); Chris@16: if (*text != Ch('>')) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text); Chris@16: ++text; // Skip '>' Chris@16: return; // Node closed, finished parsing contents Chris@16: } Chris@16: else Chris@16: { Chris@16: // Child node Chris@16: ++text; // Skip '<' Chris@16: if (xml_node *child = parse_node(text)) Chris@16: node->append_node(child); Chris@16: } Chris@16: break; Chris@16: Chris@16: // End of data - error Chris@16: case Ch('\0'): Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text); Chris@16: Chris@16: // Data node Chris@16: default: Chris@16: next_char = parse_and_append_data(node, text, contents_start); Chris@16: goto after_data_node; // Bypass regular processing after data nodes Chris@16: Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: // Parse XML attributes of the node Chris@16: template Chris@16: void parse_node_attributes(Ch *&text, xml_node *node) Chris@16: { Chris@16: // For all attributes Chris@16: while (attribute_name_pred::test(*text)) Chris@16: { Chris@16: // Extract attribute name Chris@16: Ch *n = text; Chris@16: ++text; // Skip first character of attribute name Chris@16: skip(text); Chris@16: if (text == n) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected attribute name", n); Chris@16: Chris@16: // Create new attribute Chris@16: xml_attribute *attribute = this->allocate_attribute(); Chris@16: attribute->name(n, text - n); Chris@16: node->append_attribute(attribute); Chris@16: Chris@16: // Skip whitespace after attribute name Chris@16: skip(text); Chris@16: Chris@16: // Skip = Chris@16: if (*text != Ch('=')) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected =", text); Chris@16: ++text; Chris@16: Chris@16: // Add terminating zero after name Chris@16: if (!(Flags & parse_no_string_terminators)) Chris@16: attribute->name()[attribute->name_size()] = 0; Chris@16: Chris@16: // Skip whitespace after = Chris@16: skip(text); Chris@16: Chris@16: // Skip quote and remember if it was ' or " Chris@16: Ch quote = *text; Chris@16: if (quote != Ch('\'') && quote != Ch('"')) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text); Chris@16: ++text; Chris@16: Chris@16: // Extract attribute value and expand char refs in it Chris@16: Ch *val = text, *end; Chris@16: const int AttFlags = Flags & ~parse_normalize_whitespace; // No whitespace normalization in attributes Chris@16: if (quote == Ch('\'')) Chris@16: end = skip_and_expand_character_refs, attribute_value_pure_pred, AttFlags>(text); Chris@16: else Chris@16: end = skip_and_expand_character_refs, attribute_value_pure_pred, AttFlags>(text); Chris@16: Chris@16: // Set attribute value Chris@16: attribute->value(val, end - val); Chris@16: Chris@16: // Make sure that end quote is present Chris@16: if (*text != quote) Chris@16: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text); Chris@16: ++text; // Skip quote Chris@16: Chris@16: // Add terminating zero after value Chris@16: if (!(Flags & parse_no_string_terminators)) Chris@16: attribute->value()[attribute->value_size()] = 0; Chris@16: Chris@16: // Skip whitespace after attribute value Chris@16: skip(text); Chris@16: } Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: //! \cond internal Chris@16: namespace internal Chris@16: { Chris@16: Chris@16: // Whitespace (space \n \r \t) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_whitespace[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, // 0 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1 Chris@16: 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 7 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9 Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // C Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // D Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // E Chris@16: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // F Chris@16: }; Chris@16: Chris@16: // Node name (anything but space \n \r \t / > ? \0) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_node_name[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Text (i.e. PCDATA) (anything but < \0) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_text[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Text (i.e. PCDATA) that does not require processing when ws normalization is disabled Chris@16: // (anything but < \0 &) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_text_pure_no_ws[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Text (i.e. PCDATA) that does not require processing when ws normalizationis is enabled Chris@16: // (anything but < \0 & space \n \r \t) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_text_pure_with_ws[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Attribute name (anything but space \n \r \t / < > = ? ! \0) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_attribute_name[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Attribute data with single quote (anything but ' \0) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_attribute_data_1[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Attribute data with single quote that does not require processing (anything but ' \0 &) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_attribute_data_1_pure[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Attribute data with double quote (anything but " \0) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_attribute_data_2[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Attribute data with double quote that does not require processing (anything but " \0 &) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_attribute_data_2_pure[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 Chris@16: 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9 Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E Chris@16: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F Chris@16: }; Chris@16: Chris@16: // Digits (dec and hex, 255 denotes end of numeric character reference) Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_digits[256] = Chris@16: { Chris@16: // 0 1 2 3 4 5 6 7 8 9 A B C D E F Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 0 Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 1 Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 2 Chris@16: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,255,255,255,255,255,255, // 3 Chris@16: 255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255, // 4 Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 5 Chris@16: 255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255, // 6 Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 7 Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 8 Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 9 Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // A Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // B Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // C Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // D Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // E Chris@16: 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 // F Chris@16: }; Chris@16: Chris@16: // Upper case conversion Chris@16: template Chris@16: const unsigned char lookup_tables::lookup_upcase[256] = Chris@16: { Chris@16: // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A B C D E F Chris@16: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 0 Chris@16: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, // 1 Chris@16: 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, // 2 Chris@16: 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, // 3 Chris@16: 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, // 4 Chris@16: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, // 5 Chris@16: 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, // 6 Chris@16: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123,124,125,126,127, // 7 Chris@16: 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, // 8 Chris@16: 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, // 9 Chris@16: 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, // A Chris@16: 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, // B Chris@16: 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, // C Chris@16: 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, // D Chris@16: 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, // E Chris@16: 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 // F Chris@16: }; Chris@16: } Chris@16: //! \endcond Chris@16: Chris@16: }}}} Chris@16: Chris@16: // Undefine internal macros Chris@16: #undef BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR Chris@16: Chris@16: // On MSVC, restore warnings state Chris@16: #ifdef _MSC_VER Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #endif