rapidxml.hpp 116 KB

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