rapidxml.hpp 116 KB

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