HttpEncoder.cs 23 KB

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