2
0

HttpEncoder.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. //
  2. // Authors:
  3. // Patrik Torstensson ([email protected])
  4. // Wictor Wilén (decode/encode functions) ([email protected])
  5. // Tim Coleman ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. // Marek Habersack <[email protected]>
  8. //
  9. // (C) 2005-2010 Novell, Inc (http://novell.com/)
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Collections.Generic;
  33. using System.Configuration;
  34. using System.IO;
  35. using System.Text;
  36. #if NET_4_0
  37. using System.Web.Configuration;
  38. #endif
  39. namespace System.Web.Util
  40. {
  41. #if NET_4_0
  42. public
  43. #endif
  44. class HttpEncoder
  45. {
  46. static char [] hexChars = "0123456789abcdef".ToCharArray ();
  47. static object entitiesLock = new object ();
  48. static SortedDictionary <string, char> entities;
  49. #if NET_4_0
  50. static Lazy <HttpEncoder> defaultEncoder;
  51. static Lazy <HttpEncoder> currentEncoderLazy;
  52. #else
  53. static HttpEncoder defaultEncoder;
  54. #endif
  55. static HttpEncoder currentEncoder;
  56. static IDictionary <string, char> Entities {
  57. get {
  58. lock (entitiesLock) {
  59. if (entities == null)
  60. InitEntities ();
  61. return entities;
  62. }
  63. }
  64. }
  65. public static HttpEncoder Current {
  66. get {
  67. #if NET_4_0
  68. if (currentEncoder == null)
  69. currentEncoder = currentEncoderLazy.Value;
  70. #endif
  71. return currentEncoder;
  72. }
  73. #if NET_4_0
  74. set {
  75. if (value == null)
  76. throw new ArgumentNullException ("value");
  77. currentEncoder = value;
  78. }
  79. #endif
  80. }
  81. public static HttpEncoder Default {
  82. get {
  83. #if NET_4_0
  84. return defaultEncoder.Value;
  85. #else
  86. return defaultEncoder;
  87. #endif
  88. }
  89. }
  90. static HttpEncoder ()
  91. {
  92. #if NET_4_0
  93. defaultEncoder = new Lazy <HttpEncoder> (() => new HttpEncoder ());
  94. currentEncoderLazy = new Lazy <HttpEncoder> (new Func <HttpEncoder> (GetCustomEncoderFromConfig));
  95. #else
  96. defaultEncoder = new HttpEncoder ();
  97. currentEncoder = defaultEncoder;
  98. #endif
  99. }
  100. public HttpEncoder ()
  101. {
  102. }
  103. #if NET_4_0
  104. protected internal virtual
  105. #else
  106. internal static
  107. #endif
  108. void HeaderNameValueEncode (string headerName, string headerValue, out string encodedHeaderName, out string encodedHeaderValue)
  109. {
  110. if (String.IsNullOrEmpty (headerName))
  111. encodedHeaderName = headerName;
  112. else
  113. encodedHeaderName = EncodeHeaderString (headerName);
  114. if (String.IsNullOrEmpty (headerValue))
  115. encodedHeaderValue = headerValue;
  116. else
  117. encodedHeaderValue = EncodeHeaderString (headerValue);
  118. }
  119. static void StringBuilderAppend (string s, ref StringBuilder sb)
  120. {
  121. if (sb == null)
  122. sb = new StringBuilder (s);
  123. else
  124. sb.Append (s);
  125. }
  126. static string EncodeHeaderString (string input)
  127. {
  128. StringBuilder sb = null;
  129. char ch;
  130. for (int i = 0; i < input.Length; i++) {
  131. ch = input [i];
  132. if ((ch < 32 && ch != 9) || ch == 127)
  133. StringBuilderAppend (String.Format ("%{0:x2}", (int)ch), ref sb);
  134. }
  135. if (sb != null)
  136. return sb.ToString ();
  137. return input;
  138. }
  139. #if NET_4_0
  140. protected internal virtual void HtmlAttributeEncode (string value, TextWriter output)
  141. {
  142. if (output == null)
  143. throw new ArgumentNullException ("output");
  144. if (String.IsNullOrEmpty (value))
  145. return;
  146. output.Write (HtmlAttributeEncode (value));
  147. }
  148. protected internal virtual void HtmlDecode (string value, TextWriter output)
  149. {
  150. if (output == null)
  151. throw new ArgumentNullException ("output");
  152. output.Write (HtmlDecode (value));
  153. }
  154. protected internal virtual void HtmlEncode (string value, TextWriter output)
  155. {
  156. if (output == null)
  157. throw new ArgumentNullException ("output");
  158. output.Write (HtmlEncode (value));
  159. }
  160. protected internal virtual byte[] UrlEncode (byte[] bytes, int offset, int count)
  161. {
  162. return UrlEncodeToBytes (bytes, offset, count);
  163. }
  164. static HttpEncoder GetCustomEncoderFromConfig ()
  165. {
  166. var cfg = WebConfigurationManager.GetSection ("system.web/httpRuntime") as HttpRuntimeSection;
  167. string typeName = cfg.EncoderType;
  168. if (String.Compare (typeName, "System.Web.Util.HttpEncoder", StringComparison.OrdinalIgnoreCase) == 0)
  169. return Default;
  170. Type t = Type.GetType (typeName, false);
  171. if (t == null)
  172. throw new ConfigurationErrorsException (String.Format ("Could not load type '{0}'.", typeName));
  173. if (!typeof (HttpEncoder).IsAssignableFrom (t))
  174. throw new ConfigurationErrorsException (
  175. String.Format ("'{0}' is not allowed here because it does not extend class 'System.Web.Util.HttpEncoder'.", typeName)
  176. );
  177. return Activator.CreateInstance (t, false) as HttpEncoder;
  178. }
  179. #endif
  180. #if NET_4_0
  181. protected internal virtual
  182. #else
  183. internal static
  184. #endif
  185. string UrlPathEncode (string value)
  186. {
  187. if (String.IsNullOrEmpty (value))
  188. return value;
  189. MemoryStream result = new MemoryStream ();
  190. int length = value.Length;
  191. for (int i = 0; i < length; i++)
  192. UrlPathEncodeChar (value [i], result);
  193. return Encoding.ASCII.GetString (result.ToArray ());
  194. }
  195. internal static byte[] UrlEncodeToBytes (byte[] bytes, int offset, int count)
  196. {
  197. if (bytes == null)
  198. throw new ArgumentNullException ("bytes");
  199. int blen = bytes.Length;
  200. if (blen == 0)
  201. return new byte [0];
  202. if (offset < 0 || offset >= blen)
  203. throw new ArgumentOutOfRangeException("offset");
  204. if (count < 0 || count > blen - offset)
  205. throw new ArgumentOutOfRangeException("count");
  206. MemoryStream result = new MemoryStream (count);
  207. int end = offset + count;
  208. for (int i = offset; i < end; i++)
  209. UrlEncodeChar ((char)bytes [i], result, false);
  210. return result.ToArray();
  211. }
  212. internal static string HtmlEncode (string s)
  213. {
  214. if (s == null)
  215. return null;
  216. if (s.Length == 0)
  217. return String.Empty;
  218. bool needEncode = false;
  219. for (int i = 0; i < s.Length; i++) {
  220. char c = s [i];
  221. if (c == '&' || c == '"' || c == '<' || c == '>' || c > 159
  222. #if NET_4_0
  223. || c == '\''
  224. #endif
  225. ) {
  226. needEncode = true;
  227. break;
  228. }
  229. }
  230. if (!needEncode)
  231. return s;
  232. StringBuilder output = new StringBuilder ();
  233. char ch;
  234. int len = s.Length;
  235. for (int i = 0; i < len; i++) {
  236. switch (s [i]) {
  237. case '&' :
  238. output.Append ("&amp;");
  239. break;
  240. case '>' :
  241. output.Append ("&gt;");
  242. break;
  243. case '<' :
  244. output.Append ("&lt;");
  245. break;
  246. case '"' :
  247. output.Append ("&quot;");
  248. break;
  249. #if NET_4_0
  250. case '\'':
  251. output.Append ("&#39;");
  252. break;
  253. #endif
  254. case '\uff1c':
  255. output.Append ("&#65308;");
  256. break;
  257. case '\uff1e':
  258. output.Append ("&#65310;");
  259. break;
  260. default:
  261. ch = s [i];
  262. if (ch > 159 && ch < 256) {
  263. output.Append ("&#");
  264. output.Append (((int) ch).ToString (Helpers.InvariantCulture));
  265. output.Append (";");
  266. } else
  267. output.Append (ch);
  268. break;
  269. }
  270. }
  271. return output.ToString ();
  272. }
  273. internal static string HtmlAttributeEncode (string s)
  274. {
  275. #if NET_4_0
  276. if (String.IsNullOrEmpty (s))
  277. return String.Empty;
  278. #else
  279. if (s == null)
  280. return null;
  281. if (s.Length == 0)
  282. return String.Empty;
  283. #endif
  284. bool needEncode = false;
  285. for (int i = 0; i < s.Length; i++) {
  286. char c = s [i];
  287. if (c == '&' || c == '"' || c == '<'
  288. #if NET_4_0
  289. || c == '\''
  290. #endif
  291. ) {
  292. needEncode = true;
  293. break;
  294. }
  295. }
  296. if (!needEncode)
  297. return s;
  298. StringBuilder output = new StringBuilder ();
  299. int len = s.Length;
  300. for (int i = 0; i < len; i++)
  301. switch (s [i]) {
  302. case '&' :
  303. output.Append ("&amp;");
  304. break;
  305. case '"' :
  306. output.Append ("&quot;");
  307. break;
  308. case '<':
  309. output.Append ("&lt;");
  310. break;
  311. #if NET_4_0
  312. case '\'':
  313. output.Append ("&#39;");
  314. break;
  315. #endif
  316. default:
  317. output.Append (s [i]);
  318. break;
  319. }
  320. return output.ToString();
  321. }
  322. internal static string HtmlDecode (string s)
  323. {
  324. if (s == null)
  325. return null;
  326. if (s.Length == 0)
  327. return String.Empty;
  328. if (s.IndexOf ('&') == -1)
  329. return s;
  330. #if NET_4_0
  331. StringBuilder rawEntity = new StringBuilder ();
  332. #endif
  333. StringBuilder entity = new StringBuilder ();
  334. StringBuilder output = new StringBuilder ();
  335. int len = s.Length;
  336. // 0 -> nothing,
  337. // 1 -> right after '&'
  338. // 2 -> between '&' and ';' but no '#'
  339. // 3 -> '#' found after '&' and getting numbers
  340. int state = 0;
  341. int number = 0;
  342. bool is_hex_value = false;
  343. bool have_trailing_digits = false;
  344. for (int i = 0; i < len; i++) {
  345. char c = s [i];
  346. if (state == 0) {
  347. if (c == '&') {
  348. entity.Append (c);
  349. #if NET_4_0
  350. rawEntity.Append (c);
  351. #endif
  352. state = 1;
  353. } else {
  354. output.Append (c);
  355. }
  356. continue;
  357. }
  358. if (c == '&') {
  359. state = 1;
  360. if (have_trailing_digits) {
  361. entity.Append (number.ToString (Helpers.InvariantCulture));
  362. have_trailing_digits = false;
  363. }
  364. output.Append (entity.ToString ());
  365. entity.Length = 0;
  366. entity.Append ('&');
  367. continue;
  368. }
  369. if (state == 1) {
  370. if (c == ';') {
  371. state = 0;
  372. output.Append (entity.ToString ());
  373. output.Append (c);
  374. entity.Length = 0;
  375. } else {
  376. number = 0;
  377. is_hex_value = false;
  378. if (c != '#') {
  379. state = 2;
  380. } else {
  381. state = 3;
  382. }
  383. entity.Append (c);
  384. #if NET_4_0
  385. rawEntity.Append (c);
  386. #endif
  387. }
  388. } else if (state == 2) {
  389. entity.Append (c);
  390. if (c == ';') {
  391. string key = entity.ToString ();
  392. if (key.Length > 1 && Entities.ContainsKey (key.Substring (1, key.Length - 2)))
  393. key = Entities [key.Substring (1, key.Length - 2)].ToString ();
  394. output.Append (key);
  395. state = 0;
  396. entity.Length = 0;
  397. #if NET_4_0
  398. rawEntity.Length = 0;
  399. #endif
  400. }
  401. } else if (state == 3) {
  402. if (c == ';') {
  403. #if NET_4_0
  404. if (number == 0)
  405. output.Append (rawEntity.ToString () + ";");
  406. else
  407. #endif
  408. if (number > 65535) {
  409. output.Append ("&#");
  410. output.Append (number.ToString (Helpers.InvariantCulture));
  411. output.Append (";");
  412. } else {
  413. output.Append ((char) number);
  414. }
  415. state = 0;
  416. entity.Length = 0;
  417. #if NET_4_0
  418. rawEntity.Length = 0;
  419. #endif
  420. have_trailing_digits = false;
  421. } else if (is_hex_value && Uri.IsHexDigit(c)) {
  422. number = number * 16 + Uri.FromHex(c);
  423. have_trailing_digits = true;
  424. #if NET_4_0
  425. rawEntity.Append (c);
  426. #endif
  427. } else if (Char.IsDigit (c)) {
  428. number = number * 10 + ((int) c - '0');
  429. have_trailing_digits = true;
  430. #if NET_4_0
  431. rawEntity.Append (c);
  432. #endif
  433. } else if (number == 0 && (c == 'x' || c == 'X')) {
  434. is_hex_value = true;
  435. #if NET_4_0
  436. rawEntity.Append (c);
  437. #endif
  438. } else {
  439. state = 2;
  440. if (have_trailing_digits) {
  441. entity.Append (number.ToString (Helpers.InvariantCulture));
  442. have_trailing_digits = false;
  443. }
  444. entity.Append (c);
  445. }
  446. }
  447. }
  448. if (entity.Length > 0) {
  449. output.Append (entity.ToString ());
  450. } else if (have_trailing_digits) {
  451. output.Append (number.ToString (Helpers.InvariantCulture));
  452. }
  453. return output.ToString ();
  454. }
  455. internal static bool NotEncoded (char c)
  456. {
  457. return (c == '!' || c == '(' || c == ')' || c == '*' || c == '-' || c == '.' || c == '_'
  458. #if !NET_4_0
  459. || c == '\''
  460. #endif
  461. );
  462. }
  463. internal static void UrlEncodeChar (char c, Stream result, bool isUnicode) {
  464. if (c > 255) {
  465. //FIXME: what happens when there is an internal error?
  466. //if (!isUnicode)
  467. // throw new ArgumentOutOfRangeException ("c", c, "c must be less than 256");
  468. int idx;
  469. int i = (int) c;
  470. result.WriteByte ((byte)'%');
  471. result.WriteByte ((byte)'u');
  472. idx = i >> 12;
  473. result.WriteByte ((byte)hexChars [idx]);
  474. idx = (i >> 8) & 0x0F;
  475. result.WriteByte ((byte)hexChars [idx]);
  476. idx = (i >> 4) & 0x0F;
  477. result.WriteByte ((byte)hexChars [idx]);
  478. idx = i & 0x0F;
  479. result.WriteByte ((byte)hexChars [idx]);
  480. return;
  481. }
  482. if (c > ' ' && NotEncoded (c)) {
  483. result.WriteByte ((byte)c);
  484. return;
  485. }
  486. if (c==' ') {
  487. result.WriteByte ((byte)'+');
  488. return;
  489. }
  490. if ( (c < '0') ||
  491. (c < 'A' && c > '9') ||
  492. (c > 'Z' && c < 'a') ||
  493. (c > 'z')) {
  494. if (isUnicode && c > 127) {
  495. result.WriteByte ((byte)'%');
  496. result.WriteByte ((byte)'u');
  497. result.WriteByte ((byte)'0');
  498. result.WriteByte ((byte)'0');
  499. }
  500. else
  501. result.WriteByte ((byte)'%');
  502. int idx = ((int) c) >> 4;
  503. result.WriteByte ((byte)hexChars [idx]);
  504. idx = ((int) c) & 0x0F;
  505. result.WriteByte ((byte)hexChars [idx]);
  506. }
  507. else
  508. result.WriteByte ((byte)c);
  509. }
  510. internal static void UrlPathEncodeChar (char c, Stream result)
  511. {
  512. if (c < 33 || c > 126) {
  513. byte [] bIn = Encoding.UTF8.GetBytes (c.ToString ());
  514. for (int i = 0; i < bIn.Length; i++) {
  515. result.WriteByte ((byte) '%');
  516. int idx = ((int) bIn [i]) >> 4;
  517. result.WriteByte ((byte) hexChars [idx]);
  518. idx = ((int) bIn [i]) & 0x0F;
  519. result.WriteByte ((byte) hexChars [idx]);
  520. }
  521. }
  522. else if (c == ' ') {
  523. result.WriteByte ((byte) '%');
  524. result.WriteByte ((byte) '2');
  525. result.WriteByte ((byte) '0');
  526. }
  527. else
  528. result.WriteByte ((byte) c);
  529. }
  530. static void InitEntities ()
  531. {
  532. // Build the hash table of HTML entity references. This list comes
  533. // from the HTML 4.01 W3C recommendation.
  534. entities = new SortedDictionary <string, char> (StringComparer.Ordinal);
  535. entities.Add ("nbsp", '\u00A0');
  536. entities.Add ("iexcl", '\u00A1');
  537. entities.Add ("cent", '\u00A2');
  538. entities.Add ("pound", '\u00A3');
  539. entities.Add ("curren", '\u00A4');
  540. entities.Add ("yen", '\u00A5');
  541. entities.Add ("brvbar", '\u00A6');
  542. entities.Add ("sect", '\u00A7');
  543. entities.Add ("uml", '\u00A8');
  544. entities.Add ("copy", '\u00A9');
  545. entities.Add ("ordf", '\u00AA');
  546. entities.Add ("laquo", '\u00AB');
  547. entities.Add ("not", '\u00AC');
  548. entities.Add ("shy", '\u00AD');
  549. entities.Add ("reg", '\u00AE');
  550. entities.Add ("macr", '\u00AF');
  551. entities.Add ("deg", '\u00B0');
  552. entities.Add ("plusmn", '\u00B1');
  553. entities.Add ("sup2", '\u00B2');
  554. entities.Add ("sup3", '\u00B3');
  555. entities.Add ("acute", '\u00B4');
  556. entities.Add ("micro", '\u00B5');
  557. entities.Add ("para", '\u00B6');
  558. entities.Add ("middot", '\u00B7');
  559. entities.Add ("cedil", '\u00B8');
  560. entities.Add ("sup1", '\u00B9');
  561. entities.Add ("ordm", '\u00BA');
  562. entities.Add ("raquo", '\u00BB');
  563. entities.Add ("frac14", '\u00BC');
  564. entities.Add ("frac12", '\u00BD');
  565. entities.Add ("frac34", '\u00BE');
  566. entities.Add ("iquest", '\u00BF');
  567. entities.Add ("Agrave", '\u00C0');
  568. entities.Add ("Aacute", '\u00C1');
  569. entities.Add ("Acirc", '\u00C2');
  570. entities.Add ("Atilde", '\u00C3');
  571. entities.Add ("Auml", '\u00C4');
  572. entities.Add ("Aring", '\u00C5');
  573. entities.Add ("AElig", '\u00C6');
  574. entities.Add ("Ccedil", '\u00C7');
  575. entities.Add ("Egrave", '\u00C8');
  576. entities.Add ("Eacute", '\u00C9');
  577. entities.Add ("Ecirc", '\u00CA');
  578. entities.Add ("Euml", '\u00CB');
  579. entities.Add ("Igrave", '\u00CC');
  580. entities.Add ("Iacute", '\u00CD');
  581. entities.Add ("Icirc", '\u00CE');
  582. entities.Add ("Iuml", '\u00CF');
  583. entities.Add ("ETH", '\u00D0');
  584. entities.Add ("Ntilde", '\u00D1');
  585. entities.Add ("Ograve", '\u00D2');
  586. entities.Add ("Oacute", '\u00D3');
  587. entities.Add ("Ocirc", '\u00D4');
  588. entities.Add ("Otilde", '\u00D5');
  589. entities.Add ("Ouml", '\u00D6');
  590. entities.Add ("times", '\u00D7');
  591. entities.Add ("Oslash", '\u00D8');
  592. entities.Add ("Ugrave", '\u00D9');
  593. entities.Add ("Uacute", '\u00DA');
  594. entities.Add ("Ucirc", '\u00DB');
  595. entities.Add ("Uuml", '\u00DC');
  596. entities.Add ("Yacute", '\u00DD');
  597. entities.Add ("THORN", '\u00DE');
  598. entities.Add ("szlig", '\u00DF');
  599. entities.Add ("agrave", '\u00E0');
  600. entities.Add ("aacute", '\u00E1');
  601. entities.Add ("acirc", '\u00E2');
  602. entities.Add ("atilde", '\u00E3');
  603. entities.Add ("auml", '\u00E4');
  604. entities.Add ("aring", '\u00E5');
  605. entities.Add ("aelig", '\u00E6');
  606. entities.Add ("ccedil", '\u00E7');
  607. entities.Add ("egrave", '\u00E8');
  608. entities.Add ("eacute", '\u00E9');
  609. entities.Add ("ecirc", '\u00EA');
  610. entities.Add ("euml", '\u00EB');
  611. entities.Add ("igrave", '\u00EC');
  612. entities.Add ("iacute", '\u00ED');
  613. entities.Add ("icirc", '\u00EE');
  614. entities.Add ("iuml", '\u00EF');
  615. entities.Add ("eth", '\u00F0');
  616. entities.Add ("ntilde", '\u00F1');
  617. entities.Add ("ograve", '\u00F2');
  618. entities.Add ("oacute", '\u00F3');
  619. entities.Add ("ocirc", '\u00F4');
  620. entities.Add ("otilde", '\u00F5');
  621. entities.Add ("ouml", '\u00F6');
  622. entities.Add ("divide", '\u00F7');
  623. entities.Add ("oslash", '\u00F8');
  624. entities.Add ("ugrave", '\u00F9');
  625. entities.Add ("uacute", '\u00FA');
  626. entities.Add ("ucirc", '\u00FB');
  627. entities.Add ("uuml", '\u00FC');
  628. entities.Add ("yacute", '\u00FD');
  629. entities.Add ("thorn", '\u00FE');
  630. entities.Add ("yuml", '\u00FF');
  631. entities.Add ("fnof", '\u0192');
  632. entities.Add ("Alpha", '\u0391');
  633. entities.Add ("Beta", '\u0392');
  634. entities.Add ("Gamma", '\u0393');
  635. entities.Add ("Delta", '\u0394');
  636. entities.Add ("Epsilon", '\u0395');
  637. entities.Add ("Zeta", '\u0396');
  638. entities.Add ("Eta", '\u0397');
  639. entities.Add ("Theta", '\u0398');
  640. entities.Add ("Iota", '\u0399');
  641. entities.Add ("Kappa", '\u039A');
  642. entities.Add ("Lambda", '\u039B');
  643. entities.Add ("Mu", '\u039C');
  644. entities.Add ("Nu", '\u039D');
  645. entities.Add ("Xi", '\u039E');
  646. entities.Add ("Omicron", '\u039F');
  647. entities.Add ("Pi", '\u03A0');
  648. entities.Add ("Rho", '\u03A1');
  649. entities.Add ("Sigma", '\u03A3');
  650. entities.Add ("Tau", '\u03A4');
  651. entities.Add ("Upsilon", '\u03A5');
  652. entities.Add ("Phi", '\u03A6');
  653. entities.Add ("Chi", '\u03A7');
  654. entities.Add ("Psi", '\u03A8');
  655. entities.Add ("Omega", '\u03A9');
  656. entities.Add ("alpha", '\u03B1');
  657. entities.Add ("beta", '\u03B2');
  658. entities.Add ("gamma", '\u03B3');
  659. entities.Add ("delta", '\u03B4');
  660. entities.Add ("epsilon", '\u03B5');
  661. entities.Add ("zeta", '\u03B6');
  662. entities.Add ("eta", '\u03B7');
  663. entities.Add ("theta", '\u03B8');
  664. entities.Add ("iota", '\u03B9');
  665. entities.Add ("kappa", '\u03BA');
  666. entities.Add ("lambda", '\u03BB');
  667. entities.Add ("mu", '\u03BC');
  668. entities.Add ("nu", '\u03BD');
  669. entities.Add ("xi", '\u03BE');
  670. entities.Add ("omicron", '\u03BF');
  671. entities.Add ("pi", '\u03C0');
  672. entities.Add ("rho", '\u03C1');
  673. entities.Add ("sigmaf", '\u03C2');
  674. entities.Add ("sigma", '\u03C3');
  675. entities.Add ("tau", '\u03C4');
  676. entities.Add ("upsilon", '\u03C5');
  677. entities.Add ("phi", '\u03C6');
  678. entities.Add ("chi", '\u03C7');
  679. entities.Add ("psi", '\u03C8');
  680. entities.Add ("omega", '\u03C9');
  681. entities.Add ("thetasym", '\u03D1');
  682. entities.Add ("upsih", '\u03D2');
  683. entities.Add ("piv", '\u03D6');
  684. entities.Add ("bull", '\u2022');
  685. entities.Add ("hellip", '\u2026');
  686. entities.Add ("prime", '\u2032');
  687. entities.Add ("Prime", '\u2033');
  688. entities.Add ("oline", '\u203E');
  689. entities.Add ("frasl", '\u2044');
  690. entities.Add ("weierp", '\u2118');
  691. entities.Add ("image", '\u2111');
  692. entities.Add ("real", '\u211C');
  693. entities.Add ("trade", '\u2122');
  694. entities.Add ("alefsym", '\u2135');
  695. entities.Add ("larr", '\u2190');
  696. entities.Add ("uarr", '\u2191');
  697. entities.Add ("rarr", '\u2192');
  698. entities.Add ("darr", '\u2193');
  699. entities.Add ("harr", '\u2194');
  700. entities.Add ("crarr", '\u21B5');
  701. entities.Add ("lArr", '\u21D0');
  702. entities.Add ("uArr", '\u21D1');
  703. entities.Add ("rArr", '\u21D2');
  704. entities.Add ("dArr", '\u21D3');
  705. entities.Add ("hArr", '\u21D4');
  706. entities.Add ("forall", '\u2200');
  707. entities.Add ("part", '\u2202');
  708. entities.Add ("exist", '\u2203');
  709. entities.Add ("empty", '\u2205');
  710. entities.Add ("nabla", '\u2207');
  711. entities.Add ("isin", '\u2208');
  712. entities.Add ("notin", '\u2209');
  713. entities.Add ("ni", '\u220B');
  714. entities.Add ("prod", '\u220F');
  715. entities.Add ("sum", '\u2211');
  716. entities.Add ("minus", '\u2212');
  717. entities.Add ("lowast", '\u2217');
  718. entities.Add ("radic", '\u221A');
  719. entities.Add ("prop", '\u221D');
  720. entities.Add ("infin", '\u221E');
  721. entities.Add ("ang", '\u2220');
  722. entities.Add ("and", '\u2227');
  723. entities.Add ("or", '\u2228');
  724. entities.Add ("cap", '\u2229');
  725. entities.Add ("cup", '\u222A');
  726. entities.Add ("int", '\u222B');
  727. entities.Add ("there4", '\u2234');
  728. entities.Add ("sim", '\u223C');
  729. entities.Add ("cong", '\u2245');
  730. entities.Add ("asymp", '\u2248');
  731. entities.Add ("ne", '\u2260');
  732. entities.Add ("equiv", '\u2261');
  733. entities.Add ("le", '\u2264');
  734. entities.Add ("ge", '\u2265');
  735. entities.Add ("sub", '\u2282');
  736. entities.Add ("sup", '\u2283');
  737. entities.Add ("nsub", '\u2284');
  738. entities.Add ("sube", '\u2286');
  739. entities.Add ("supe", '\u2287');
  740. entities.Add ("oplus", '\u2295');
  741. entities.Add ("otimes", '\u2297');
  742. entities.Add ("perp", '\u22A5');
  743. entities.Add ("sdot", '\u22C5');
  744. entities.Add ("lceil", '\u2308');
  745. entities.Add ("rceil", '\u2309');
  746. entities.Add ("lfloor", '\u230A');
  747. entities.Add ("rfloor", '\u230B');
  748. entities.Add ("lang", '\u2329');
  749. entities.Add ("rang", '\u232A');
  750. entities.Add ("loz", '\u25CA');
  751. entities.Add ("spades", '\u2660');
  752. entities.Add ("clubs", '\u2663');
  753. entities.Add ("hearts", '\u2665');
  754. entities.Add ("diams", '\u2666');
  755. entities.Add ("quot", '\u0022');
  756. entities.Add ("amp", '\u0026');
  757. entities.Add ("lt", '\u003C');
  758. entities.Add ("gt", '\u003E');
  759. entities.Add ("OElig", '\u0152');
  760. entities.Add ("oelig", '\u0153');
  761. entities.Add ("Scaron", '\u0160');
  762. entities.Add ("scaron", '\u0161');
  763. entities.Add ("Yuml", '\u0178');
  764. entities.Add ("circ", '\u02C6');
  765. entities.Add ("tilde", '\u02DC');
  766. entities.Add ("ensp", '\u2002');
  767. entities.Add ("emsp", '\u2003');
  768. entities.Add ("thinsp", '\u2009');
  769. entities.Add ("zwnj", '\u200C');
  770. entities.Add ("zwj", '\u200D');
  771. entities.Add ("lrm", '\u200E');
  772. entities.Add ("rlm", '\u200F');
  773. entities.Add ("ndash", '\u2013');
  774. entities.Add ("mdash", '\u2014');
  775. entities.Add ("lsquo", '\u2018');
  776. entities.Add ("rsquo", '\u2019');
  777. entities.Add ("sbquo", '\u201A');
  778. entities.Add ("ldquo", '\u201C');
  779. entities.Add ("rdquo", '\u201D');
  780. entities.Add ("bdquo", '\u201E');
  781. entities.Add ("dagger", '\u2020');
  782. entities.Add ("Dagger", '\u2021');
  783. entities.Add ("permil", '\u2030');
  784. entities.Add ("lsaquo", '\u2039');
  785. entities.Add ("rsaquo", '\u203A');
  786. entities.Add ("euro", '\u20AC');
  787. }
  788. }
  789. }