package com.laozizhu.search.util;
import java.util.HashMap;
/**
* 替换HTMl里面的字符 e.g.: < > " å И 水
*
* @author 老紫竹(laozizhu.com)
*/
public class HTMLDecoder {
public static final HashMap charTable;
public static String decode(String s) {
String t;
Character ch;
int tmpPos, i;
int maxPos = s.length();
StringBuffer sb = new StringBuffer(maxPos);
int curPos = 0;
while (curPos < maxPos) {
char c = s.charAt(curPos++);
if (c == '&') {
tmpPos = curPos;
if (tmpPos < maxPos) {
char d = s.charAt(tmpPos++);
if (d == '#') {
if (tmpPos < maxPos) {
d = s.charAt(tmpPos++);
if ((d == 'x') || (d == 'X')) {
if (tmpPos < maxPos) {
d = s.charAt(tmpPos++);
if (isHexDigit(d)) {
while (tmpPos < maxPos) {
d = s.charAt(tmpPos++);
if (!isHexDigit(d)) {
if (d == ';') {
t = s.substring(curPos + 2, tmpPos - 1);
try {
i = Integer.parseInt(t, 16);
if ((i >= 0) && (i < 65536)) {
c = (char) i;
curPos = tmpPos;
}
} catch (NumberFormatException e) {
}
}
break; (责任编辑:大宝库)