HttpEncoder.cs 23 KB

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