rapidxml.hpp 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595
  1. // ----------------------------------------------------------------------------
  2. // Copyright (C) 2006, 2009 Marcin Kalicinski
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see www.boost.org
  9. // ----------------------------------------------------------------------------
  10. #ifndef BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED
  11. #define BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED
  12. //! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation
  13. #include <boost/assert.hpp>
  14. #include <cstdlib> // For std::size_t
  15. #include <new> // For placement new
  16. // On MSVC, disable "conditional expression is constant" warning (level 4).
  17. // This warning is almost impossible to avoid with certain types of templated code
  18. #ifdef _MSC_VER
  19. #pragma warning(push)
  20. #pragma warning(disable:4127) // Conditional expression is constant
  21. #endif
  22. ///////////////////////////////////////////////////////////////////////////
  23. // BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR
  24. #include <exception> // For std::exception
  25. #define BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where)
  26. namespace boost { namespace property_tree { namespace detail {namespace rapidxml
  27. {
  28. //! Parse error exception.
  29. //! This exception is thrown by the parser when an error occurs.
  30. //! Use what() function to get human-readable error message.
  31. //! Use where() function to get a pointer to position within source text where error was detected.
  32. //! <br><br>
  33. //! If throwing exceptions by the parser is undesirable,
  34. //! it can be disabled by defining RAPIDXML_NO_EXCEPTIONS macro before rapidxml.hpp is included.
  35. //! This will cause the parser to call rapidxml::parse_error_handler() function instead of throwing an exception.
  36. //! This function must be defined by the user.
  37. //! <br><br>
  38. //! This class derives from <code>std::exception</code> class.
  39. class parse_error: public std::exception
  40. {
  41. public:
  42. //! Constructs parse error
  43. parse_error(const char *wa, void *we)
  44. : m_what(wa)
  45. , m_where(we)
  46. {
  47. }
  48. //! Gets human readable description of error.
  49. //! \return Pointer to null terminated description of the error.
  50. virtual const char *what() const throw()
  51. {
  52. return m_what;
  53. }
  54. //! Gets pointer to character data where error happened.
  55. //! Ch should be the same as char type of xml_document that produced the error.
  56. //! \return Pointer to location within the parsed string where error occurred.
  57. template<class Ch>
  58. Ch *where() const
  59. {
  60. return reinterpret_cast<Ch *>(m_where);
  61. }
  62. private:
  63. const char *m_what;
  64. void *m_where;
  65. };
  66. }}}}
  67. ///////////////////////////////////////////////////////////////////////////
  68. // Pool sizes
  69. #ifndef BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE
  70. // Size of static memory block of memory_pool.
  71. // Define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
  72. // No dynamic memory allocations are performed by memory_pool until static memory is exhausted.
  73. #define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE (64 * 1024)
  74. #endif
  75. #ifndef BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE
  76. // Size of dynamic memory block of memory_pool.
  77. // Define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
  78. // After the static block is exhausted, dynamic blocks with approximately this size are allocated by memory_pool.
  79. #define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024)
  80. #endif
  81. #ifndef BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT
  82. // Memory allocation alignment.
  83. // Define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer.
  84. // All memory allocations for nodes, attributes and strings will be aligned to this value.
  85. // This must be a power of 2 and at least 1, otherwise memory_pool will not work.
  86. #define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT sizeof(void *)
  87. #endif
  88. namespace boost { namespace property_tree { namespace detail {namespace rapidxml
  89. {
  90. // Forward declarations
  91. template<class Ch> class xml_node;
  92. template<class Ch> class xml_attribute;
  93. template<class Ch> class xml_document;
  94. //! Enumeration listing all node types produced by the parser.
  95. //! Use xml_node::type() function to query node type.
  96. enum node_type
  97. {
  98. node_document, //!< A document node. Name and value are empty.
  99. node_element, //!< An element node. Name contains element name. Value contains text of first data node.
  100. node_data, //!< A data node. Name is empty. Value contains data text.
  101. node_cdata, //!< A CDATA node. Name is empty. Value contains data text.
  102. node_comment, //!< A comment node. Name is empty. Value contains comment text.
  103. node_declaration, //!< A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes.
  104. node_doctype, //!< A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
  105. node_pi //!< A PI node. Name contains target. Value contains instructions.
  106. };
  107. ///////////////////////////////////////////////////////////////////////
  108. // Parsing flags
  109. //! Parse flag instructing the parser to not create data nodes.
  110. //! Text of first data node will still be placed in value of parent element, unless rapidxml::parse_no_element_values flag is also specified.
  111. //! Can be combined with other flags by use of | operator.
  112. //! <br><br>
  113. //! See xml_document::parse() function.
  114. const int parse_no_data_nodes = 0x1;
  115. //! Parse flag instructing the parser to not use text of first data node as a value of parent element.
  116. //! Can be combined with other flags by use of | operator.
  117. //! Note that child data nodes of element node take precendence over its value when printing.
  118. //! That is, if element has one or more child data nodes <em>and</em> a value, the value will be ignored.
  119. //! Use rapidxml::parse_no_data_nodes flag to prevent creation of data nodes if you want to manipulate data using values of elements.
  120. //! <br><br>
  121. //! See xml_document::parse() function.
  122. const int parse_no_element_values = 0x2;
  123. //! Parse flag instructing the parser to not place zero terminators after strings in the source text.
  124. //! By default zero terminators are placed, modifying source text.
  125. //! Can be combined with other flags by use of | operator.
  126. //! <br><br>
  127. //! See xml_document::parse() function.
  128. const int parse_no_string_terminators = 0x4;
  129. //! Parse flag instructing the parser to not translate entities in the source text.
  130. //! By default entities are translated, modifying source text.
  131. //! Can be combined with other flags by use of | operator.
  132. //! <br><br>
  133. //! See xml_document::parse() function.
  134. const int parse_no_entity_translation = 0x8;
  135. //! Parse flag instructing the parser to disable UTF-8 handling and assume plain 8 bit characters.
  136. //! By default, UTF-8 handling is enabled.
  137. //! Can be combined with other flags by use of | operator.
  138. //! <br><br>
  139. //! See xml_document::parse() function.
  140. const int parse_no_utf8 = 0x10;
  141. //! Parse flag instructing the parser to create XML declaration node.
  142. //! By default, declaration node is not created.
  143. //! Can be combined with other flags by use of | operator.
  144. //! <br><br>
  145. //! See xml_document::parse() function.
  146. const int parse_declaration_node = 0x20;
  147. //! Parse flag instructing the parser to create comments nodes.
  148. //! By default, comment nodes are not created.
  149. //! Can be combined with other flags by use of | operator.
  150. //! <br><br>
  151. //! See xml_document::parse() function.
  152. const int parse_comment_nodes = 0x40;
  153. //! Parse flag instructing the parser to create DOCTYPE node.
  154. //! By default, doctype node is not created.
  155. //! Although W3C specification allows at most one DOCTYPE node, RapidXml will silently accept documents with more than one.
  156. //! Can be combined with other flags by use of | operator.
  157. //! <br><br>
  158. //! See xml_document::parse() function.
  159. const int parse_doctype_node = 0x80;
  160. //! Parse flag instructing the parser to create PI nodes.
  161. //! By default, PI nodes are not created.
  162. //! Can be combined with other flags by use of | operator.
  163. //! <br><br>
  164. //! See xml_document::parse() function.
  165. const int parse_pi_nodes = 0x100;
  166. //! Parse flag instructing the parser to validate closing tag names.
  167. //! If not set, name inside closing tag is irrelevant to the parser.
  168. //! By default, closing tags are not validated.
  169. //! Can be combined with other flags by use of | operator.
  170. //! <br><br>
  171. //! See xml_document::parse() function.
  172. const int parse_validate_closing_tags = 0x200;
  173. //! Parse flag instructing the parser to trim all leading and trailing whitespace of data nodes.
  174. //! By default, whitespace is not trimmed.
  175. //! This flag does not cause the parser to modify source text.
  176. //! Can be combined with other flags by use of | operator.
  177. //! <br><br>
  178. //! See xml_document::parse() function.
  179. const int parse_trim_whitespace = 0x400;
  180. //! Parse flag instructing the parser to condense all whitespace runs of data nodes to a single space character.
  181. //! Trimming of leading and trailing whitespace of data is controlled by rapidxml::parse_trim_whitespace flag.
  182. //! By default, whitespace is not normalized.
  183. //! If this flag is specified, source text will be modified.
  184. //! Can be combined with other flags by use of | operator.
  185. //! <br><br>
  186. //! See xml_document::parse() function.
  187. const int parse_normalize_whitespace = 0x800;
  188. // Compound flags
  189. //! Parse flags which represent default behaviour of the parser.
  190. //! This is always equal to 0, so that all other flags can be simply ored together.
  191. //! Normally there is no need to inconveniently disable flags by anding with their negated (~) values.
  192. //! This also means that meaning of each flag is a <i>negation</i> of the default setting.
  193. //! For example, if flag name is rapidxml::parse_no_utf8, it means that utf-8 is <i>enabled</i> by default,
  194. //! and using the flag will disable it.
  195. //! <br><br>
  196. //! See xml_document::parse() function.
  197. const int parse_default = 0;
  198. //! A combination of parse flags that forbids any modifications of the source text.
  199. //! This also results in faster parsing. However, note that the following will occur:
  200. //! <ul>
  201. //! <li>names and values of nodes will not be zero terminated, you have to use xml_base::name_size() and xml_base::value_size() functions to determine where name and value ends</li>
  202. //! <li>entities will not be translated</li>
  203. //! <li>whitespace will not be normalized</li>
  204. //! </ul>
  205. //! See xml_document::parse() function.
  206. const int parse_non_destructive = parse_no_string_terminators | parse_no_entity_translation;
  207. //! A combination of parse flags resulting in fastest possible parsing, without sacrificing important data.
  208. //! <br><br>
  209. //! See xml_document::parse() function.
  210. const int parse_fastest = parse_non_destructive | parse_no_data_nodes;
  211. //! A combination of parse flags resulting in largest amount of data being extracted.
  212. //! This usually results in slowest parsing.
  213. //! <br><br>
  214. //! See xml_document::parse() function.
  215. const int parse_full = parse_declaration_node | parse_comment_nodes | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags;
  216. ///////////////////////////////////////////////////////////////////////
  217. // Internals
  218. //! \cond internal
  219. namespace internal
  220. {
  221. // Struct that contains lookup tables for the parser
  222. // It must be a template to allow correct linking (because it has static data members, which are defined in a header file).
  223. template<int Dummy>
  224. struct lookup_tables
  225. {
  226. static const unsigned char lookup_whitespace[256]; // Whitespace table
  227. static const unsigned char lookup_node_name[256]; // Node name table
  228. static const unsigned char lookup_text[256]; // Text table
  229. static const unsigned char lookup_text_pure_no_ws[256]; // Text table
  230. static const unsigned char lookup_text_pure_with_ws[256]; // Text table
  231. static const unsigned char lookup_attribute_name[256]; // Attribute name table
  232. static const unsigned char lookup_attribute_data_1[256]; // Attribute data table with single quote
  233. static const unsigned char lookup_attribute_data_1_pure[256]; // Attribute data table with single quote
  234. static const unsigned char lookup_attribute_data_2[256]; // Attribute data table with double quotes
  235. static const unsigned char lookup_attribute_data_2_pure[256]; // Attribute data table with double quotes
  236. static const unsigned char lookup_digits[256]; // Digits
  237. static const unsigned char lookup_upcase[256]; // To uppercase conversion table for ASCII characters
  238. };
  239. // Find length of the string
  240. template<class Ch>
  241. inline std::size_t measure(const Ch *p)
  242. {
  243. const Ch *tmp = p;
  244. while (*tmp)
  245. ++tmp;
  246. return tmp - p;
  247. }
  248. // Compare strings for equality
  249. template<class Ch>
  250. inline bool compare(const Ch *p1, std::size_t size1, const Ch *p2, std::size_t size2, bool case_sensitive)
  251. {
  252. if (size1 != size2)
  253. return false;
  254. if (case_sensitive)
  255. {
  256. for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
  257. if (*p1 != *p2)
  258. return false;
  259. }
  260. else
  261. {
  262. for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
  263. if (lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p1)] != lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p2)])
  264. return false;
  265. }
  266. return true;
  267. }
  268. template<class Ch>
  269. inline size_t get_index(const Ch c)
  270. {
  271. // If not ASCII char, its semantic is same as plain 'z'.
  272. // char could be signed, so first stretch and make unsigned.
  273. unsigned n = c;
  274. if (n > 127)
  275. {
  276. return 'z';
  277. }
  278. return c;
  279. }
  280. }
  281. //! \endcond
  282. ///////////////////////////////////////////////////////////////////////
  283. // Memory pool
  284. //! This class is used by the parser to create new nodes and attributes, without overheads of dynamic memory allocation.
  285. //! In most cases, you will not need to use this class directly.
  286. //! However, if you need to create nodes manually or modify names/values of nodes,
  287. //! you are encouraged to use memory_pool of relevant xml_document to allocate the memory.
  288. //! Not only is this faster than allocating them by using <code>new</code> operator,
  289. //! but also their lifetime will be tied to the lifetime of document,
  290. //! possibly simplyfing memory management.
  291. //! <br><br>
  292. //! Call allocate_node() or allocate_attribute() functions to obtain new nodes or attributes from the pool.
  293. //! You can also call allocate_string() function to allocate strings.
  294. //! Such strings can then be used as names or values of nodes without worrying about their lifetime.
  295. //! Note that there is no <code>free()</code> function -- all allocations are freed at once when clear() function is called,
  296. //! or when the pool is destroyed.
  297. //! <br><br>
  298. //! It is also possible to create a standalone memory_pool, and use it
  299. //! to allocate nodes, whose lifetime will not be tied to any document.
  300. //! <br><br>
  301. //! Pool maintains <code>BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE</code> bytes of statically allocated memory.
  302. //! Until static memory is exhausted, no dynamic memory allocations are done.
  303. //! When static memory is exhausted, pool allocates additional blocks of memory of size <code>BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE</code> each,
  304. //! by using global <code>new[]</code> and <code>delete[]</code> operators.
  305. //! This behaviour can be changed by setting custom allocation routines.
  306. //! Use set_allocator() function to set them.
  307. //! <br><br>
  308. //! Allocations for nodes, attributes and strings are aligned at <code>BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT</code> bytes.
  309. //! This value defaults to the size of pointer on target architecture.
  310. //! <br><br>
  311. //! To obtain absolutely top performance from the parser,
  312. //! it is important that all nodes are allocated from a single, contiguous block of memory.
  313. //! Otherwise, cache misses when jumping between two (or more) disjoint blocks of memory can slow down parsing quite considerably.
  314. //! If required, you can tweak <code>BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE</code>, <code>BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE</code> and <code>BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT</code>
  315. //! to obtain best wasted memory to performance compromise.
  316. //! To do it, define their values before rapidxml.hpp file is included.
  317. //! \param Ch Character type of created nodes.
  318. template<class Ch = char>
  319. class memory_pool
  320. {
  321. public:
  322. //! \cond internal
  323. // Prefixed names to work around weird MSVC lookup bug.
  324. typedef void *(boost_ptree_raw_alloc_func)(std::size_t); // Type of user-defined function used to allocate memory
  325. typedef void (boost_ptree_raw_free_func)(void *); // Type of user-defined function used to free memory
  326. //! \endcond
  327. //! Constructs empty pool with default allocator functions.
  328. memory_pool()
  329. : m_alloc_func(0)
  330. , m_free_func(0)
  331. {
  332. init();
  333. }
  334. //! Destroys pool and frees all the memory.
  335. //! This causes memory occupied by nodes allocated by the pool to be freed.
  336. //! Nodes allocated from the pool are no longer valid.
  337. ~memory_pool()
  338. {
  339. clear();
  340. }
  341. //! Allocates a new node from the pool, and optionally assigns name and value to it.
  342. //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
  343. //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
  344. //! will call rapidxml::parse_error_handler() function.
  345. //! \param type Type of node to create.
  346. //! \param name Name to assign to the node, or 0 to assign no name.
  347. //! \param value Value to assign to the node, or 0 to assign no value.
  348. //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
  349. //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
  350. //! \return Pointer to allocated node. This pointer will never be NULL.
  351. xml_node<Ch> *allocate_node(node_type type,
  352. const Ch *name = 0, const Ch *value = 0,
  353. std::size_t name_size = 0, std::size_t value_size = 0)
  354. {
  355. void *memory = allocate_aligned(sizeof(xml_node<Ch>));
  356. xml_node<Ch> *node = new(memory) xml_node<Ch>(type);
  357. if (name)
  358. {
  359. if (name_size > 0)
  360. node->name(name, name_size);
  361. else
  362. node->name(name);
  363. }
  364. if (value)
  365. {
  366. if (value_size > 0)
  367. node->value(value, value_size);
  368. else
  369. node->value(value);
  370. }
  371. return node;
  372. }
  373. //! Allocates a new attribute from the pool, and optionally assigns name and value to it.
  374. //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
  375. //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
  376. //! will call rapidxml::parse_error_handler() function.
  377. //! \param name Name to assign to the attribute, or 0 to assign no name.
  378. //! \param value Value to assign to the attribute, or 0 to assign no value.
  379. //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
  380. //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
  381. //! \return Pointer to allocated attribute. This pointer will never be NULL.
  382. xml_attribute<Ch> *allocate_attribute(const Ch *name = 0, const Ch *value = 0,
  383. std::size_t name_size = 0, std::size_t value_size = 0)
  384. {
  385. void *memory = allocate_aligned(sizeof(xml_attribute<Ch>));
  386. xml_attribute<Ch> *attribute = new(memory) xml_attribute<Ch>;
  387. if (name)
  388. {
  389. if (name_size > 0)
  390. attribute->name(name, name_size);
  391. else
  392. attribute->name(name);
  393. }
  394. if (value)
  395. {
  396. if (value_size > 0)
  397. attribute->value(value, value_size);
  398. else
  399. attribute->value(value);
  400. }
  401. return attribute;
  402. }
  403. //! Allocates a char array of given size from the pool, and optionally copies a given string to it.
  404. //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
  405. //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
  406. //! will call rapidxml::parse_error_handler() function.
  407. //! \param source String to initialize the allocated memory with, or 0 to not initialize it.
  408. //! \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.
  409. //! \return Pointer to allocated char array. This pointer will never be NULL.
  410. Ch *allocate_string(const Ch *source = 0, std::size_t size = 0)
  411. {
  412. BOOST_ASSERT(source || size); // Either source or size (or both) must be specified
  413. if (size == 0)
  414. size = internal::measure(source) + 1;
  415. Ch *result = static_cast<Ch *>(allocate_aligned(size * sizeof(Ch)));
  416. if (source)
  417. for (std::size_t i = 0; i < size; ++i)
  418. result[i] = source[i];
  419. return result;
  420. }
  421. //! Clones an xml_node and its hierarchy of child nodes and attributes.
  422. //! Nodes and attributes are allocated from this memory pool.
  423. //! Names and values are not cloned, they are shared between the clone and the source.
  424. //! Result node can be optionally specified as a second parameter,
  425. //! in which case its contents will be replaced with cloned source node.
  426. //! This is useful when you want to clone entire document.
  427. //! \param source Node to clone.
  428. //! \param result Node to put results in, or 0 to automatically allocate result node
  429. //! \return Pointer to cloned node. This pointer will never be NULL.
  430. xml_node<Ch> *clone_node(const xml_node<Ch> *source, xml_node<Ch> *result = 0)
  431. {
  432. // Prepare result node
  433. if (result)
  434. {
  435. result->remove_all_attributes();
  436. result->remove_all_nodes();
  437. result->type(source->type());
  438. }
  439. else
  440. result = allocate_node(source->type());
  441. // Clone name and value
  442. result->name(source->name(), source->name_size());
  443. result->value(source->value(), source->value_size());
  444. // Clone child nodes and attributes
  445. for (xml_node<Ch> *child = source->first_node(); child; child = child->next_sibling())
  446. result->append_node(clone_node(child));
  447. for (xml_attribute<Ch> *attr = source->first_attribute(); attr; attr = attr->next_attribute())
  448. result->append_attribute(allocate_attribute(attr->name(), attr->value(), attr->name_size(), attr->value_size()));
  449. return result;
  450. }
  451. //! Clears the pool.
  452. //! This causes memory occupied by nodes allocated by the pool to be freed.
  453. //! Any nodes or strings allocated from the pool will no longer be valid.
  454. void clear()
  455. {
  456. while (m_begin != m_static_memory)
  457. {
  458. char *previous_begin = reinterpret_cast<header *>(align(m_begin))->previous_begin;
  459. if (m_free_func)
  460. m_free_func(m_begin);
  461. else
  462. delete[] m_begin;
  463. m_begin = previous_begin;
  464. }
  465. init();
  466. }
  467. //! Sets or resets the user-defined memory allocation functions for the pool.
  468. //! This can only be called when no memory is allocated from the pool yet, otherwise results are undefined.
  469. //! Allocation function must not return invalid pointer on failure. It should either throw,
  470. //! stop the program, or use <code>longjmp()</code> function to pass control to other place of program.
  471. //! If it returns invalid pointer, results are undefined.
  472. //! <br><br>
  473. //! User defined allocation functions must have the following forms:
  474. //! <br><code>
  475. //! <br>void *allocate(std::size_t size);
  476. //! <br>void free(void *pointer);
  477. //! </code><br>
  478. //! \param af Allocation function, or 0 to restore default function
  479. //! \param ff Free function, or 0 to restore default function
  480. void set_allocator(boost_ptree_raw_alloc_func *af, boost_ptree_raw_free_func *ff)
  481. {
  482. BOOST_ASSERT(m_begin == m_static_memory && m_ptr == align(m_begin)); // Verify that no memory is allocated yet
  483. m_alloc_func = af;
  484. m_free_func = ff;
  485. }
  486. private:
  487. struct header
  488. {
  489. char *previous_begin;
  490. };
  491. void init()
  492. {
  493. m_begin = m_static_memory;
  494. m_ptr = align(m_begin);
  495. m_end = m_static_memory + sizeof(m_static_memory);
  496. }
  497. char *align(char *ptr)
  498. {
  499. 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));
  500. return ptr + alignment;
  501. }
  502. char *allocate_raw(std::size_t size)
  503. {
  504. // Allocate
  505. void *memory;
  506. if (m_alloc_func) // Allocate memory using either user-specified allocation function or global operator new[]
  507. {
  508. memory = m_alloc_func(size);
  509. BOOST_ASSERT(memory); // Allocator is not allowed to return 0, on failure it must either throw, stop the program or use longjmp
  510. }
  511. else
  512. {
  513. memory = new char[size];
  514. }
  515. return static_cast<char *>(memory);
  516. }
  517. void *allocate_aligned(std::size_t size)
  518. {
  519. // Calculate aligned pointer
  520. char *result = align(m_ptr);
  521. // If not enough memory left in current pool, allocate a new pool
  522. if (result + size > m_end)
  523. {
  524. // Calculate required pool size (may be bigger than BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE)
  525. std::size_t pool_size = BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE;
  526. if (pool_size < size)
  527. pool_size = size;
  528. // Allocate
  529. 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
  530. char *raw_memory = allocate_raw(alloc_size);
  531. // Setup new pool in allocated memory
  532. char *pool = align(raw_memory);
  533. header *new_header = reinterpret_cast<header *>(pool);
  534. new_header->previous_begin = m_begin;
  535. m_begin = raw_memory;
  536. m_ptr = pool + sizeof(header);
  537. m_end = raw_memory + alloc_size;
  538. // Calculate aligned pointer again using new pool
  539. result = align(m_ptr);
  540. }
  541. // Update pool and return aligned pointer
  542. m_ptr = result + size;
  543. return result;
  544. }
  545. char *m_begin; // Start of raw memory making up current pool
  546. char *m_ptr; // First free byte in current pool
  547. char *m_end; // One past last available byte in current pool
  548. char m_static_memory[BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE]; // Static raw memory
  549. boost_ptree_raw_alloc_func *m_alloc_func; // Allocator function, or 0 if default is to be used
  550. boost_ptree_raw_free_func *m_free_func; // Free function, or 0 if default is to be used
  551. };
  552. ///////////////////////////////////////////////////////////////////////////
  553. // XML base
  554. //! Base class for xml_node and xml_attribute implementing common functions:
  555. //! name(), name_size(), value(), value_size() and parent().
  556. //! \param Ch Character type to use
  557. template<class Ch = char>
  558. class xml_base
  559. {
  560. public:
  561. ///////////////////////////////////////////////////////////////////////////
  562. // Construction & destruction
  563. // Construct a base with empty name, value and parent
  564. xml_base()
  565. : m_name(0)
  566. , m_value(0)
  567. , m_parent(0)
  568. {
  569. }
  570. ///////////////////////////////////////////////////////////////////////////
  571. // Node data access
  572. //! Gets name of the node.
  573. //! Interpretation of name depends on type of node.
  574. //! Note that name will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
  575. //! <br><br>
  576. //! Use name_size() function to determine length of the name.
  577. //! \return Name of node, or empty string if node has no name.
  578. Ch *name() const
  579. {
  580. return m_name ? m_name : nullstr();
  581. }
  582. //! Gets size of node name, not including terminator character.
  583. //! This function works correctly irrespective of whether name is or is not zero terminated.
  584. //! \return Size of node name, in characters.
  585. std::size_t name_size() const
  586. {
  587. return m_name ? m_name_size : 0;
  588. }
  589. //! Gets value of node.
  590. //! Interpretation of value depends on type of node.
  591. //! Note that value will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
  592. //! <br><br>
  593. //! Use value_size() function to determine length of the value.
  594. //! \return Value of node, or empty string if node has no value.
  595. Ch *value() const
  596. {
  597. return m_value ? m_value : nullstr();
  598. }
  599. //! Gets size of node value, not including terminator character.
  600. //! This function works correctly irrespective of whether value is or is not zero terminated.
  601. //! \return Size of node value, in characters.
  602. std::size_t value_size() const
  603. {
  604. return m_value ? m_value_size : 0;
  605. }
  606. ///////////////////////////////////////////////////////////////////////////
  607. // Node modification
  608. //! Sets name of node to a non zero-terminated string.
  609. //! See \ref ownership_of_strings.
  610. //! <br><br>
  611. //! Note that node does not own its name or value, it only stores a pointer to it.
  612. //! It will not delete or otherwise free the pointer on destruction.
  613. //! It is reponsibility of the user to properly manage lifetime of the string.
  614. //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
  615. //! on destruction of the document the string will be automatically freed.
  616. //! <br><br>
  617. //! Size of name must be specified separately, because name does not have to be zero terminated.
  618. //! Use name(const Ch *) function to have the length automatically calculated (string must be zero terminated).
  619. //! \param n Name of node to set. Does not have to be zero terminated.
  620. //! \param size Size of name, in characters. This does not include zero terminator, if one is present.
  621. void name(const Ch *n, std::size_t size)
  622. {
  623. m_name = const_cast<Ch *>(n);
  624. m_name_size = size;
  625. }
  626. //! Sets name of node to a zero-terminated string.
  627. //! See also \ref ownership_of_strings and xml_node::name(const Ch *, std::size_t).
  628. //! \param n Name of node to set. Must be zero terminated.
  629. void name(const Ch *n)
  630. {
  631. name(n, internal::measure(n));
  632. }
  633. //! Sets value of node to a non zero-terminated string.
  634. //! See \ref ownership_of_strings.
  635. //! <br><br>
  636. //! Note that node does not own its name or value, it only stores a pointer to it.
  637. //! It will not delete or otherwise free the pointer on destruction.
  638. //! It is reponsibility of the user to properly manage lifetime of the string.
  639. //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
  640. //! on destruction of the document the string will be automatically freed.
  641. //! <br><br>
  642. //! Size of value must be specified separately, because it does not have to be zero terminated.
  643. //! Use value(const Ch *) function to have the length automatically calculated (string must be zero terminated).
  644. //! <br><br>
  645. //! If an element has a child node of type node_data, it will take precedence over element value when printing.
  646. //! 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.
  647. //! \param val value of node to set. Does not have to be zero terminated.
  648. //! \param size Size of value, in characters. This does not include zero terminator, if one is present.
  649. void value(const Ch *val, std::size_t size)
  650. {
  651. m_value = const_cast<Ch *>(val);
  652. m_value_size = size;
  653. }
  654. //! Sets value of node to a zero-terminated string.
  655. //! See also \ref ownership_of_strings and xml_node::value(const Ch *, std::size_t).
  656. //! \param val Vame of node to set. Must be zero terminated.
  657. void value(const Ch *val)
  658. {
  659. this->value(val, internal::measure(val));
  660. }
  661. ///////////////////////////////////////////////////////////////////////////
  662. // Related nodes access
  663. //! Gets node parent.
  664. //! \return Pointer to parent node, or 0 if there is no parent.
  665. xml_node<Ch> *parent() const
  666. {
  667. return m_parent;
  668. }
  669. protected:
  670. // Return empty string
  671. static Ch *nullstr()
  672. {
  673. static Ch zero = Ch('\0');
  674. return &zero;
  675. }
  676. Ch *m_name; // Name of node, or 0 if no name
  677. Ch *m_value; // Value of node, or 0 if no value
  678. std::size_t m_name_size; // Length of node name, or undefined of no name
  679. std::size_t m_value_size; // Length of node value, or undefined if no value
  680. xml_node<Ch> *m_parent; // Pointer to parent node, or 0 if none
  681. };
  682. //! Class representing attribute node of XML document.
  683. //! Each attribute has name and value strings, which are available through name() and value() functions (inherited from xml_base).
  684. //! Note that after parse, both name and value of attribute will point to interior of source text used for parsing.
  685. //! Thus, this text must persist in memory for the lifetime of attribute.
  686. //! \param Ch Character type to use.
  687. template<class Ch = char>
  688. class xml_attribute: public xml_base<Ch>
  689. {
  690. friend class xml_node<Ch>;
  691. public:
  692. ///////////////////////////////////////////////////////////////////////////
  693. // Construction & destruction
  694. //! Constructs an empty attribute with the specified type.
  695. //! Consider using memory_pool of appropriate xml_document if allocating attributes manually.
  696. xml_attribute()
  697. {
  698. }
  699. ///////////////////////////////////////////////////////////////////////////
  700. // Related nodes access
  701. //! Gets document of which attribute is a child.
  702. //! \return Pointer to document that contains this attribute, or 0 if there is no parent document.
  703. xml_document<Ch> *document() const
  704. {
  705. if (xml_node<Ch> *node = this->parent())
  706. {
  707. while (node->parent())
  708. node = node->parent();
  709. return node->type() == node_document ? static_cast<xml_document<Ch> *>(node) : 0;
  710. }
  711. else
  712. return 0;
  713. }
  714. //! Gets previous attribute, optionally matching attribute name.
  715. //! \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
  716. //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
  717. //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
  718. //! \return Pointer to found attribute, or 0 if not found.
  719. xml_attribute<Ch> *previous_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
  720. {
  721. if (n)
  722. {
  723. if (nsize == 0)
  724. nsize = internal::measure(n);
  725. for (xml_attribute<Ch> *attribute = m_prev_attribute; attribute; attribute = attribute->m_prev_attribute)
  726. if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
  727. return attribute;
  728. return 0;
  729. }
  730. else
  731. return this->m_parent ? m_prev_attribute : 0;
  732. }
  733. //! Gets next attribute, optionally matching attribute name.
  734. //! \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
  735. //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
  736. //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
  737. //! \return Pointer to found attribute, or 0 if not found.
  738. xml_attribute<Ch> *next_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
  739. {
  740. if (n)
  741. {
  742. if (nsize == 0)
  743. nsize = internal::measure(n);
  744. for (xml_attribute<Ch> *attribute = m_next_attribute; attribute; attribute = attribute->m_next_attribute)
  745. if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
  746. return attribute;
  747. return 0;
  748. }
  749. else
  750. return this->m_parent ? m_next_attribute : 0;
  751. }
  752. private:
  753. xml_attribute<Ch> *m_prev_attribute; // Pointer to previous sibling of attribute, or 0 if none; only valid if parent is non-zero
  754. xml_attribute<Ch> *m_next_attribute; // Pointer to next sibling of attribute, or 0 if none; only valid if parent is non-zero
  755. };
  756. ///////////////////////////////////////////////////////////////////////////
  757. // XML node
  758. //! Class representing a node of XML document.
  759. //! Each node may have associated name and value strings, which are available through name() and value() functions.
  760. //! Interpretation of name and value depends on type of the node.
  761. //! Type of node can be determined by using type() function.
  762. //! <br><br>
  763. //! Note that after parse, both name and value of node, if any, will point interior of source text used for parsing.
  764. //! Thus, this text must persist in the memory for the lifetime of node.
  765. //! \param Ch Character type to use.
  766. template<class Ch = char>
  767. class xml_node: public xml_base<Ch>
  768. {
  769. public:
  770. ///////////////////////////////////////////////////////////////////////////
  771. // Construction & destruction
  772. //! Constructs an empty node with the specified type.
  773. //! Consider using memory_pool of appropriate document to allocate nodes manually.
  774. //! \param t Type of node to construct.
  775. xml_node(node_type t)
  776. : m_type(t)
  777. , m_first_node(0)
  778. , m_first_attribute(0)
  779. {
  780. }
  781. ///////////////////////////////////////////////////////////////////////////
  782. // Node data access
  783. //! Gets type of node.
  784. //! \return Type of node.
  785. node_type type() const
  786. {
  787. return m_type;
  788. }
  789. ///////////////////////////////////////////////////////////////////////////
  790. // Related nodes access
  791. //! Gets document of which node is a child.
  792. //! \return Pointer to document that contains this node, or 0 if there is no parent document.
  793. xml_document<Ch> *document() const
  794. {
  795. xml_node<Ch> *node = const_cast<xml_node<Ch> *>(this);
  796. while (node->parent())
  797. node = node->parent();
  798. return node->type() == node_document ? static_cast<xml_document<Ch> *>(node) : 0;
  799. }
  800. //! Gets first child node, optionally matching node name.
  801. //! \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
  802. //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
  803. //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
  804. //! \return Pointer to found child, or 0 if not found.
  805. xml_node<Ch> *first_node(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
  806. {
  807. if (n)
  808. {
  809. if (nsize == 0)
  810. nsize = internal::measure(n);
  811. for (xml_node<Ch> *child = m_first_node; child; child = child->next_sibling())
  812. if (internal::compare(child->name(), child->name_size(), n, nsize, case_sensitive))
  813. return child;
  814. return 0;
  815. }
  816. else
  817. return m_first_node;
  818. }
  819. //! Gets last child node, optionally matching node name.
  820. //! Behaviour is undefined if node has no children.
  821. //! Use first_node() to test if node has children.
  822. //! \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
  823. //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
  824. //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
  825. //! \return Pointer to found child, or 0 if not found.
  826. xml_node<Ch> *last_node(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
  827. {
  828. BOOST_ASSERT(m_first_node); // Cannot query for last child if node has no children
  829. if (n)
  830. {
  831. if (nsize == 0)
  832. nsize = internal::measure(n);
  833. for (xml_node<Ch> *child = m_last_node; child; child = child->previous_sibling())
  834. if (internal::compare(child->name(), child->name_size(), n, nsize, case_sensitive))
  835. return child;
  836. return 0;
  837. }
  838. else
  839. return m_last_node;
  840. }
  841. //! Gets previous sibling node, optionally matching node name.
  842. //! Behaviour is undefined if node has no parent.
  843. //! Use parent() to test if node has a parent.
  844. //! \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
  845. //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
  846. //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
  847. //! \return Pointer to found sibling, or 0 if not found.
  848. xml_node<Ch> *previous_sibling(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
  849. {
  850. BOOST_ASSERT(this->m_parent); // Cannot query for siblings if node has no parent
  851. if (n)
  852. {
  853. if (nsize == 0)
  854. nsize = internal::measure(n);
  855. for (xml_node<Ch> *sibling = m_prev_sibling; sibling; sibling = sibling->m_prev_sibling)
  856. if (internal::compare(sibling->name(), sibling->name_size(), n, nsize, case_sensitive))
  857. return sibling;
  858. return 0;
  859. }
  860. else
  861. return m_prev_sibling;
  862. }
  863. //! Gets next sibling node, optionally matching node name.
  864. //! Behaviour is undefined if node has no parent.
  865. //! Use parent() to test if node has a parent.
  866. //! \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
  867. //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
  868. //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
  869. //! \return Pointer to found sibling, or 0 if not found.
  870. xml_node<Ch> *next_sibling(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
  871. {
  872. BOOST_ASSERT(this->m_parent); // Cannot query for siblings if node has no parent
  873. if (n)
  874. {
  875. if (nsize == 0)
  876. nsize = internal::measure(n);
  877. for (xml_node<Ch> *sibling = m_next_sibling; sibling; sibling = sibling->m_next_sibling)
  878. if (internal::compare(sibling->name(), sibling->name_size(), n, nsize, case_sensitive))
  879. return sibling;
  880. return 0;
  881. }
  882. else
  883. return m_next_sibling;
  884. }
  885. //! Gets first attribute of node, optionally matching attribute name.
  886. //! \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
  887. //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
  888. //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
  889. //! \return Pointer to found attribute, or 0 if not found.
  890. xml_attribute<Ch> *first_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
  891. {
  892. if (n)
  893. {
  894. if (nsize == 0)
  895. nsize = internal::measure(n);
  896. for (xml_attribute<Ch> *attribute = m_first_attribute; attribute; attribute = attribute->m_next_attribute)
  897. if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
  898. return attribute;
  899. return 0;
  900. }
  901. else
  902. return m_first_attribute;
  903. }
  904. //! Gets last attribute of node, optionally matching attribute name.
  905. //! \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
  906. //! \param nsize Size of name, in characters, or 0 to have size calculated automatically from string
  907. //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
  908. //! \return Pointer to found attribute, or 0 if not found.
  909. xml_attribute<Ch> *last_attribute(const Ch *n = 0, std::size_t nsize = 0, bool case_sensitive = true) const
  910. {
  911. if (n)
  912. {
  913. if (nsize == 0)
  914. nsize = internal::measure(n);
  915. for (xml_attribute<Ch> *attribute = m_last_attribute; attribute; attribute = attribute->m_prev_attribute)
  916. if (internal::compare(attribute->name(), attribute->name_size(), n, nsize, case_sensitive))
  917. return attribute;
  918. return 0;
  919. }
  920. else
  921. return m_first_attribute ? m_last_attribute : 0;
  922. }
  923. ///////////////////////////////////////////////////////////////////////////
  924. // Node modification
  925. //! Sets type of node.
  926. //! \param t Type of node to set.
  927. void type(node_type t)
  928. {
  929. m_type = t;
  930. }
  931. ///////////////////////////////////////////////////////////////////////////
  932. // Node manipulation
  933. //! Prepends a new child node.
  934. //! The prepended child becomes the first child, and all existing children are moved one position back.
  935. //! \param child Node to prepend.
  936. void prepend_node(xml_node<Ch> *child)
  937. {
  938. BOOST_ASSERT(child && !child->parent() && child->type() != node_document);
  939. if (first_node())
  940. {
  941. child->m_next_sibling = m_first_node;
  942. m_first_node->m_prev_sibling = child;
  943. }
  944. else
  945. {
  946. child->m_next_sibling = 0;
  947. m_last_node = child;
  948. }
  949. m_first_node = child;
  950. child->m_parent = this;
  951. child->m_prev_sibling = 0;
  952. }
  953. //! Appends a new child node.
  954. //! The appended child becomes the last child.
  955. //! \param child Node to append.
  956. void append_node(xml_node<Ch> *child)
  957. {
  958. BOOST_ASSERT(child && !child->parent() && child->type() != node_document);
  959. if (first_node())
  960. {
  961. child->m_prev_sibling = m_last_node;
  962. m_last_node->m_next_sibling = child;
  963. }
  964. else
  965. {
  966. child->m_prev_sibling = 0;
  967. m_first_node = child;
  968. }
  969. m_last_node = child;
  970. child->m_parent = this;
  971. child->m_next_sibling = 0;
  972. }
  973. //! Inserts a new child node at specified place inside the node.
  974. //! All children after and including the specified node are moved one position back.
  975. //! \param where Place where to insert the child, or 0 to insert at the back.
  976. //! \param child Node to insert.
  977. void insert_node(xml_node<Ch> *where, xml_node<Ch> *child)
  978. {
  979. BOOST_ASSERT(!where || where->parent() == this);
  980. BOOST_ASSERT(child && !child->parent() && child->type() != node_document);
  981. if (where == m_first_node)
  982. prepend_node(child);
  983. else if (where == 0)
  984. append_node(child);
  985. else
  986. {
  987. child->m_prev_sibling = where->m_prev_sibling;
  988. child->m_next_sibling = where;
  989. where->m_prev_sibling->m_next_sibling = child;
  990. where->m_prev_sibling = child;
  991. child->m_parent = this;
  992. }
  993. }
  994. //! Removes first child node.
  995. //! If node has no children, behaviour is undefined.
  996. //! Use first_node() to test if node has children.
  997. void remove_first_node()
  998. {
  999. BOOST_ASSERT(first_node());
  1000. xml_node<Ch> *child = m_first_node;
  1001. m_first_node = child->m_next_sibling;
  1002. if (child->m_next_sibling)
  1003. child->m_next_sibling->m_prev_sibling = 0;
  1004. else
  1005. m_last_node = 0;
  1006. child->m_parent = 0;
  1007. }
  1008. //! Removes last child of the node.
  1009. //! If node has no children, behaviour is undefined.
  1010. //! Use first_node() to test if node has children.
  1011. void remove_last_node()
  1012. {
  1013. BOOST_ASSERT(first_node());
  1014. xml_node<Ch> *child = m_last_node;
  1015. if (child->m_prev_sibling)
  1016. {
  1017. m_last_node = child->m_prev_sibling;
  1018. child->m_prev_sibling->m_next_sibling = 0;
  1019. }
  1020. else
  1021. m_first_node = 0;
  1022. child->m_parent = 0;
  1023. }
  1024. //! Removes specified child from the node
  1025. // \param where Pointer to child to be removed.
  1026. void remove_node(xml_node<Ch> *where)
  1027. {
  1028. BOOST_ASSERT(where && where->parent() == this);
  1029. BOOST_ASSERT(first_node());
  1030. if (where == m_first_node)
  1031. remove_first_node();
  1032. else if (where == m_last_node)
  1033. remove_last_node();
  1034. else
  1035. {
  1036. where->m_prev_sibling->m_next_sibling = where->m_next_sibling;
  1037. where->m_next_sibling->m_prev_sibling = where->m_prev_sibling;
  1038. where->m_parent = 0;
  1039. }
  1040. }
  1041. //! Removes all child nodes (but not attributes).
  1042. void remove_all_nodes()
  1043. {
  1044. for (xml_node<Ch> *node = first_node(); node; node = node->m_next_sibling)
  1045. node->m_parent = 0;
  1046. m_first_node = 0;
  1047. }
  1048. //! Prepends a new attribute to the node.
  1049. //! \param attribute Attribute to prepend.
  1050. void prepend_attribute(xml_attribute<Ch> *attribute)
  1051. {
  1052. BOOST_ASSERT(attribute && !attribute->parent());
  1053. if (first_attribute())
  1054. {
  1055. attribute->m_next_attribute = m_first_attribute;
  1056. m_first_attribute->m_prev_attribute = attribute;
  1057. }
  1058. else
  1059. {
  1060. attribute->m_next_attribute = 0;
  1061. m_last_attribute = attribute;
  1062. }
  1063. m_first_attribute = attribute;
  1064. attribute->m_parent = this;
  1065. attribute->m_prev_attribute = 0;
  1066. }
  1067. //! Appends a new attribute to the node.
  1068. //! \param attribute Attribute to append.
  1069. void append_attribute(xml_attribute<Ch> *attribute)
  1070. {
  1071. BOOST_ASSERT(attribute && !attribute->parent());
  1072. if (first_attribute())
  1073. {
  1074. attribute->m_prev_attribute = m_last_attribute;
  1075. m_last_attribute->m_next_attribute = attribute;
  1076. }
  1077. else
  1078. {
  1079. attribute->m_prev_attribute = 0;
  1080. m_first_attribute = attribute;
  1081. }
  1082. m_last_attribute = attribute;
  1083. attribute->m_parent = this;
  1084. attribute->m_next_attribute = 0;
  1085. }
  1086. //! Inserts a new attribute at specified place inside the node.
  1087. //! All attributes after and including the specified attribute are moved one position back.
  1088. //! \param where Place where to insert the attribute, or 0 to insert at the back.
  1089. //! \param attribute Attribute to insert.
  1090. void insert_attribute(xml_attribute<Ch> *where, xml_attribute<Ch> *attribute)
  1091. {
  1092. BOOST_ASSERT(!where || where->parent() == this);
  1093. BOOST_ASSERT(attribute && !attribute->parent());
  1094. if (where == m_first_attribute)
  1095. prepend_attribute(attribute);
  1096. else if (where == 0)
  1097. append_attribute(attribute);
  1098. else
  1099. {
  1100. attribute->m_prev_attribute = where->m_prev_attribute;
  1101. attribute->m_next_attribute = where;
  1102. where->m_prev_attribute->m_next_attribute = attribute;
  1103. where->m_prev_attribute = attribute;
  1104. attribute->m_parent = this;
  1105. }
  1106. }
  1107. //! Removes first attribute of the node.
  1108. //! If node has no attributes, behaviour is undefined.
  1109. //! Use first_attribute() to test if node has attributes.
  1110. void remove_first_attribute()
  1111. {
  1112. BOOST_ASSERT(first_attribute());
  1113. xml_attribute<Ch> *attribute = m_first_attribute;
  1114. if (attribute->m_next_attribute)
  1115. {
  1116. attribute->m_next_attribute->m_prev_attribute = 0;
  1117. }
  1118. else
  1119. m_last_attribute = 0;
  1120. attribute->m_parent = 0;
  1121. m_first_attribute = attribute->m_next_attribute;
  1122. }
  1123. //! Removes last attribute of the node.
  1124. //! If node has no attributes, behaviour is undefined.
  1125. //! Use first_attribute() to test if node has attributes.
  1126. void remove_last_attribute()
  1127. {
  1128. BOOST_ASSERT(first_attribute());
  1129. xml_attribute<Ch> *attribute = m_last_attribute;
  1130. if (attribute->m_prev_attribute)
  1131. {
  1132. attribute->m_prev_attribute->m_next_attribute = 0;
  1133. m_last_attribute = attribute->m_prev_attribute;
  1134. }
  1135. else
  1136. m_first_attribute = 0;
  1137. attribute->m_parent = 0;
  1138. }
  1139. //! Removes specified attribute from node.
  1140. //! \param where Pointer to attribute to be removed.
  1141. void remove_attribute(xml_attribute<Ch> *where)
  1142. {
  1143. BOOST_ASSERT(first_attribute() && where->parent() == this);
  1144. if (where == m_first_attribute)
  1145. remove_first_attribute();
  1146. else if (where == m_last_attribute)
  1147. remove_last_attribute();
  1148. else
  1149. {
  1150. where->m_prev_attribute->m_next_attribute = where->m_next_attribute;
  1151. where->m_next_attribute->m_prev_attribute = where->m_prev_attribute;
  1152. where->m_parent = 0;
  1153. }
  1154. }
  1155. //! Removes all attributes of node.
  1156. void remove_all_attributes()
  1157. {
  1158. for (xml_attribute<Ch> *attribute = first_attribute(); attribute; attribute = attribute->m_next_attribute)
  1159. attribute->m_parent = 0;
  1160. m_first_attribute = 0;
  1161. }
  1162. private:
  1163. ///////////////////////////////////////////////////////////////////////////
  1164. // Restrictions
  1165. // No copying
  1166. xml_node(const xml_node &);
  1167. void operator =(const xml_node &);
  1168. ///////////////////////////////////////////////////////////////////////////
  1169. // Data members
  1170. // Note that some of the pointers below have UNDEFINED values if certain other pointers are 0.
  1171. // This is required for maximum performance, as it allows the parser to omit initialization of
  1172. // unneded/redundant values.
  1173. //
  1174. // The rules are as follows:
  1175. // 1. first_node and first_attribute contain valid pointers, or 0 if node has no children/attributes respectively
  1176. // 2. last_node and last_attribute are valid only if node has at least one child/attribute respectively, otherwise they contain garbage
  1177. // 3. prev_sibling and next_sibling are valid only if node has a parent, otherwise they contain garbage
  1178. node_type m_type; // Type of node; always valid
  1179. xml_node<Ch> *m_first_node; // Pointer to first child node, or 0 if none; always valid
  1180. xml_node<Ch> *m_last_node; // Pointer to last child node, or 0 if none; this value is only valid if m_first_node is non-zero
  1181. xml_attribute<Ch> *m_first_attribute; // Pointer to first attribute of node, or 0 if none; always valid
  1182. xml_attribute<Ch> *m_last_attribute; // Pointer to last attribute of node, or 0 if none; this value is only valid if m_first_attribute is non-zero
  1183. xml_node<Ch> *m_prev_sibling; // Pointer to previous sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
  1184. xml_node<Ch> *m_next_sibling; // Pointer to next sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
  1185. };
  1186. ///////////////////////////////////////////////////////////////////////////
  1187. // XML document
  1188. //! This class represents root of the DOM hierarchy.
  1189. //! It is also an xml_node and a memory_pool through public inheritance.
  1190. //! Use parse() function to build a DOM tree from a zero-terminated XML text string.
  1191. //! parse() function allocates memory for nodes and attributes by using functions of xml_document,
  1192. //! which are inherited from memory_pool.
  1193. //! To access root node of the document, use the document itself, as if it was an xml_node.
  1194. //! \param Ch Character type to use.
  1195. template<class Ch = char>
  1196. class xml_document: public xml_node<Ch>, public memory_pool<Ch>
  1197. {
  1198. public:
  1199. //! Constructs empty XML document
  1200. xml_document()
  1201. : xml_node<Ch>(node_document)
  1202. {
  1203. }
  1204. //! Parses zero-terminated XML string according to given flags.
  1205. //! Passed string will be modified by the parser, unless rapidxml::parse_non_destructive flag is used.
  1206. //! The string must persist for the lifetime of the document.
  1207. //! In case of error, rapidxml::parse_error exception will be thrown.
  1208. //! <br><br>
  1209. //! If you want to parse contents of a file, you must first load the file into the memory, and pass pointer to its beginning.
  1210. //! Make sure that data is zero-terminated.
  1211. //! <br><br>
  1212. //! Document can be parsed into multiple times.
  1213. //! Each new call to parse removes previous nodes and attributes (if any), but does not clear memory pool.
  1214. //! \param text XML data to parse; pointer is non-const to denote fact that this data may be modified by the parser.
  1215. template<int Flags>
  1216. void parse(Ch *text)
  1217. {
  1218. BOOST_ASSERT(text);
  1219. // Remove current contents
  1220. this->remove_all_nodes();
  1221. this->remove_all_attributes();
  1222. // Parse BOM, if any
  1223. parse_bom<Flags>(text);
  1224. // Parse children
  1225. while (1)
  1226. {
  1227. // Skip whitespace before node
  1228. skip<whitespace_pred, Flags>(text);
  1229. if (*text == 0)
  1230. break;
  1231. // Parse and append new child
  1232. if (*text == Ch('<'))
  1233. {
  1234. ++text; // Skip '<'
  1235. if (xml_node<Ch> *node = parse_node<Flags>(text))
  1236. this->append_node(node);
  1237. }
  1238. else
  1239. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected <", text);
  1240. }
  1241. }
  1242. //! Clears the document by deleting all nodes and clearing the memory pool.
  1243. //! All nodes owned by document pool are destroyed.
  1244. void clear()
  1245. {
  1246. this->remove_all_nodes();
  1247. this->remove_all_attributes();
  1248. memory_pool<Ch>::clear();
  1249. }
  1250. private:
  1251. ///////////////////////////////////////////////////////////////////////
  1252. // Internal character utility functions
  1253. // Detect whitespace character
  1254. struct whitespace_pred
  1255. {
  1256. static unsigned char test(Ch ch)
  1257. {
  1258. return internal::lookup_tables<0>::lookup_whitespace[internal::get_index(ch)];
  1259. }
  1260. };
  1261. // Detect node name character
  1262. struct node_name_pred
  1263. {
  1264. static unsigned char test(Ch ch)
  1265. {
  1266. return internal::lookup_tables<0>::lookup_node_name[internal::get_index(ch)];
  1267. }
  1268. };
  1269. // Detect attribute name character
  1270. struct attribute_name_pred
  1271. {
  1272. static unsigned char test(Ch ch)
  1273. {
  1274. return internal::lookup_tables<0>::lookup_attribute_name[internal::get_index(ch)];
  1275. }
  1276. };
  1277. // Detect text character (PCDATA)
  1278. struct text_pred
  1279. {
  1280. static unsigned char test(Ch ch)
  1281. {
  1282. return internal::lookup_tables<0>::lookup_text[internal::get_index(ch)];
  1283. }
  1284. };
  1285. // Detect text character (PCDATA) that does not require processing
  1286. struct text_pure_no_ws_pred
  1287. {
  1288. static unsigned char test(Ch ch)
  1289. {
  1290. return internal::lookup_tables<0>::lookup_text_pure_no_ws[internal::get_index(ch)];
  1291. }
  1292. };
  1293. // Detect text character (PCDATA) that does not require processing
  1294. struct text_pure_with_ws_pred
  1295. {
  1296. static unsigned char test(Ch ch)
  1297. {
  1298. return internal::lookup_tables<0>::lookup_text_pure_with_ws[internal::get_index(ch)];
  1299. }
  1300. };
  1301. // Detect attribute value character
  1302. template<Ch Quote>
  1303. struct attribute_value_pred
  1304. {
  1305. static unsigned char test(Ch ch)
  1306. {
  1307. if (Quote == Ch('\''))
  1308. return internal::lookup_tables<0>::lookup_attribute_data_1[internal::get_index(ch)];
  1309. if (Quote == Ch('\"'))
  1310. return internal::lookup_tables<0>::lookup_attribute_data_2[internal::get_index(ch)];
  1311. return 0; // Should never be executed, to avoid warnings on Comeau
  1312. }
  1313. };
  1314. // Detect attribute value character
  1315. template<Ch Quote>
  1316. struct attribute_value_pure_pred
  1317. {
  1318. static unsigned char test(Ch ch)
  1319. {
  1320. if (Quote == Ch('\''))
  1321. return internal::lookup_tables<0>::lookup_attribute_data_1_pure[internal::get_index(ch)];
  1322. if (Quote == Ch('\"'))
  1323. return internal::lookup_tables<0>::lookup_attribute_data_2_pure[internal::get_index(ch)];
  1324. return 0; // Should never be executed, to avoid warnings on Comeau
  1325. }
  1326. };
  1327. // Insert coded character, using UTF8 or 8-bit ASCII
  1328. template<int Flags>
  1329. static void insert_coded_character(Ch *&text, unsigned long code)
  1330. {
  1331. if (Flags & parse_no_utf8)
  1332. {
  1333. // Insert 8-bit ASCII character
  1334. // Todo: possibly verify that code is less than 256 and use replacement char otherwise?
  1335. text[0] = static_cast<unsigned char>(code);
  1336. text += 1;
  1337. }
  1338. else
  1339. {
  1340. // Insert UTF8 sequence
  1341. if (code < 0x80) // 1 byte sequence
  1342. {
  1343. text[0] = static_cast<unsigned char>(code);
  1344. text += 1;
  1345. }
  1346. else if (code < 0x800) // 2 byte sequence
  1347. {
  1348. text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
  1349. text[0] = static_cast<unsigned char>(code | 0xC0);
  1350. text += 2;
  1351. }
  1352. else if (code < 0x10000) // 3 byte sequence
  1353. {
  1354. text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
  1355. text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
  1356. text[0] = static_cast<unsigned char>(code | 0xE0);
  1357. text += 3;
  1358. }
  1359. else if (code < 0x110000) // 4 byte sequence
  1360. {
  1361. text[3] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
  1362. text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
  1363. text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
  1364. text[0] = static_cast<unsigned char>(code | 0xF0);
  1365. text += 4;
  1366. }
  1367. else // Invalid, only codes up to 0x10FFFF are allowed in Unicode
  1368. {
  1369. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid numeric character entity", text);
  1370. }
  1371. }
  1372. }
  1373. // Skip characters until predicate evaluates to true
  1374. template<class StopPred, int Flags>
  1375. static void skip(Ch *&text)
  1376. {
  1377. Ch *tmp = text;
  1378. while (StopPred::test(*tmp))
  1379. ++tmp;
  1380. text = tmp;
  1381. }
  1382. // Skip characters until predicate evaluates to true while doing the following:
  1383. // - replacing XML character entity references with proper characters (&apos; &amp; &quot; &lt; &gt; &#...;)
  1384. // - condensing whitespace sequences to single space character
  1385. template<class StopPred, class StopPredPure, int Flags>
  1386. static Ch *skip_and_expand_character_refs(Ch *&text)
  1387. {
  1388. // If entity translation, whitespace condense and whitespace trimming is disabled, use plain skip
  1389. if (Flags & parse_no_entity_translation &&
  1390. !(Flags & parse_normalize_whitespace) &&
  1391. !(Flags & parse_trim_whitespace))
  1392. {
  1393. skip<StopPred, Flags>(text);
  1394. return text;
  1395. }
  1396. // Use simple skip until first modification is detected
  1397. skip<StopPredPure, Flags>(text);
  1398. // Use translation skip
  1399. Ch *src = text;
  1400. Ch *dest = src;
  1401. while (StopPred::test(*src))
  1402. {
  1403. // If entity translation is enabled
  1404. if (!(Flags & parse_no_entity_translation))
  1405. {
  1406. // Test if replacement is needed
  1407. if (src[0] == Ch('&'))
  1408. {
  1409. switch (src[1])
  1410. {
  1411. // &amp; &apos;
  1412. case Ch('a'):
  1413. if (src[2] == Ch('m') && src[3] == Ch('p') && src[4] == Ch(';'))
  1414. {
  1415. *dest = Ch('&');
  1416. ++dest;
  1417. src += 5;
  1418. continue;
  1419. }
  1420. if (src[2] == Ch('p') && src[3] == Ch('o') && src[4] == Ch('s') && src[5] == Ch(';'))
  1421. {
  1422. *dest = Ch('\'');
  1423. ++dest;
  1424. src += 6;
  1425. continue;
  1426. }
  1427. break;
  1428. // &quot;
  1429. case Ch('q'):
  1430. if (src[2] == Ch('u') && src[3] == Ch('o') && src[4] == Ch('t') && src[5] == Ch(';'))
  1431. {
  1432. *dest = Ch('"');
  1433. ++dest;
  1434. src += 6;
  1435. continue;
  1436. }
  1437. break;
  1438. // &gt;
  1439. case Ch('g'):
  1440. if (src[2] == Ch('t') && src[3] == Ch(';'))
  1441. {
  1442. *dest = Ch('>');
  1443. ++dest;
  1444. src += 4;
  1445. continue;
  1446. }
  1447. break;
  1448. // &lt;
  1449. case Ch('l'):
  1450. if (src[2] == Ch('t') && src[3] == Ch(';'))
  1451. {
  1452. *dest = Ch('<');
  1453. ++dest;
  1454. src += 4;
  1455. continue;
  1456. }
  1457. break;
  1458. // &#...; - assumes ASCII
  1459. case Ch('#'):
  1460. if (src[2] == Ch('x'))
  1461. {
  1462. unsigned long code = 0;
  1463. src += 3; // Skip &#x
  1464. while (1)
  1465. {
  1466. unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
  1467. if (digit == 0xFF)
  1468. break;
  1469. code = code * 16 + digit;
  1470. ++src;
  1471. }
  1472. insert_coded_character<Flags>(dest, code); // Put character in output
  1473. }
  1474. else
  1475. {
  1476. unsigned long code = 0;
  1477. src += 2; // Skip &#
  1478. while (1)
  1479. {
  1480. unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
  1481. if (digit == 0xFF)
  1482. break;
  1483. code = code * 10 + digit;
  1484. ++src;
  1485. }
  1486. insert_coded_character<Flags>(dest, code); // Put character in output
  1487. }
  1488. if (*src == Ch(';'))
  1489. ++src;
  1490. else
  1491. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ;", src);
  1492. continue;
  1493. // Something else
  1494. default:
  1495. // Ignore, just copy '&' verbatim
  1496. break;
  1497. }
  1498. }
  1499. }
  1500. // If whitespace condensing is enabled
  1501. if (Flags & parse_normalize_whitespace)
  1502. {
  1503. // Test if condensing is needed
  1504. if (whitespace_pred::test(*src))
  1505. {
  1506. *dest = Ch(' '); ++dest; // Put single space in dest
  1507. ++src; // Skip first whitespace char
  1508. // Skip remaining whitespace chars
  1509. while (whitespace_pred::test(*src))
  1510. ++src;
  1511. continue;
  1512. }
  1513. }
  1514. // No replacement, only copy character
  1515. *dest++ = *src++;
  1516. }
  1517. // Return new end
  1518. text = src;
  1519. return dest;
  1520. }
  1521. ///////////////////////////////////////////////////////////////////////
  1522. // Internal parsing functions
  1523. // Parse UTF-8 BOM, if any
  1524. template<int Flags>
  1525. void parse_bom(char *&text)
  1526. {
  1527. if (static_cast<unsigned char>(text[0]) == 0xEF &&
  1528. static_cast<unsigned char>(text[1]) == 0xBB &&
  1529. static_cast<unsigned char>(text[2]) == 0xBF)
  1530. {
  1531. text += 3;
  1532. }
  1533. }
  1534. // Parse UTF-16/32 BOM, if any
  1535. template<int Flags>
  1536. void parse_bom(wchar_t *&text)
  1537. {
  1538. const wchar_t bom = 0xFEFF;
  1539. if (text[0] == bom)
  1540. {
  1541. ++text;
  1542. }
  1543. }
  1544. // Parse XML declaration (<?xml...)
  1545. template<int Flags>
  1546. xml_node<Ch> *parse_xml_declaration(Ch *&text)
  1547. {
  1548. // If parsing of declaration is disabled
  1549. if (!(Flags & parse_declaration_node))
  1550. {
  1551. // Skip until end of declaration
  1552. while (text[0] != Ch('?') || text[1] != Ch('>'))
  1553. {
  1554. if (!text[0])
  1555. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1556. ++text;
  1557. }
  1558. text += 2; // Skip '?>'
  1559. return 0;
  1560. }
  1561. // Create declaration
  1562. xml_node<Ch> *declaration = this->allocate_node(node_declaration);
  1563. // Skip whitespace before attributes or ?>
  1564. skip<whitespace_pred, Flags>(text);
  1565. // Parse declaration attributes
  1566. parse_node_attributes<Flags>(text, declaration);
  1567. // Skip ?>
  1568. if (text[0] != Ch('?') || text[1] != Ch('>'))
  1569. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ?>", text);
  1570. text += 2;
  1571. return declaration;
  1572. }
  1573. // Parse XML comment (<!--...)
  1574. template<int Flags>
  1575. xml_node<Ch> *parse_comment(Ch *&text)
  1576. {
  1577. // If parsing of comments is disabled
  1578. if (!(Flags & parse_comment_nodes))
  1579. {
  1580. // Skip until end of comment
  1581. while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
  1582. {
  1583. if (!text[0])
  1584. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1585. ++text;
  1586. }
  1587. text += 3; // Skip '-->'
  1588. return 0; // Do not produce comment node
  1589. }
  1590. // Remember value start
  1591. Ch *val = text;
  1592. // Skip until end of comment
  1593. while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
  1594. {
  1595. if (!text[0])
  1596. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1597. ++text;
  1598. }
  1599. // Create comment node
  1600. xml_node<Ch> *comment = this->allocate_node(node_comment);
  1601. comment->value(val, text - val);
  1602. // Place zero terminator after comment value
  1603. if (!(Flags & parse_no_string_terminators))
  1604. *text = Ch('\0');
  1605. text += 3; // Skip '-->'
  1606. return comment;
  1607. }
  1608. // Parse DOCTYPE
  1609. template<int Flags>
  1610. xml_node<Ch> *parse_doctype(Ch *&text)
  1611. {
  1612. // Remember value start
  1613. Ch *val = text;
  1614. // Skip to >
  1615. while (*text != Ch('>'))
  1616. {
  1617. // Determine character type
  1618. switch (*text)
  1619. {
  1620. // If '[' encountered, scan for matching ending ']' using naive algorithm with depth
  1621. // This works for all W3C test files except for 2 most wicked
  1622. case Ch('['):
  1623. {
  1624. ++text; // Skip '['
  1625. int depth = 1;
  1626. while (depth > 0)
  1627. {
  1628. switch (*text)
  1629. {
  1630. case Ch('['): ++depth; break;
  1631. case Ch(']'): --depth; break;
  1632. case 0: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1633. default: break;
  1634. }
  1635. ++text;
  1636. }
  1637. break;
  1638. }
  1639. // Error on end of text
  1640. case Ch('\0'):
  1641. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1642. // Other character, skip it
  1643. default:
  1644. ++text;
  1645. }
  1646. }
  1647. // If DOCTYPE nodes enabled
  1648. if (Flags & parse_doctype_node)
  1649. {
  1650. // Create a new doctype node
  1651. xml_node<Ch> *doctype = this->allocate_node(node_doctype);
  1652. doctype->value(val, text - val);
  1653. // Place zero terminator after value
  1654. if (!(Flags & parse_no_string_terminators))
  1655. *text = Ch('\0');
  1656. text += 1; // skip '>'
  1657. return doctype;
  1658. }
  1659. else
  1660. {
  1661. text += 1; // skip '>'
  1662. return 0;
  1663. }
  1664. }
  1665. // Parse PI
  1666. template<int Flags>
  1667. xml_node<Ch> *parse_pi(Ch *&text)
  1668. {
  1669. // If creation of PI nodes is enabled
  1670. if (Flags & parse_pi_nodes)
  1671. {
  1672. // Create pi node
  1673. xml_node<Ch> *pi = this->allocate_node(node_pi);
  1674. // Extract PI target name
  1675. Ch *n = text;
  1676. skip<node_name_pred, Flags>(text);
  1677. if (text == n)
  1678. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected PI target", text);
  1679. pi->name(n, text - n);
  1680. // Skip whitespace between pi target and pi
  1681. skip<whitespace_pred, Flags>(text);
  1682. // Remember start of pi
  1683. Ch *val = text;
  1684. // Skip to '?>'
  1685. while (text[0] != Ch('?') || text[1] != Ch('>'))
  1686. {
  1687. if (*text == Ch('\0'))
  1688. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1689. ++text;
  1690. }
  1691. // Set pi value (verbatim, no entity expansion or whitespace normalization)
  1692. pi->value(val, text - val);
  1693. // Place zero terminator after name and value
  1694. if (!(Flags & parse_no_string_terminators))
  1695. {
  1696. pi->name()[pi->name_size()] = Ch('\0');
  1697. pi->value()[pi->value_size()] = Ch('\0');
  1698. }
  1699. text += 2; // Skip '?>'
  1700. return pi;
  1701. }
  1702. else
  1703. {
  1704. // Skip to '?>'
  1705. while (text[0] != Ch('?') || text[1] != Ch('>'))
  1706. {
  1707. if (*text == Ch('\0'))
  1708. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1709. ++text;
  1710. }
  1711. text += 2; // Skip '?>'
  1712. return 0;
  1713. }
  1714. }
  1715. // Parse and append data
  1716. // Return character that ends data.
  1717. // This is necessary because this character might have been overwritten by a terminating 0
  1718. template<int Flags>
  1719. Ch parse_and_append_data(xml_node<Ch> *node, Ch *&text, Ch *contents_start)
  1720. {
  1721. // Backup to contents start if whitespace trimming is disabled
  1722. if (!(Flags & parse_trim_whitespace))
  1723. text = contents_start;
  1724. // Skip until end of data
  1725. Ch *val = text, *end;
  1726. if (Flags & parse_normalize_whitespace)
  1727. end = skip_and_expand_character_refs<text_pred, text_pure_with_ws_pred, Flags>(text);
  1728. else
  1729. end = skip_and_expand_character_refs<text_pred, text_pure_no_ws_pred, Flags>(text);
  1730. // Trim trailing whitespace if flag is set; leading was already trimmed by whitespace skip after >
  1731. if (Flags & parse_trim_whitespace)
  1732. {
  1733. if (Flags & parse_normalize_whitespace)
  1734. {
  1735. // Whitespace is already condensed to single space characters by skipping function, so just trim 1 char off the end
  1736. if (*(end - 1) == Ch(' '))
  1737. --end;
  1738. }
  1739. else
  1740. {
  1741. // Backup until non-whitespace character is found
  1742. while (whitespace_pred::test(*(end - 1)))
  1743. --end;
  1744. }
  1745. }
  1746. // If characters are still left between end and value (this test is only necessary if normalization is enabled)
  1747. // Create new data node
  1748. if (!(Flags & parse_no_data_nodes))
  1749. {
  1750. xml_node<Ch> *data = this->allocate_node(node_data);
  1751. data->value(val, end - val);
  1752. node->append_node(data);
  1753. }
  1754. // Add data to parent node if no data exists yet
  1755. if (!(Flags & parse_no_element_values))
  1756. if (*node->value() == Ch('\0'))
  1757. node->value(val, end - val);
  1758. // Place zero terminator after value
  1759. if (!(Flags & parse_no_string_terminators))
  1760. {
  1761. Ch ch = *text;
  1762. *end = Ch('\0');
  1763. return ch; // Return character that ends data; this is required because zero terminator overwritten it
  1764. }
  1765. // Return character that ends data
  1766. return *text;
  1767. }
  1768. // Parse CDATA
  1769. template<int Flags>
  1770. xml_node<Ch> *parse_cdata(Ch *&text)
  1771. {
  1772. // If CDATA is disabled
  1773. if (Flags & parse_no_data_nodes)
  1774. {
  1775. // Skip until end of cdata
  1776. while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
  1777. {
  1778. if (!text[0])
  1779. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1780. ++text;
  1781. }
  1782. text += 3; // Skip ]]>
  1783. return 0; // Do not produce CDATA node
  1784. }
  1785. // Skip until end of cdata
  1786. Ch *val = text;
  1787. while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
  1788. {
  1789. if (!text[0])
  1790. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1791. ++text;
  1792. }
  1793. // Create new cdata node
  1794. xml_node<Ch> *cdata = this->allocate_node(node_cdata);
  1795. cdata->value(val, text - val);
  1796. // Place zero terminator after value
  1797. if (!(Flags & parse_no_string_terminators))
  1798. *text = Ch('\0');
  1799. text += 3; // Skip ]]>
  1800. return cdata;
  1801. }
  1802. // Parse element node
  1803. template<int Flags>
  1804. xml_node<Ch> *parse_element(Ch *&text)
  1805. {
  1806. // Create element node
  1807. xml_node<Ch> *element = this->allocate_node(node_element);
  1808. // Extract element name
  1809. Ch *n = text;
  1810. skip<node_name_pred, Flags>(text);
  1811. if (text == n)
  1812. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected element name", text);
  1813. element->name(n, text - n);
  1814. // Skip whitespace between element name and attributes or >
  1815. skip<whitespace_pred, Flags>(text);
  1816. // Parse attributes, if any
  1817. parse_node_attributes<Flags>(text, element);
  1818. // Determine ending type
  1819. if (*text == Ch('>'))
  1820. {
  1821. ++text;
  1822. parse_node_contents<Flags>(text, element);
  1823. }
  1824. else if (*text == Ch('/'))
  1825. {
  1826. ++text;
  1827. if (*text != Ch('>'))
  1828. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
  1829. ++text;
  1830. }
  1831. else
  1832. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
  1833. // Place zero terminator after name
  1834. if (!(Flags & parse_no_string_terminators))
  1835. element->name()[element->name_size()] = Ch('\0');
  1836. // Return parsed element
  1837. return element;
  1838. }
  1839. // Determine node type, and parse it
  1840. template<int Flags>
  1841. xml_node<Ch> *parse_node(Ch *&text)
  1842. {
  1843. // Parse proper node type
  1844. switch (text[0])
  1845. {
  1846. // <...
  1847. default:
  1848. // Parse and append element node
  1849. return parse_element<Flags>(text);
  1850. // <?...
  1851. case Ch('?'):
  1852. ++text; // Skip ?
  1853. if ((text[0] == Ch('x') || text[0] == Ch('X')) &&
  1854. (text[1] == Ch('m') || text[1] == Ch('M')) &&
  1855. (text[2] == Ch('l') || text[2] == Ch('L')) &&
  1856. whitespace_pred::test(text[3]))
  1857. {
  1858. // '<?xml ' - xml declaration
  1859. text += 4; // Skip 'xml '
  1860. return parse_xml_declaration<Flags>(text);
  1861. }
  1862. else
  1863. {
  1864. // Parse PI
  1865. return parse_pi<Flags>(text);
  1866. }
  1867. // <!...
  1868. case Ch('!'):
  1869. // Parse proper subset of <! node
  1870. switch (text[1])
  1871. {
  1872. // <!-
  1873. case Ch('-'):
  1874. if (text[2] == Ch('-'))
  1875. {
  1876. // '<!--' - xml comment
  1877. text += 3; // Skip '!--'
  1878. return parse_comment<Flags>(text);
  1879. }
  1880. break;
  1881. // <![
  1882. case Ch('['):
  1883. if (text[2] == Ch('C') && text[3] == Ch('D') && text[4] == Ch('A') &&
  1884. text[5] == Ch('T') && text[6] == Ch('A') && text[7] == Ch('['))
  1885. {
  1886. // '<![CDATA[' - cdata
  1887. text += 8; // Skip '![CDATA['
  1888. return parse_cdata<Flags>(text);
  1889. }
  1890. break;
  1891. // <!D
  1892. case Ch('D'):
  1893. if (text[2] == Ch('O') && text[3] == Ch('C') && text[4] == Ch('T') &&
  1894. text[5] == Ch('Y') && text[6] == Ch('P') && text[7] == Ch('E') &&
  1895. whitespace_pred::test(text[8]))
  1896. {
  1897. // '<!DOCTYPE ' - doctype
  1898. text += 9; // skip '!DOCTYPE '
  1899. return parse_doctype<Flags>(text);
  1900. }
  1901. break;
  1902. default: break;
  1903. } // switch
  1904. // Attempt to skip other, unrecognized node types starting with <!
  1905. ++text; // Skip !
  1906. while (*text != Ch('>'))
  1907. {
  1908. if (*text == 0)
  1909. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1910. ++text;
  1911. }
  1912. ++text; // Skip '>'
  1913. return 0; // No node recognized
  1914. }
  1915. }
  1916. // Parse contents of the node - children, data etc.
  1917. template<int Flags>
  1918. void parse_node_contents(Ch *&text, xml_node<Ch> *node)
  1919. {
  1920. // For all children and text
  1921. while (1)
  1922. {
  1923. // Skip whitespace between > and node contents
  1924. Ch *contents_start = text; // Store start of node contents before whitespace is skipped
  1925. if (Flags & parse_trim_whitespace)
  1926. skip<whitespace_pred, Flags>(text);
  1927. Ch next_char = *text;
  1928. // After data nodes, instead of continuing the loop, control jumps here.
  1929. // This is because zero termination inside parse_and_append_data() function
  1930. // would wreak havoc with the above code.
  1931. // Also, skipping whitespace after data nodes is unnecessary.
  1932. after_data_node:
  1933. // Determine what comes next: node closing, child node, data node, or 0?
  1934. switch (next_char)
  1935. {
  1936. // Node closing or child node
  1937. case Ch('<'):
  1938. if (text[1] == Ch('/'))
  1939. {
  1940. // Node closing
  1941. text += 2; // Skip '</'
  1942. if (Flags & parse_validate_closing_tags)
  1943. {
  1944. // Skip and validate closing tag name
  1945. Ch *closing_name = text;
  1946. skip<node_name_pred, Flags>(text);
  1947. if (!internal::compare(node->name(), node->name_size(), closing_name, text - closing_name, true))
  1948. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid closing tag name", text);
  1949. }
  1950. else
  1951. {
  1952. // No validation, just skip name
  1953. skip<node_name_pred, Flags>(text);
  1954. }
  1955. // Skip remaining whitespace after node name
  1956. skip<whitespace_pred, Flags>(text);
  1957. if (*text != Ch('>'))
  1958. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
  1959. ++text; // Skip '>'
  1960. return; // Node closed, finished parsing contents
  1961. }
  1962. else
  1963. {
  1964. // Child node
  1965. ++text; // Skip '<'
  1966. if (xml_node<Ch> *child = parse_node<Flags>(text))
  1967. node->append_node(child);
  1968. }
  1969. break;
  1970. // End of data - error
  1971. case Ch('\0'):
  1972. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
  1973. // Data node
  1974. default:
  1975. next_char = parse_and_append_data<Flags>(node, text, contents_start);
  1976. goto after_data_node; // Bypass regular processing after data nodes
  1977. }
  1978. }
  1979. }
  1980. // Parse XML attributes of the node
  1981. template<int Flags>
  1982. void parse_node_attributes(Ch *&text, xml_node<Ch> *node)
  1983. {
  1984. // For all attributes
  1985. while (attribute_name_pred::test(*text))
  1986. {
  1987. // Extract attribute name
  1988. Ch *n = text;
  1989. ++text; // Skip first character of attribute name
  1990. skip<attribute_name_pred, Flags>(text);
  1991. if (text == n)
  1992. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected attribute name", n);
  1993. // Create new attribute
  1994. xml_attribute<Ch> *attribute = this->allocate_attribute();
  1995. attribute->name(n, text - n);
  1996. node->append_attribute(attribute);
  1997. // Skip whitespace after attribute name
  1998. skip<whitespace_pred, Flags>(text);
  1999. // Skip =
  2000. if (*text != Ch('='))
  2001. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected =", text);
  2002. ++text;
  2003. // Add terminating zero after name
  2004. if (!(Flags & parse_no_string_terminators))
  2005. attribute->name()[attribute->name_size()] = 0;
  2006. // Skip whitespace after =
  2007. skip<whitespace_pred, Flags>(text);
  2008. // Skip quote and remember if it was ' or "
  2009. Ch quote = *text;
  2010. if (quote != Ch('\'') && quote != Ch('"'))
  2011. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text);
  2012. ++text;
  2013. // Extract attribute value and expand char refs in it
  2014. Ch *val = text, *end;
  2015. const int AttFlags = Flags & ~parse_normalize_whitespace; // No whitespace normalization in attributes
  2016. if (quote == Ch('\''))
  2017. end = skip_and_expand_character_refs<attribute_value_pred<Ch('\'')>, attribute_value_pure_pred<Ch('\'')>, AttFlags>(text);
  2018. else
  2019. end = skip_and_expand_character_refs<attribute_value_pred<Ch('"')>, attribute_value_pure_pred<Ch('"')>, AttFlags>(text);
  2020. // Set attribute value
  2021. attribute->value(val, end - val);
  2022. // Make sure that end quote is present
  2023. if (*text != quote)
  2024. BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text);
  2025. ++text; // Skip quote
  2026. // Add terminating zero after value
  2027. if (!(Flags & parse_no_string_terminators))
  2028. attribute->value()[attribute->value_size()] = 0;
  2029. // Skip whitespace after attribute value
  2030. skip<whitespace_pred, Flags>(text);
  2031. }
  2032. }
  2033. };
  2034. //! \cond internal
  2035. namespace internal
  2036. {
  2037. // Whitespace (space \n \r \t)
  2038. template<int Dummy>
  2039. const unsigned char lookup_tables<Dummy>::lookup_whitespace[256] =
  2040. {
  2041. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, // 0
  2043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
  2044. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2
  2045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3
  2046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4
  2047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5
  2048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6
  2049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 7
  2050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8
  2051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9
  2052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A
  2053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B
  2054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // C
  2055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // D
  2056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // E
  2057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // F
  2058. };
  2059. // Node name (anything but space \n \r \t / > ? \0)
  2060. template<int Dummy>
  2061. const unsigned char lookup_tables<Dummy>::lookup_node_name[256] =
  2062. {
  2063. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2064. 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
  2065. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2066. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2
  2067. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, // 3
  2068. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2069. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2070. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2071. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2072. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2073. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2074. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2075. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2076. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2077. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2078. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2079. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2080. };
  2081. // Text (i.e. PCDATA) (anything but < \0)
  2082. template<int Dummy>
  2083. const unsigned char lookup_tables<Dummy>::lookup_text[256] =
  2084. {
  2085. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2086. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
  2087. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2088. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
  2089. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
  2090. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2091. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2092. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2093. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2094. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2095. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2096. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2097. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2098. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2099. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2100. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2101. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2102. };
  2103. // Text (i.e. PCDATA) that does not require processing when ws normalization is disabled
  2104. // (anything but < \0 &)
  2105. template<int Dummy>
  2106. const unsigned char lookup_tables<Dummy>::lookup_text_pure_no_ws[256] =
  2107. {
  2108. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2109. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
  2110. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2111. 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
  2112. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
  2113. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2114. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2115. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2116. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2117. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2118. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2119. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2120. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2121. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2122. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2123. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2124. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2125. };
  2126. // Text (i.e. PCDATA) that does not require processing when ws normalizationis is enabled
  2127. // (anything but < \0 & space \n \r \t)
  2128. template<int Dummy>
  2129. const unsigned char lookup_tables<Dummy>::lookup_text_pure_with_ws[256] =
  2130. {
  2131. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2132. 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
  2133. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2134. 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
  2135. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
  2136. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2137. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2138. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2139. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2140. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2141. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2142. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2143. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2144. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2145. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2146. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2147. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2148. };
  2149. // Attribute name (anything but space \n \r \t / < > = ? ! \0)
  2150. template<int Dummy>
  2151. const unsigned char lookup_tables<Dummy>::lookup_attribute_name[256] =
  2152. {
  2153. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2154. 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
  2155. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2156. 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2
  2157. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, // 3
  2158. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2159. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2160. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2161. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2162. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2163. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2164. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2165. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2166. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2167. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2168. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2169. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2170. };
  2171. // Attribute data with single quote (anything but ' \0)
  2172. template<int Dummy>
  2173. const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1[256] =
  2174. {
  2175. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2176. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
  2177. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2178. 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2
  2179. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
  2180. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2181. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2182. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2183. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2184. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2185. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2186. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2187. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2188. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2189. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2190. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2191. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2192. };
  2193. // Attribute data with single quote that does not require processing (anything but ' \0 &)
  2194. template<int Dummy>
  2195. const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1_pure[256] =
  2196. {
  2197. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2198. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
  2199. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2200. 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2
  2201. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
  2202. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2203. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2204. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2205. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2206. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2207. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2208. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2209. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2210. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2211. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2212. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2213. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2214. };
  2215. // Attribute data with double quote (anything but " \0)
  2216. template<int Dummy>
  2217. const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2[256] =
  2218. {
  2219. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2220. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
  2221. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2222. 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
  2223. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
  2224. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2225. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2226. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2227. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2228. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2229. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2230. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2231. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2232. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2233. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2234. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2235. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2236. };
  2237. // Attribute data with double quote that does not require processing (anything but " \0 &)
  2238. template<int Dummy>
  2239. const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2_pure[256] =
  2240. {
  2241. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2242. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
  2243. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
  2244. 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
  2245. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
  2246. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
  2247. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
  2248. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
  2249. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
  2250. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
  2251. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
  2252. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
  2253. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
  2254. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
  2255. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
  2256. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
  2257. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
  2258. };
  2259. // Digits (dec and hex, 255 denotes end of numeric character reference)
  2260. template<int Dummy>
  2261. const unsigned char lookup_tables<Dummy>::lookup_digits[256] =
  2262. {
  2263. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  2264. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 0
  2265. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 1
  2266. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 2
  2267. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,255,255,255,255,255,255, // 3
  2268. 255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255, // 4
  2269. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 5
  2270. 255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255, // 6
  2271. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 7
  2272. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 8
  2273. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 9
  2274. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // A
  2275. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // B
  2276. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // C
  2277. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // D
  2278. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // E
  2279. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 // F
  2280. };
  2281. // Upper case conversion
  2282. template<int Dummy>
  2283. const unsigned char lookup_tables<Dummy>::lookup_upcase[256] =
  2284. {
  2285. // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A B C D E F
  2286. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 0
  2287. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, // 1
  2288. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, // 2
  2289. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, // 3
  2290. 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, // 4
  2291. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, // 5
  2292. 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, // 6
  2293. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123,124,125,126,127, // 7
  2294. 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, // 8
  2295. 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, // 9
  2296. 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, // A
  2297. 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, // B
  2298. 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, // C
  2299. 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, // D
  2300. 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, // E
  2301. 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 // F
  2302. };
  2303. }
  2304. //! \endcond
  2305. }}}}
  2306. // Undefine internal macros
  2307. #undef BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR
  2308. // On MSVC, restore warnings state
  2309. #ifdef _MSC_VER
  2310. #pragma warning(pop)
  2311. #endif
  2312. #endif