Entitiespublic class Entities extends Object 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. |
Fields Summary |
---|
static final Hashtable | decoder | static final String[] | encoder |
Methods Summary |
---|
static final void | add(java.lang.String entity, int value)
decoder.put(entity, (new Character((char)value)).toString());
if (value < 0x100)
encoder[value] = entity;
| static final java.lang.String | decode(java.lang.String entity)
if (entity.charAt(entity.length()-1) == ';") // remove trailing semicolon
entity = entity.substring(0, entity.length()-1);
if (entity.charAt(1) == '#") {
int start = 2;
int radix = 10;
if (entity.charAt(2) == 'X" || entity.charAt(2) == 'x") {
start++;
radix = 16;
}
Character c =
new Character((char)Integer.parseInt(entity.substring(start), radix));
return c.toString();
} else {
String s = (String)decoder.get(entity);
if (s != null)
return s;
else return "";
}
| public static final java.lang.String | encode(java.lang.String s)
int length = s.length();
StringBuffer buffer = new StringBuffer(length * 2);
for (int i = 0; i < length; i++) {
char c = s.charAt(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();
|
|