* Licensed 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.
public class XmlEscape {
private XmlEscape() {}
-
+
private static final TreeMap<String,Integer> charMap; // see initialization at end
private static final TreeMap<Integer,String> intMap; // see initialization at end
StringBuilder esc = new StringBuilder();
for (int cnt = 0;cnt<9 /*max*/; ++cnt) {
if ((c=r.read())<0)throw new ParseException("Invalid Data: Unfinished Escape Sequence");
- if (c!=';') {
+ if (c!=';') {
esc.append((char)c);
} else { // evaluate
Integer i = charMap.get(esc.toString());
break;
}
}
-
-
+
+
} catch (IOException e) {
throw new ParseException(e);
}
}
-
+
public static void xmlEscape(StringBuilder sb, int chr) {
sb.append('&');
sb.append(intMap.get(chr));
sb.append(';');
}
-
+
public static String convert(StringBuilder insb) {
int idx, ch;
StringBuilder sb=null;
break;
}
}
-
+
if (sb==null)return insb.toString();
-
+
for (int i=idx;i<insb.length();++i) {
ch = insb.charAt(i);
if (ch<160) {
charMap.put("clubs",9827);
charMap.put("hearts",9829);
charMap.put("diams",9830);
-
+
for ( Entry<String, Integer> es: charMap.entrySet()) {
if (es.getValue()>=160); // save small space... note that no longer has amp, etc.
intMap.put(es.getValue(), es.getKey());