rapidxml.h 117 KB

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