break;
}
}
}
}
}
sb.append(c);
}
return sb.toString();
}
private static boolean isLetterOrDigit(char c) {
return isLetter(c) || isDigit(c);
}
private static boolean isHexDigit(char c) {
return isHexLetter(c) || isDigit(c);
}
private static boolean isLetter(char c) {
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
}
private static boolean isHexLetter(char c) {
return ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F'));
}
private static boolean isDigit(char c) {
return (c >= '0') && (c <= '9');
}
public static String compact(String s) {
int maxPos = s.length();
StringBuffer sb = new StringBuffer(maxPos);
int curPos = 0;
while (curPos < maxPos) {
char c = s.charAt(curPos++);
if (isWhitespace(c)) {
while ((curPos < maxPos) && isWhitespace(s.charAt(curPos))) {
curPos++;
}
c = '\u0020';
}
sb.append(c);
}
return sb.toString();
}
// HTML is very particular about what constitutes white space.
public static boolean isWhitespace(char ch) {
return (ch == '\u0020') || (ch == '\r') || (ch == '\n') || (ch == '\u0009') || (ch == '\u000c') || (ch == '\u200b');
}
static {
charTable = new HashMap();
charTable.put("quot", new Character((char) 34));
charTable.put("amp", new Character((char) 38));
charTable.put("apos", new Character((char) 39));
charTable.put("lt", new Character((char) 60));
charTable.put("gt", new Character((char) 62));
charTable.put("nbsp", new Character((char) 160));
charTable.put("iexcl", new Character((char) 161));
charTable.put("cent", new Character((char) 162));
charTable.put("pound", new Character((char) 163));
charTable.put("curren", new Character((char) 164));
charTable.put("yen", new Character((char) 165));
charTable.put("brvbar", new Character((char) 166));
charTable.put("sect", new Character((char) 167));
charTable.put("uml", new Character((char) 168));
charTable.put("copy", new Character((char) 169));
charTable.put("ordf", new Character((char) 170));
charTable.put("laquo", new Character((char) 171));
charTable.put("not", new Character((char) 172)); (责任编辑:大宝库)