1 package org.apache.lucene.benchmark.byTask.feeds.demohtml;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.util.HashMap;
23 public class Entities {
24 static final Map<String,String> decoder = new HashMap<String,String>(300);
25 static final String[] encoder = new String[0x100];
27 static final String decode(String entity) {
28 if (entity.charAt(entity.length()-1) == ';') // remove trailing semicolon
29 entity = entity.substring(0, entity.length()-1);
30 if (entity.charAt(1) == '#') {
33 if (entity.charAt(2) == 'X' || entity.charAt(2) == 'x') {
38 new Character((char)Integer.parseInt(entity.substring(start), radix));
41 String s = decoder.get(entity);
48 public static final String encode(String s) {
49 int length = s.length();
50 StringBuffer buffer = new StringBuffer(length * 2);
51 for (int i = 0; i < length; i++) {
53 if (j < 0x100 && encoder[j] != null) {
54 buffer.append(encoder[j]); // have a named encoding
56 } else if (j < 0x80) {
57 buffer.append((char) j); // use ASCII value
59 buffer.append("&#"); // use numeric encoding
60 buffer.append(j).append(';');
63 return buffer.toString();
66 static final void add(String entity, int value) {
67 decoder.put(entity, (new Character((char)value)).toString());
69 encoder[value] = entity;
219 add("&thetasym",977);
223 add("&hellip", 8230);
228 add("&weierp", 8472);
232 add("&alefsym",8501);
244 add("&forall", 8704);
255 add("&lowast", 8727);
265 add("&there4", 8756);
279 add("&otimes", 8855);
284 add("&lfloor", 8970);
285 add("&rfloor", 8971);
289 add("&spades", 9824);
291 add("&hearts", 9829);
306 add("&thinsp", 8201);
319 add("&dagger", 8224);
320 add("&Dagger", 8225);
321 add("&permil", 8240);
322 add("&lsaquo", 8249);
323 add("&rsaquo", 8250);