XmlUTF8TextReader.cs 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. // Parser
  5. // PERF: Optimize double, decimal? They get converted to strings in lots of cases
  6. // PERF: Cleanup CharType. Don't generate tables at runtime. Use const tables.
  7. namespace System.Xml
  8. {
  9. using System;
  10. using System.IO;
  11. using System.Runtime;
  12. using System.Runtime.Serialization; // For SR
  13. using System.Text;
  14. public interface IXmlTextReaderInitializer
  15. {
  16. void SetInput(byte[] buffer, int offset, int count, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose);
  17. void SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose);
  18. }
  19. class XmlUTF8TextReader : XmlBaseReader, IXmlLineInfo, IXmlTextReaderInitializer
  20. {
  21. const int MaxTextChunk = 2048;
  22. PrefixHandle prefix;
  23. StringHandle localName;
  24. int[] rowOffsets;
  25. OnXmlDictionaryReaderClose onClose;
  26. bool buffered;
  27. int maxBytesPerRead;
  28. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.SpacingRules", "SA1003:SymbolsMustBeSpacedCorrectly", Justification = "Spacing is concise")]
  29. static byte[] charType = new byte[256]
  30. {
  31. /* 0 (.) */ CharType.None,
  32. /* 1 (.) */ CharType.None,
  33. /* 2 (.) */ CharType.None,
  34. /* 3 (.) */ CharType.None,
  35. /* 4 (.) */ CharType.None,
  36. /* 5 (.) */ CharType.None,
  37. /* 6 (.) */ CharType.None,
  38. /* 7 (.) */ CharType.None,
  39. /* 8 (.) */ CharType.None,
  40. /* 9 (.) */ CharType.None|CharType.Comment|CharType.Comment|CharType.Whitespace|CharType.Text|CharType.SpecialWhitespace,
  41. /* A (.) */ CharType.None|CharType.Comment|CharType.Comment|CharType.Whitespace|CharType.Text|CharType.SpecialWhitespace,
  42. /* B (.) */ CharType.None,
  43. /* C (.) */ CharType.None,
  44. /* D (.) */ CharType.None|CharType.Comment|CharType.Comment|CharType.Whitespace,
  45. /* E (.) */ CharType.None,
  46. /* F (.) */ CharType.None,
  47. /* 10 (.) */ CharType.None,
  48. /* 11 (.) */ CharType.None,
  49. /* 12 (.) */ CharType.None,
  50. /* 13 (.) */ CharType.None,
  51. /* 14 (.) */ CharType.None,
  52. /* 15 (.) */ CharType.None,
  53. /* 16 (.) */ CharType.None,
  54. /* 17 (.) */ CharType.None,
  55. /* 18 (.) */ CharType.None,
  56. /* 19 (.) */ CharType.None,
  57. /* 1A (.) */ CharType.None,
  58. /* 1B (.) */ CharType.None,
  59. /* 1C (.) */ CharType.None,
  60. /* 1D (.) */ CharType.None,
  61. /* 1E (.) */ CharType.None,
  62. /* 1F (.) */ CharType.None,
  63. /* 20 ( ) */ CharType.None|CharType.Comment|CharType.Whitespace|CharType.Text|CharType.AttributeText|CharType.SpecialWhitespace,
  64. /* 21 (!) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  65. /* 22 (") */ CharType.None|CharType.Comment|CharType.Text,
  66. /* 23 (#) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  67. /* 24 ($) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  68. /* 25 (%) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  69. /* 26 (&) */ CharType.None|CharType.Comment,
  70. /* 27 (') */ CharType.None|CharType.Comment|CharType.Text,
  71. /* 28 (() */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  72. /* 29 ()) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  73. /* 2A (*) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  74. /* 2B (+) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  75. /* 2C (,) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  76. /* 2D (-) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  77. /* 2E (.) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  78. /* 2F (/) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  79. /* 30 (0) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  80. /* 31 (1) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  81. /* 32 (2) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  82. /* 33 (3) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  83. /* 34 (4) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  84. /* 35 (5) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  85. /* 36 (6) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  86. /* 37 (7) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  87. /* 38 (8) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  88. /* 39 (9) */ CharType.None|CharType.Comment|CharType.Name|CharType.Text|CharType.AttributeText,
  89. /* 3A (:) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  90. /* 3B (;) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  91. /* 3C (<) */ CharType.None|CharType.Comment,
  92. /* 3D (=) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  93. /* 3E (>) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  94. /* 3F (?) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  95. /* 40 (@) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  96. /* 41 (A) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  97. /* 42 (B) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  98. /* 43 (C) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  99. /* 44 (D) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  100. /* 45 (E) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  101. /* 46 (F) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  102. /* 47 (G) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  103. /* 48 (H) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  104. /* 49 (I) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  105. /* 4A (J) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  106. /* 4B (K) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  107. /* 4C (L) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  108. /* 4D (M) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  109. /* 4E (N) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  110. /* 4F (O) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  111. /* 50 (P) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  112. /* 51 (Q) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  113. /* 52 (R) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  114. /* 53 (S) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  115. /* 54 (T) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  116. /* 55 (U) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  117. /* 56 (V) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  118. /* 57 (W) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  119. /* 58 (X) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  120. /* 59 (Y) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  121. /* 5A (Z) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  122. /* 5B ([) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  123. /* 5C (\) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  124. /* 5D (]) */ CharType.None|CharType.Comment|CharType.AttributeText,
  125. /* 5E (^) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  126. /* 5F (_) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  127. /* 60 (`) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  128. /* 61 (a) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  129. /* 62 (b) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  130. /* 63 (c) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  131. /* 64 (d) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  132. /* 65 (e) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  133. /* 66 (f) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  134. /* 67 (g) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  135. /* 68 (h) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  136. /* 69 (i) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  137. /* 6A (j) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  138. /* 6B (k) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  139. /* 6C (l) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  140. /* 6D (m) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  141. /* 6E (n) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  142. /* 6F (o) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  143. /* 70 (p) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  144. /* 71 (q) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  145. /* 72 (r) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  146. /* 73 (s) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  147. /* 74 (t) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  148. /* 75 (u) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  149. /* 76 (v) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  150. /* 77 (w) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  151. /* 78 (x) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  152. /* 79 (y) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  153. /* 7A (z) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  154. /* 7B ({) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  155. /* 7C (|) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  156. /* 7D (}) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  157. /* 7E (~) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  158. /* 7F (.) */ CharType.None|CharType.Comment|CharType.Text|CharType.AttributeText,
  159. /* 80 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  160. /* 81 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  161. /* 82 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  162. /* 83 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  163. /* 84 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  164. /* 85 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  165. /* 86 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  166. /* 87 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  167. /* 88 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  168. /* 89 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  169. /* 8A (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  170. /* 8B (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  171. /* 8C (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  172. /* 8D (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  173. /* 8E (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  174. /* 8F (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  175. /* 90 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  176. /* 91 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  177. /* 92 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  178. /* 93 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  179. /* 94 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  180. /* 95 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  181. /* 96 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  182. /* 97 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  183. /* 98 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  184. /* 99 (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  185. /* 9A (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  186. /* 9B (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  187. /* 9C (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  188. /* 9D (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  189. /* 9E (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  190. /* 9F (.) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  191. /* A0 (ÿ) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  192. /* A1 (­) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  193. /* A2 (›) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  194. /* A3 (œ) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  195. /* A4 () */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  196. /* A5 (�) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  197. /* A6 (Ý) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  198. /* A7 () */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  199. /* A8 (") */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  200. /* A9 (c) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  201. /* AA (¦) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  202. /* AB (®) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  203. /* AC (ª) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  204. /* AD (-) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  205. /* AE (r) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  206. /* AF (_) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  207. /* B0 (ø) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  208. /* B1 (ñ) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  209. /* B2 (ý) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  210. /* B3 (3) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  211. /* B4 (') */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  212. /* B5 (æ) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  213. /* B6 () */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  214. /* B7 (ú) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  215. /* B8 (,) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  216. /* B9 (1) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  217. /* BA (§) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  218. /* BB (¯) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  219. /* BC (¬) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  220. /* BD («) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  221. /* BE (_) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  222. /* BF (¨) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  223. /* C0 (A) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  224. /* C1 (A) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  225. /* C2 (A) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  226. /* C3 (A) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  227. /* C4 (Ž) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  228. /* C5 (�) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  229. /* C6 (’) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  230. /* C7 (€) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  231. /* C8 (E) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  232. /* C9 (�) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  233. /* CA (E) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  234. /* CB (E) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  235. /* CC (I) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  236. /* CD (I) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  237. /* CE (I) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  238. /* CF (I) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  239. /* D0 (D) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  240. /* D1 (¥) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  241. /* D2 (O) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  242. /* D3 (O) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  243. /* D4 (O) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  244. /* D5 (O) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  245. /* D6 (™) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  246. /* D7 (x) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  247. /* D8 (O) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  248. /* D9 (U) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  249. /* DA (U) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  250. /* DB (U) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  251. /* DC (š) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  252. /* DD (Y) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  253. /* DE (_) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  254. /* DF (á) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  255. /* E0 (…) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  256. /* E1 ( ) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  257. /* E2 (ƒ) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  258. /* E3 (a) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  259. /* E4 („) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  260. /* E5 (†) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  261. /* E6 (‘) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  262. /* E7 (‡) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  263. /* E8 (Š) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  264. /* E9 (‚) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  265. /* EA (ˆ) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  266. /* EB (‰) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  267. /* EC (�) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  268. /* ED (¡) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  269. /* EE (Œ) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  270. /* EF (‹) */ CharType.None|CharType.FirstName|CharType.Name,
  271. /* F0 (d) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  272. /* F1 (¤) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  273. /* F2 (•) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  274. /* F3 (¢) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  275. /* F4 (“) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  276. /* F5 (o) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  277. /* F6 (”) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  278. /* F7 (ö) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  279. /* F8 (o) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  280. /* F9 (—) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  281. /* FA (£) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  282. /* FB (–) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  283. /* FC (�) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  284. /* FD (y) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  285. /* FE (_) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  286. /* FF (˜) */ CharType.None|CharType.Comment|CharType.FirstName|CharType.Name|CharType.Text|CharType.AttributeText,
  287. };
  288. public XmlUTF8TextReader()
  289. {
  290. this.prefix = new PrefixHandle(BufferReader);
  291. this.localName = new StringHandle(BufferReader);
  292. #if GENERATE_CHARTYPE
  293. CharType.Generate();
  294. #endif
  295. }
  296. public void SetInput(byte[] buffer, int offset, int count, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
  297. {
  298. if (buffer == null)
  299. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("buffer"));
  300. if (offset < 0)
  301. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.ValueMustBeNonNegative)));
  302. if (offset > buffer.Length)
  303. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", SR.GetString(SR.OffsetExceedsBufferSize, buffer.Length)));
  304. if (count < 0)
  305. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", SR.GetString(SR.ValueMustBeNonNegative)));
  306. if (count > buffer.Length - offset)
  307. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", SR.GetString(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
  308. MoveToInitial(quotas, onClose);
  309. ArraySegment<byte> seg = EncodingStreamWrapper.ProcessBuffer(buffer, offset, count, encoding);
  310. BufferReader.SetBuffer(seg.Array, seg.Offset, seg.Count, null, null);
  311. this.buffered = true;
  312. }
  313. public void SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
  314. {
  315. if (stream == null)
  316. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
  317. MoveToInitial(quotas, onClose);
  318. stream = new EncodingStreamWrapper(stream, encoding);
  319. BufferReader.SetBuffer(stream, null, null);
  320. this.buffered = false;
  321. }
  322. void MoveToInitial(XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
  323. {
  324. MoveToInitial(quotas);
  325. this.maxBytesPerRead = quotas.MaxBytesPerRead;
  326. this.onClose = onClose;
  327. }
  328. public override void Close()
  329. {
  330. rowOffsets = null;
  331. base.Close();
  332. OnXmlDictionaryReaderClose onClose = this.onClose;
  333. this.onClose = null;
  334. if (onClose != null)
  335. {
  336. try
  337. {
  338. onClose(this);
  339. }
  340. catch (Exception e)
  341. {
  342. if (Fx.IsFatal(e)) throw;
  343. throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
  344. }
  345. }
  346. }
  347. void SkipWhitespace()
  348. {
  349. while (!BufferReader.EndOfFile && (charType[BufferReader.GetByte()] & CharType.Whitespace) != 0)
  350. BufferReader.SkipByte();
  351. }
  352. void ReadDeclaration()
  353. {
  354. if (!buffered)
  355. BufferElement();
  356. int offset;
  357. byte[] buffer = BufferReader.GetBuffer(5, out offset);
  358. if (buffer[offset + 0] != (byte)'?' ||
  359. buffer[offset + 1] != (byte)'x' ||
  360. buffer[offset + 2] != (byte)'m' ||
  361. buffer[offset + 3] != (byte)'l' ||
  362. (charType[buffer[offset + 4]] & CharType.Whitespace) == 0)
  363. {
  364. XmlExceptionHelper.ThrowProcessingInstructionNotSupported(this);
  365. }
  366. // If anything came before the "<?xml ?>" it's an error.
  367. if (this.Node.ReadState != ReadState.Initial)
  368. {
  369. XmlExceptionHelper.ThrowDeclarationNotFirst(this);
  370. }
  371. BufferReader.Advance(5);
  372. int localNameOffset = offset + 1;
  373. int localNameLength = 3;
  374. int valueOffset = BufferReader.Offset;
  375. SkipWhitespace();
  376. ReadAttributes();
  377. int valueLength = BufferReader.Offset - valueOffset;
  378. // Backoff the spaces
  379. while (valueLength > 0)
  380. {
  381. byte ch = BufferReader.GetByte(valueOffset + valueLength - 1);
  382. if ((charType[ch] & CharType.Whitespace) == 0)
  383. break;
  384. valueLength--;
  385. }
  386. buffer = BufferReader.GetBuffer(2, out offset);
  387. if (buffer[offset + 0] != (byte)'?' ||
  388. buffer[offset + 1] != (byte)'>')
  389. {
  390. XmlExceptionHelper.ThrowTokenExpected(this, "?>", Encoding.UTF8.GetString(buffer, offset, 2));
  391. }
  392. BufferReader.Advance(2);
  393. XmlDeclarationNode declarationNode = MoveToDeclaration();
  394. declarationNode.LocalName.SetValue(localNameOffset, localNameLength);
  395. declarationNode.Value.SetValue(ValueHandleType.UTF8, valueOffset, valueLength);
  396. }
  397. void VerifyNCName(string s)
  398. {
  399. try
  400. {
  401. XmlConvert.VerifyNCName(s);
  402. }
  403. catch (XmlException exception)
  404. {
  405. XmlExceptionHelper.ThrowXmlException(this, exception);
  406. }
  407. }
  408. void ReadQualifiedName(PrefixHandle prefix, StringHandle localName)
  409. {
  410. int offset;
  411. int offsetMax;
  412. byte[] buffer = BufferReader.GetBuffer(out offset, out offsetMax);
  413. int ch = 0;
  414. int anyChar = 0;
  415. int prefixChar = 0;
  416. int prefixOffset = offset;
  417. if (offset < offsetMax)
  418. {
  419. ch = buffer[offset];
  420. prefixChar = ch;
  421. if ((charType[ch] & CharType.FirstName) == 0)
  422. anyChar |= 0x80;
  423. anyChar |= ch;
  424. offset++;
  425. while (offset < offsetMax)
  426. {
  427. ch = buffer[offset];
  428. if ((charType[ch] & CharType.Name) == 0)
  429. break;
  430. anyChar |= ch;
  431. offset++;
  432. }
  433. }
  434. else
  435. {
  436. anyChar |= 0x80;
  437. ch = 0;
  438. }
  439. if (ch == ':')
  440. {
  441. int prefixLength = offset - prefixOffset;
  442. if (prefixLength == 1 && prefixChar >= 'a' && prefixChar <= 'z')
  443. prefix.SetValue(PrefixHandle.GetAlphaPrefix(prefixChar - 'a'));
  444. else
  445. prefix.SetValue(prefixOffset, prefixLength);
  446. offset++;
  447. int localNameOffset = offset;
  448. if (offset < offsetMax)
  449. {
  450. ch = buffer[offset];
  451. if ((charType[ch] & CharType.FirstName) == 0)
  452. anyChar |= 0x80;
  453. anyChar |= ch;
  454. offset++;
  455. while (offset < offsetMax)
  456. {
  457. ch = buffer[offset];
  458. if ((charType[ch] & CharType.Name) == 0)
  459. break;
  460. anyChar |= ch;
  461. offset++;
  462. }
  463. }
  464. else
  465. {
  466. anyChar |= 0x80;
  467. ch = 0;
  468. }
  469. localName.SetValue(localNameOffset, offset - localNameOffset);
  470. if (anyChar >= 0x80)
  471. {
  472. VerifyNCName(prefix.GetString());
  473. VerifyNCName(localName.GetString());
  474. }
  475. }
  476. else
  477. {
  478. prefix.SetValue(PrefixHandleType.Empty);
  479. localName.SetValue(prefixOffset, offset - prefixOffset);
  480. if (anyChar >= 0x80)
  481. {
  482. VerifyNCName(localName.GetString());
  483. }
  484. }
  485. BufferReader.Advance(offset - prefixOffset);
  486. }
  487. int ReadAttributeText(byte[] buffer, int offset, int offsetMax)
  488. {
  489. byte[] charType = XmlUTF8TextReader.charType;
  490. int textOffset = offset;
  491. while (offset < offsetMax && (charType[buffer[offset]] & CharType.AttributeText) != 0)
  492. offset++;
  493. return offset - textOffset;
  494. }
  495. void ReadAttributes()
  496. {
  497. int startOffset = 0;
  498. if (buffered)
  499. startOffset = BufferReader.Offset;
  500. while (true)
  501. {
  502. byte ch;
  503. ReadQualifiedName(prefix, localName);
  504. if (BufferReader.GetByte() != '=')
  505. {
  506. SkipWhitespace();
  507. if (BufferReader.GetByte() != '=')
  508. XmlExceptionHelper.ThrowTokenExpected(this, "=", (char)BufferReader.GetByte());
  509. }
  510. BufferReader.SkipByte();
  511. byte quoteChar = BufferReader.GetByte();
  512. if (quoteChar != '"' && quoteChar != '\'')
  513. {
  514. SkipWhitespace();
  515. quoteChar = BufferReader.GetByte();
  516. if (quoteChar != '"' && quoteChar != '\'')
  517. XmlExceptionHelper.ThrowTokenExpected(this, "\"", (char)BufferReader.GetByte());
  518. }
  519. BufferReader.SkipByte();
  520. bool escaped = false;
  521. int valueOffset = BufferReader.Offset;
  522. while (true)
  523. {
  524. int offset, offsetMax;
  525. byte[] buffer = BufferReader.GetBuffer(out offset, out offsetMax);
  526. int length = ReadAttributeText(buffer, offset, offsetMax);
  527. BufferReader.Advance(length);
  528. ch = BufferReader.GetByte();
  529. if (ch == quoteChar)
  530. break;
  531. if (ch == '&')
  532. {
  533. ReadCharRef();
  534. escaped = true;
  535. }
  536. else if (ch == '\'' || ch == '"')
  537. {
  538. BufferReader.SkipByte();
  539. }
  540. else if (ch == '\n' || ch == '\r' || ch == '\t')
  541. {
  542. BufferReader.SkipByte();
  543. escaped = true;
  544. }
  545. else if (ch == 0xEF)
  546. {
  547. ReadNonFFFE();
  548. }
  549. else
  550. {
  551. XmlExceptionHelper.ThrowTokenExpected(this, ((char)quoteChar).ToString(), (char)ch);
  552. }
  553. }
  554. int valueLength = BufferReader.Offset - valueOffset;
  555. XmlAttributeNode attributeNode;
  556. if (prefix.IsXmlns)
  557. {
  558. Namespace ns = AddNamespace();
  559. localName.ToPrefixHandle(ns.Prefix);
  560. ns.Uri.SetValue(valueOffset, valueLength, escaped);
  561. attributeNode = AddXmlnsAttribute(ns);
  562. }
  563. else if (prefix.IsEmpty && localName.IsXmlns)
  564. {
  565. Namespace ns = AddNamespace();
  566. ns.Prefix.SetValue(PrefixHandleType.Empty);
  567. ns.Uri.SetValue(valueOffset, valueLength, escaped);
  568. attributeNode = AddXmlnsAttribute(ns);
  569. }
  570. else if (prefix.IsXml)
  571. {
  572. attributeNode = AddXmlAttribute();
  573. attributeNode.Prefix.SetValue(prefix);
  574. attributeNode.LocalName.SetValue(localName);
  575. attributeNode.Value.SetValue((escaped ? ValueHandleType.EscapedUTF8 : ValueHandleType.UTF8), valueOffset, valueLength);
  576. FixXmlAttribute(attributeNode);
  577. }
  578. else
  579. {
  580. attributeNode = AddAttribute();
  581. attributeNode.Prefix.SetValue(prefix);
  582. attributeNode.LocalName.SetValue(localName);
  583. attributeNode.Value.SetValue((escaped ? ValueHandleType.EscapedUTF8 : ValueHandleType.UTF8), valueOffset, valueLength);
  584. }
  585. attributeNode.QuoteChar = (char)quoteChar;
  586. BufferReader.SkipByte();
  587. ch = BufferReader.GetByte();
  588. bool space = false;
  589. while ((charType[ch] & CharType.Whitespace) != 0)
  590. {
  591. space = true;
  592. BufferReader.SkipByte();
  593. ch = BufferReader.GetByte();
  594. }
  595. if (ch == '>' || ch == '/' || ch == '?')
  596. break;
  597. if (!space)
  598. XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.GetString(SR.XmlSpaceBetweenAttributes)));
  599. }
  600. if (buffered && (BufferReader.Offset - startOffset) > this.maxBytesPerRead)
  601. XmlExceptionHelper.ThrowMaxBytesPerReadExceeded(this, this.maxBytesPerRead);
  602. ProcessAttributes();
  603. }
  604. void ReadNonFFFE()
  605. {
  606. int off;
  607. byte[] buff = BufferReader.GetBuffer(3, out off);
  608. if (buff[off + 1] == 0xBF && (buff[off + 2] == 0xBE || buff[off + 2] == 0xBF))
  609. {
  610. XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.GetString(SR.XmlInvalidFFFE)));
  611. }
  612. BufferReader.Advance(3);
  613. }
  614. // NOTE: Call only if 0xEF has been seen in the stream AND there are three valid bytes to check (buffer[offset], buffer[offset + 1], buffer[offset + 2]).
  615. // 0xFFFE and 0xFFFF are not valid characters per Unicode specification. The first byte in the UTF8 representation is 0xEF.
  616. bool IsNextCharacterNonFFFE(byte[] buffer, int offset)
  617. {
  618. Fx.Assert(buffer[offset] == 0xEF, "buffer[offset] MUST be 0xEF.");
  619. if (buffer[offset + 1] == 0xBF && (buffer[offset + 2] == 0xBE || buffer[offset + 2] == 0xBF))
  620. {
  621. // 0xFFFE : 0xEF 0xBF 0xBE
  622. // 0xFFFF : 0xEF 0xBF 0xBF
  623. // we know that buffer[offset] is already 0xEF, don't bother checking it.
  624. return false;
  625. }
  626. // no bad characters
  627. return true;
  628. }
  629. void BufferElement()
  630. {
  631. int elementOffset = BufferReader.Offset;
  632. const int byteCount = 128;
  633. bool done = false;
  634. byte quoteChar = 0;
  635. while (!done)
  636. {
  637. int offset;
  638. int offsetMax;
  639. byte[] buffer = BufferReader.GetBuffer(byteCount, out offset, out offsetMax);
  640. if (offset + byteCount != offsetMax)
  641. break;
  642. for (int i = offset; i < offsetMax && !done; i++)
  643. {
  644. byte b = buffer[i];
  645. if (quoteChar == 0)
  646. {
  647. if (b == '\'' || b == '"')
  648. quoteChar = b;
  649. if (b == '>')
  650. done = true;
  651. }
  652. else
  653. {
  654. if (b == quoteChar)
  655. {
  656. quoteChar = 0;
  657. }
  658. }
  659. }
  660. BufferReader.Advance(byteCount);
  661. }
  662. BufferReader.Offset = elementOffset;
  663. }
  664. new void ReadStartElement()
  665. {
  666. if (!buffered)
  667. BufferElement();
  668. XmlElementNode elementNode = EnterScope();
  669. elementNode.NameOffset = BufferReader.Offset;
  670. ReadQualifiedName(elementNode.Prefix, elementNode.LocalName);
  671. elementNode.NameLength = BufferReader.Offset - elementNode.NameOffset;
  672. byte ch = BufferReader.GetByte();
  673. while ((charType[ch] & CharType.Whitespace) != 0)
  674. {
  675. BufferReader.SkipByte();
  676. ch = BufferReader.GetByte();
  677. }
  678. if (ch != '>' && ch != '/')
  679. {
  680. ReadAttributes();
  681. ch = BufferReader.GetByte();
  682. }
  683. elementNode.Namespace = LookupNamespace(elementNode.Prefix);
  684. bool isEmptyElement = false;
  685. if (ch == '/')
  686. {
  687. isEmptyElement = true;
  688. BufferReader.SkipByte();
  689. }
  690. elementNode.IsEmptyElement = isEmptyElement;
  691. elementNode.ExitScope = isEmptyElement;
  692. if (BufferReader.GetByte() != '>')
  693. XmlExceptionHelper.ThrowTokenExpected(this, ">", (char)BufferReader.GetByte());
  694. BufferReader.SkipByte();
  695. elementNode.BufferOffset = BufferReader.Offset;
  696. }
  697. new void ReadEndElement()
  698. {
  699. BufferReader.SkipByte();
  700. XmlElementNode elementNode = this.ElementNode;
  701. int nameOffset = elementNode.NameOffset;
  702. int nameLength = elementNode.NameLength;
  703. int offset;
  704. byte[] buffer = BufferReader.GetBuffer(nameLength, out offset);
  705. for (int i = 0; i < nameLength; i++)
  706. {
  707. if (buffer[offset + i] != buffer[nameOffset + i])
  708. {
  709. ReadQualifiedName(prefix, localName);
  710. XmlExceptionHelper.ThrowTagMismatch(this, elementNode.Prefix.GetString(), elementNode.LocalName.GetString(), prefix.GetString(), localName.GetString());
  711. }
  712. }
  713. BufferReader.Advance(nameLength);
  714. if (BufferReader.GetByte() != '>')
  715. {
  716. SkipWhitespace();
  717. if (BufferReader.GetByte() != '>')
  718. XmlExceptionHelper.ThrowTokenExpected(this, ">", (char)BufferReader.GetByte());
  719. }
  720. BufferReader.SkipByte();
  721. MoveToEndElement();
  722. }
  723. void ReadComment()
  724. {
  725. BufferReader.SkipByte();
  726. if (BufferReader.GetByte() != '-')
  727. XmlExceptionHelper.ThrowTokenExpected(this, "--", (char)BufferReader.GetByte());
  728. BufferReader.SkipByte();
  729. int commentOffset = BufferReader.Offset;
  730. while (true)
  731. {
  732. while (true)
  733. {
  734. byte b = BufferReader.GetByte();
  735. if (b == '-')
  736. break;
  737. if ((charType[b] & CharType.Comment) == 0)
  738. {
  739. if (b == 0xEF)
  740. ReadNonFFFE();
  741. else
  742. XmlExceptionHelper.ThrowInvalidXml(this, b);
  743. }
  744. else
  745. {
  746. BufferReader.SkipByte();
  747. }
  748. }
  749. int offset;
  750. byte[] buffer = BufferReader.GetBuffer(3, out offset);
  751. if (buffer[offset + 0] == (byte)'-' &&
  752. buffer[offset + 1] == (byte)'-')
  753. {
  754. if (buffer[offset + 2] == (byte)'>')
  755. break;
  756. XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.GetString(SR.XmlInvalidCommentChars)));
  757. }
  758. BufferReader.SkipByte();
  759. }
  760. int commentLength = BufferReader.Offset - commentOffset;
  761. MoveToComment().Value.SetValue(ValueHandleType.UTF8, commentOffset, commentLength);
  762. BufferReader.Advance(3);
  763. }
  764. void ReadCData()
  765. {
  766. int offset;
  767. byte[] buffer = BufferReader.GetBuffer(7, out offset);
  768. if (buffer[offset + 0] != (byte)'[' ||
  769. buffer[offset + 1] != (byte)'C' ||
  770. buffer[offset + 2] != (byte)'D' ||
  771. buffer[offset + 3] != (byte)'A' ||
  772. buffer[offset + 4] != (byte)'T' ||
  773. buffer[offset + 5] != (byte)'A' ||
  774. buffer[offset + 6] != (byte)'[')
  775. {
  776. XmlExceptionHelper.ThrowTokenExpected(this, "[CDATA[", Encoding.UTF8.GetString(buffer, offset, 7));
  777. }
  778. BufferReader.Advance(7);
  779. int cdataOffset = BufferReader.Offset;
  780. while (true)
  781. {
  782. byte b;
  783. while (true)
  784. {
  785. b = BufferReader.GetByte();
  786. if (b == ']')
  787. break;
  788. if (b == 0xEF)
  789. ReadNonFFFE();
  790. else
  791. BufferReader.SkipByte();
  792. }
  793. buffer = BufferReader.GetBuffer(3, out offset);
  794. if (buffer[offset + 0] == (byte)']' &&
  795. buffer[offset + 1] == (byte)']' &&
  796. buffer[offset + 2] == (byte)'>')
  797. break;
  798. BufferReader.SkipByte();
  799. }
  800. int cdataLength = BufferReader.Offset - cdataOffset;
  801. MoveToCData().Value.SetValue(ValueHandleType.UTF8, cdataOffset, cdataLength);
  802. BufferReader.Advance(3);
  803. }
  804. int ReadCharRef()
  805. {
  806. Fx.Assert(BufferReader.GetByte() == '&', "");
  807. int charEntityOffset = BufferReader.Offset;
  808. BufferReader.SkipByte();
  809. while (BufferReader.GetByte() != ';')
  810. BufferReader.SkipByte();
  811. BufferReader.SkipByte();
  812. int charEntityLength = BufferReader.Offset - charEntityOffset;
  813. BufferReader.Offset = charEntityOffset;
  814. int ch = BufferReader.GetCharEntity(charEntityOffset, charEntityLength);
  815. BufferReader.Advance(charEntityLength);
  816. return ch;
  817. }
  818. void ReadWhitespace()
  819. {
  820. byte[] buffer;
  821. int offset;
  822. int offsetMax;
  823. int length;
  824. if (buffered)
  825. {
  826. buffer = BufferReader.GetBuffer(out offset, out offsetMax);
  827. length = ReadWhitespace(buffer, offset, offsetMax);
  828. }
  829. else
  830. {
  831. buffer = BufferReader.GetBuffer(MaxTextChunk, out offset, out offsetMax);
  832. length = ReadWhitespace(buffer, offset, offsetMax);
  833. length = BreakText(buffer, offset, length);
  834. }
  835. BufferReader.Advance(length);
  836. MoveToWhitespaceText().Value.SetValue(ValueHandleType.UTF8, offset, length);
  837. }
  838. int ReadWhitespace(byte[] buffer, int offset, int offsetMax)
  839. {
  840. byte[] charType = XmlUTF8TextReader.charType;
  841. int wsOffset = offset;
  842. while (offset < offsetMax && (charType[buffer[offset]] & CharType.SpecialWhitespace) != 0)
  843. offset++;
  844. return offset - wsOffset;
  845. }
  846. int ReadText(byte[] buffer, int offset, int offsetMax)
  847. {
  848. byte[] charType = XmlUTF8TextReader.charType;
  849. int textOffset = offset;
  850. while (offset < offsetMax && (charType[buffer[offset]] & CharType.Text) != 0)
  851. offset++;
  852. return offset - textOffset;
  853. }
  854. // Read Unicode codepoints 0xFvvv
  855. int ReadTextAndWatchForInvalidCharacters(byte[] buffer, int offset, int offsetMax)
  856. {
  857. byte[] charType = XmlUTF8TextReader.charType;
  858. int textOffset = offset;
  859. while (offset < offsetMax && ((charType[buffer[offset]] & CharType.Text) != 0 || buffer[offset] == 0xEF))
  860. {
  861. if (buffer[offset] != 0xEF)
  862. {
  863. offset++;
  864. }
  865. else
  866. {
  867. // Ensure that we have three bytes (buffer[offset], buffer[offset + 1], buffer[offset + 2])
  868. // available for IsNextCharacterNonFFFE to check.
  869. if (offset + 2 < offsetMax)
  870. {
  871. if (IsNextCharacterNonFFFE(buffer, offset))
  872. {
  873. // if first byte is 0xEF, UTF8 mandates a 3-byte character representation of this Unicode code point
  874. offset += 3;
  875. }
  876. else
  877. {
  878. XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.GetString(SR.XmlInvalidFFFE)));
  879. }
  880. }
  881. else
  882. {
  883. if (BufferReader.Offset < offset)
  884. {
  885. // We have read some characters already
  886. // Let the outer ReadText advance the bufferReader and return text node to caller
  887. break;
  888. }
  889. else
  890. {
  891. // Get enough bytes for us to process next character, then go back to top of while loop
  892. int dummy;
  893. BufferReader.GetBuffer(3, out dummy);
  894. }
  895. }
  896. }
  897. }
  898. return offset - textOffset;
  899. }
  900. // bytes bits UTF-8 representation
  901. // ----- ---- -----------------------------------
  902. // 1 7 0vvvvvvv
  903. // 2 11 110vvvvv 10vvvvvv
  904. // 3 16 1110vvvv 10vvvvvv 10vvvvvv
  905. // 4 21 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv
  906. // ----- ---- -----------------------------------
  907. int BreakText(byte[] buffer, int offset, int length)
  908. {
  909. // See if we might be breaking a utf8 sequence
  910. if (length > 0 && (buffer[offset + length - 1] & 0x80) == 0x80)
  911. {
  912. // Find the lead char of the utf8 sequence (0x11xxxxxx)
  913. int originalLength = length;
  914. do
  915. {
  916. length--;
  917. }
  918. while (length > 0 && (buffer[offset + length] & 0xC0) != 0xC0);
  919. // Couldn't find the lead char
  920. if (length == 0)
  921. return originalLength; // Invalid utf8 sequence - can't break
  922. // Count how many bytes follow the lead char
  923. byte b = (byte)(buffer[offset + length] << 2);
  924. int byteCount = 2;
  925. while ((b & 0x80) == 0x80)
  926. {
  927. b = (byte)(b << 1);
  928. byteCount++;
  929. // There shouldn't be more than 3 bytes following the lead char
  930. if (byteCount > 4)
  931. return originalLength; // Invalid utf8 sequence - can't break
  932. }
  933. if (length + byteCount == originalLength)
  934. return originalLength; // sequence fits exactly
  935. if (length == 0)
  936. return originalLength; // Quota too small to read a char
  937. }
  938. return length;
  939. }
  940. void ReadText(bool hasLeadingByteOf0xEF)
  941. {
  942. byte[] buffer;
  943. int offset;
  944. int offsetMax;
  945. int length;
  946. if (buffered)
  947. {
  948. buffer = BufferReader.GetBuffer(out offset, out offsetMax);
  949. if (hasLeadingByteOf0xEF)
  950. {
  951. length = ReadTextAndWatchForInvalidCharacters(buffer, offset, offsetMax);
  952. }
  953. else
  954. {
  955. length = ReadText(buffer, offset, offsetMax);
  956. }
  957. }
  958. else
  959. {
  960. buffer = BufferReader.GetBuffer(MaxTextChunk, out offset, out offsetMax);
  961. if (hasLeadingByteOf0xEF)
  962. {
  963. length = ReadTextAndWatchForInvalidCharacters(buffer, offset, offsetMax);
  964. }
  965. else
  966. {
  967. length = ReadText(buffer, offset, offsetMax);
  968. }
  969. length = BreakText(buffer, offset, length);
  970. }
  971. BufferReader.Advance(length);
  972. if (offset < offsetMax - 1 - length && (buffer[offset + length] == (byte)'<' && buffer[offset + length + 1] != (byte)'!'))
  973. {
  974. MoveToAtomicText().Value.SetValue(ValueHandleType.UTF8, offset, length);
  975. }
  976. else
  977. {
  978. MoveToComplexText().Value.SetValue(ValueHandleType.UTF8, offset, length);
  979. }
  980. }
  981. void ReadEscapedText()
  982. {
  983. int ch = ReadCharRef();
  984. if (ch < 256 && (charType[ch] & CharType.Whitespace) != 0)
  985. MoveToWhitespaceText().Value.SetCharValue(ch);
  986. else
  987. MoveToComplexText().Value.SetCharValue(ch);
  988. }
  989. public override bool Read()
  990. {
  991. if (this.Node.ReadState == ReadState.Closed)
  992. return false;
  993. if (this.Node.CanMoveToElement)
  994. {
  995. // If we're positioned on an attribute or attribute text on an empty element, we need to move back
  996. // to the element in order to get the correct setting of ExitScope
  997. MoveToElement();
  998. }
  999. SignNode();
  1000. if (this.Node.ExitScope)
  1001. {
  1002. ExitScope();
  1003. }
  1004. if (!buffered)
  1005. BufferReader.SetWindow(ElementNode.BufferOffset, this.maxBytesPerRead);
  1006. if (BufferReader.EndOfFile)
  1007. {
  1008. MoveToEndOfFile();
  1009. return false;
  1010. }
  1011. byte ch = BufferReader.GetByte();
  1012. if (ch == (byte)'<')
  1013. {
  1014. BufferReader.SkipByte();
  1015. ch = BufferReader.GetByte();
  1016. if (ch == (byte)'/')
  1017. ReadEndElement();
  1018. else if (ch == (byte)'!')
  1019. {
  1020. BufferReader.SkipByte();
  1021. ch = BufferReader.GetByte();
  1022. if (ch == '-')
  1023. {
  1024. ReadComment();
  1025. }
  1026. else
  1027. {
  1028. if (OutsideRootElement)
  1029. XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.GetString(SR.XmlCDATAInvalidAtTopLevel)));
  1030. ReadCData();
  1031. }
  1032. }
  1033. else if (ch == (byte)'?')
  1034. ReadDeclaration();
  1035. else
  1036. ReadStartElement();
  1037. }
  1038. else if ((charType[ch] & CharType.SpecialWhitespace) != 0)
  1039. {
  1040. ReadWhitespace();
  1041. }
  1042. else if (OutsideRootElement && ch != '\r')
  1043. {
  1044. XmlExceptionHelper.ThrowInvalidRootData(this);
  1045. }
  1046. else if ((charType[ch] & CharType.Text) != 0)
  1047. {
  1048. ReadText(false);
  1049. }
  1050. else if (ch == '&')
  1051. {
  1052. ReadEscapedText();
  1053. }
  1054. else if (ch == '\r')
  1055. {
  1056. BufferReader.SkipByte();
  1057. if (!BufferReader.EndOfFile && BufferReader.GetByte() == '\n')
  1058. ReadWhitespace();
  1059. else
  1060. MoveToComplexText().Value.SetCharValue('\n');
  1061. }
  1062. else if (ch == ']')
  1063. {
  1064. int offset;
  1065. byte[] buffer = BufferReader.GetBuffer(3, out offset);
  1066. if (buffer[offset + 0] == (byte)']' &&
  1067. buffer[offset + 1] == (byte)']' &&
  1068. buffer[offset + 2] == (byte)'>')
  1069. {
  1070. XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.GetString(SR.XmlCloseCData)));
  1071. }
  1072. BufferReader.SkipByte();
  1073. MoveToComplexText().Value.SetCharValue(']'); // Need to get past the ']' and keep going.
  1074. }
  1075. else if (ch == 0xEF) // Watch for invalid characters 0xfffe and 0xffff
  1076. {
  1077. ReadText(true);
  1078. }
  1079. else
  1080. {
  1081. XmlExceptionHelper.ThrowInvalidXml(this, ch);
  1082. }
  1083. return true;
  1084. }
  1085. protected override XmlSigningNodeWriter CreateSigningNodeWriter()
  1086. {
  1087. return new XmlSigningNodeWriter(true);
  1088. }
  1089. public bool HasLineInfo()
  1090. {
  1091. return true;
  1092. }
  1093. public int LineNumber
  1094. {
  1095. get
  1096. {
  1097. int row, column;
  1098. GetPosition(out row, out column);
  1099. return row;
  1100. }
  1101. }
  1102. public int LinePosition
  1103. {
  1104. get
  1105. {
  1106. int row, column;
  1107. GetPosition(out row, out column);
  1108. return column;
  1109. }
  1110. }
  1111. void GetPosition(out int row, out int column)
  1112. {
  1113. if (rowOffsets == null)
  1114. {
  1115. rowOffsets = BufferReader.GetRows();
  1116. }
  1117. int offset = BufferReader.Offset;
  1118. int j = 0;
  1119. while (j < rowOffsets.Length - 1 && rowOffsets[j + 1] < offset)
  1120. j++;
  1121. row = j + 1;
  1122. column = offset - rowOffsets[j] + 1;
  1123. }
  1124. static class CharType
  1125. {
  1126. public const byte None = 0x00;
  1127. public const byte FirstName = 0x01;
  1128. public const byte Name = 0x02;
  1129. public const byte Whitespace = 0x04;
  1130. public const byte Text = 0x08;
  1131. public const byte AttributeText = 0x10;
  1132. public const byte SpecialWhitespace = 0x20;
  1133. public const byte Comment = 0x40;
  1134. #if GENERATE_CHARTYPE
  1135. static public void Generate()
  1136. {
  1137. bool[] isFirstNameChar = new bool[256];
  1138. bool[] isNameChar = new bool[256];
  1139. bool[] isSpaceChar = new bool[256];
  1140. bool[] isSpecialSpaceChar = new bool[256];
  1141. bool[] isTextChar = new bool[256];
  1142. bool[] isAttributeTextChar = new bool[256];
  1143. for (int i = 0; i < 256; i++)
  1144. {
  1145. isFirstNameChar[i] = false;
  1146. isNameChar[i] = false;
  1147. isSpaceChar[i] = false;
  1148. isTextChar[i] = false;
  1149. isSpecialSpaceChar[i] = false;
  1150. }
  1151. for (int i = 'A'; i <= 'Z'; i++)
  1152. {
  1153. isFirstNameChar[i] = true;
  1154. isFirstNameChar[i + 32] = true;
  1155. }
  1156. isFirstNameChar['_'] = true;
  1157. // Allow utf8 chars as the first char
  1158. for (int i = 128; i < 256; i++)
  1159. {
  1160. isFirstNameChar[i] = true;
  1161. }
  1162. for (int i = 'A'; i <= 'Z'; i++)
  1163. {
  1164. isNameChar[i] = true;
  1165. isNameChar[i + 32] = true;
  1166. }
  1167. for (int i = '0'; i <= '9'; i++)
  1168. isNameChar[i] = true;
  1169. isNameChar['_'] = true;
  1170. isNameChar['.'] = true;
  1171. isNameChar['-'] = true;
  1172. for (int i = 128; i < 256; i++)
  1173. {
  1174. isNameChar[i] = true;
  1175. }
  1176. isSpaceChar[' '] = true;
  1177. isSpaceChar[0x09] = true;
  1178. isSpaceChar[0x0D] = true;
  1179. isSpaceChar[0x0A] = true;
  1180. isSpecialSpaceChar[' '] = true;
  1181. isSpecialSpaceChar[0x09] = true;
  1182. isSpecialSpaceChar[0x0A] = true;
  1183. for (int i = 32; i < 128; i++)
  1184. isTextChar[i] = true;
  1185. isTextChar[0x09] = true;
  1186. isTextChar[0x0D] = false;
  1187. isTextChar[0x0A] = true;
  1188. isTextChar['<'] = false;
  1189. isTextChar['&'] = false;
  1190. isTextChar[']'] = false;
  1191. for (int i = 128; i < 256; i++)
  1192. isTextChar[i] = true;
  1193. for (int i = 0; i < 256; i++)
  1194. {
  1195. isAttributeTextChar[i] = isTextChar[i];
  1196. }
  1197. isAttributeTextChar[0x09] = false;
  1198. isAttributeTextChar[0x0D] = false;
  1199. isAttributeTextChar[0x0A] = false;
  1200. isAttributeTextChar[']'] = true;
  1201. isAttributeTextChar['\''] = false;
  1202. isAttributeTextChar['"'] = false;
  1203. for (int i = 0; i < 256; i++)
  1204. {
  1205. Console.Write(" /* {0,2:X} ({1}) */ CharType.None", i, char.IsControl((char)i) ? '.' : (char)i);
  1206. if (isFirstNameChar[i])
  1207. Console.Write("|CharType.FirstName");
  1208. if (isNameChar[i])
  1209. Console.Write("|CharType.Name");
  1210. if (isSpaceChar[i])
  1211. Console.Write("|CharType.Whitespace");
  1212. if (isTextChar[i])
  1213. Console.Write("|CharType.Text");
  1214. if (isAttributeTextChar[i])
  1215. Console.Write("|CharType.AttributeText");
  1216. if (isSpecialSpaceChar[i])
  1217. Console.Write("|CharType.SpecialWhitespace");
  1218. Console.WriteLine(",");
  1219. }
  1220. }
  1221. #endif
  1222. }
  1223. }
  1224. }