/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace Lucene.Net.Demo.Html { public class Entities { internal static readonly System.Collections.Hashtable decoder = new System.Collections.Hashtable(300); internal static readonly System.String[] encoder = new System.String[0x100]; internal static System.String Decode(System.String entity) { if (entity[entity.Length - 1] == ';') // remove trailing semicolon entity = entity.Substring(0, (entity.Length - 1) - (0)); if (entity[1] == '#') { int start = 2; int radix = 10; if (entity[2] == 'X' || entity[2] == 'x') { start++; radix = 16; } System.Char c = (char) System.Convert.ToInt32(entity.Substring(start), radix); return c.ToString(); } else { System.String s = (System.String) decoder[entity]; if (s != null) return s; else return ""; } } public static System.String Encode(System.String s) { int length = s.Length; System.Text.StringBuilder buffer = new System.Text.StringBuilder(length * 2); for (int i = 0; i < length; i++) { char c = s[i]; int j = (int) c; if (j < 0x100 && encoder[j] != null) { buffer.Append(encoder[j]); // have a named encoding buffer.Append(';'); } else if (j < 0x80) { buffer.Append(c); // use ASCII value } else { buffer.Append("&#"); // use numeric encoding buffer.Append((int) c); buffer.Append(';'); } } return buffer.ToString(); } internal static void Add(System.String entity, int value_Renamed) { decoder[entity] = ((char) value_Renamed).ToString(); if (value_Renamed < 0x100) encoder[value_Renamed] = entity; } static Entities() { { Add(" ", 160); Add("¡", 161); Add("¢", 162); Add("£", 163); Add("¤", 164); Add("¥", 165); Add("¦", 166); Add("§", 167); Add("¨", 168); Add("©", 169); Add("ª", 170); Add("«", 171); Add("¬", 172); Add("­", 173); Add("®", 174); Add("¯", 175); Add("°", 176); Add("±", 177); Add("²", 178); Add("³", 179); Add("´", 180); Add("µ", 181); Add("¶", 182); Add("·", 183); Add("¸", 184); Add("¹", 185); Add("º", 186); Add("»", 187); Add("¼", 188); Add("½", 189); Add("¾", 190); Add("¿", 191); Add("À", 192); Add("Á", 193); Add("Â", 194); Add("Ã", 195); Add("Ä", 196); Add("Å", 197); Add("Æ", 198); Add("Ç", 199); Add("È", 200); Add("É", 201); Add("Ê", 202); Add("Ë", 203); Add("Ì", 204); Add("Í", 205); Add("Î", 206); Add("Ï", 207); Add("Ð", 208); Add("Ñ", 209); Add("Ò", 210); Add("Ó", 211); Add("Ô", 212); Add("Õ", 213); Add("Ö", 214); Add("×", 215); Add("Ø", 216); Add("Ù", 217); Add("Ú", 218); Add("Û", 219); Add("Ü", 220); Add("Ý", 221); Add("Þ", 222); Add("ß", 223); Add("à", 224); Add("á", 225); Add("â", 226); Add("ã", 227); Add("ä", 228); Add("å", 229); Add("æ", 230); Add("ç", 231); Add("è", 232); Add("é", 233); Add("ê", 234); Add("ë", 235); Add("ì", 236); Add("í", 237); Add("î", 238); Add("ï", 239); Add("ð", 240); Add("ñ", 241); Add("ò", 242); Add("ó", 243); Add("ô", 244); Add("õ", 245); Add("ö", 246); Add("÷", 247); Add("ø", 248); Add("ù", 249); Add("ú", 250); Add("û", 251); Add("ü", 252); Add("ý", 253); Add("þ", 254); Add("ÿ", 255); Add("&fnof", 402); Add("&Alpha", 913); Add("&Beta", 914); Add("&Gamma", 915); Add("&Delta", 916); Add("&Epsilon", 917); Add("&Zeta", 918); Add("&Eta", 919); Add("&Theta", 920); Add("&Iota", 921); Add("&Kappa", 922); Add("&Lambda", 923); Add("&Mu", 924); Add("&Nu", 925); Add("&Xi", 926); Add("&Omicron", 927); Add("&Pi", 928); Add("&Rho", 929); Add("&Sigma", 931); Add("&Tau", 932); Add("&Upsilon", 933); Add("&Phi", 934); Add("&Chi", 935); Add("&Psi", 936); Add("&Omega", 937); Add("&alpha", 945); Add("&beta", 946); Add("&gamma", 947); Add("&delta", 948); Add("&epsilon", 949); Add("&zeta", 950); Add("&eta", 951); Add("&theta", 952); Add("&iota", 953); Add("&kappa", 954); Add("&lambda", 955); Add("&mu", 956); Add("&nu", 957); Add("&xi", 958); Add("&omicron", 959); Add("&pi", 960); Add("&rho", 961); Add("&sigmaf", 962); Add("&sigma", 963); Add("&tau", 964); Add("&upsilon", 965); Add("&phi", 966); Add("&chi", 967); Add("&psi", 968); Add("&omega", 969); Add("&thetasym", 977); Add("&upsih", 978); Add("&piv", 982); Add("&bull", 8226); Add("&hellip", 8230); Add("&prime", 8242); Add("&Prime", 8243); Add("&oline", 8254); Add("&frasl", 8260); Add("&weierp", 8472); Add("&image", 8465); Add("&real", 8476); Add("&trade", 8482); Add("&alefsym", 8501); Add("&larr", 8592); Add("&uarr", 8593); Add("&rarr", 8594); Add("&darr", 8595); Add("&harr", 8596); Add("&crarr", 8629); Add("&lArr", 8656); Add("&uArr", 8657); Add("&rArr", 8658); Add("&dArr", 8659); Add("&hArr", 8660); Add("&forall", 8704); Add("&part", 8706); Add("&exist", 8707); Add("&empty", 8709); Add("&nabla", 8711); Add("&isin", 8712); Add("¬in", 8713); Add("&ni", 8715); Add("&prod", 8719); Add("&sum", 8721); Add("&minus", 8722); Add("&lowast", 8727); Add("&radic", 8730); Add("&prop", 8733); Add("&infin", 8734); Add("&ang", 8736); Add("&and", 8743); Add("&or", 8744); Add("&cap", 8745); Add("&cup", 8746); Add("&int", 8747); Add("&there4", 8756); Add("&sim", 8764); Add("&cong", 8773); Add("&asymp", 8776); Add("&ne", 8800); Add("&equiv", 8801); Add("&le", 8804); Add("&ge", 8805); Add("&sub", 8834); Add("&sup", 8835); Add("&nsub", 8836); Add("&sube", 8838); Add("&supe", 8839); Add("&oplus", 8853); Add("&otimes", 8855); Add("&perp", 8869); Add("&sdot", 8901); Add("&lceil", 8968); Add("&rceil", 8969); Add("&lfloor", 8970); Add("&rfloor", 8971); Add("&lang", 9001); Add("&rang", 9002); Add("&loz", 9674); Add("&spades", 9824); Add("&clubs", 9827); Add("&hearts", 9829); Add("&diams", 9830); Add(""", 34); Add("&", 38); Add("<", 60); Add(">", 62); Add("&OElig", 338); Add("&oelig", 339); Add("&Scaron", 352); Add("&scaron", 353); Add("&Yuml", 376); Add("&circ", 710); Add("&tilde", 732); Add("&ensp", 8194); Add("&emsp", 8195); Add("&thinsp", 8201); Add("&zwnj", 8204); Add("&zwj", 8205); Add("&lrm", 8206); Add("&rlm", 8207); Add("&ndash", 8211); Add("&mdash", 8212); Add("&lsquo", 8216); Add("&rsquo", 8217); Add("&sbquo", 8218); Add("&ldquo", 8220); Add("&rdquo", 8221); Add("&bdquo", 8222); Add("&dagger", 8224); Add("&Dagger", 8225); Add("&permil", 8240); Add("&lsaquo", 8249); Add("&rsaquo", 8250); Add("&euro", 8364); } } } }