Advertisement
Guest User

System.Web.Util

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