HtmlEncoder.cs 23 KB

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