mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Merge remote-tracking branch 'origin/master' into AndroidSupport
This commit is contained in:
commit
057e0c75ca
6 changed files with 187 additions and 82 deletions
|
@ -138,8 +138,37 @@ public class XMLTokener extends JSONTokener {
|
|||
}
|
||||
}
|
||||
String string = sb.toString();
|
||||
Object object = entity.get(string);
|
||||
return object != null ? object : ampersand + string + ";";
|
||||
return unescapeEntity(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unescapes an XML entity encoding;
|
||||
* @param e entity (only the actual entity value, not the preceding & or ending ;
|
||||
* @return
|
||||
*/
|
||||
static String unescapeEntity(String e) {
|
||||
// validate
|
||||
if (e == null || e.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
// if our entity is an encoded unicode point, parse it.
|
||||
if (e.charAt(0) == '#') {
|
||||
int cp;
|
||||
if (e.charAt(1) == 'x') {
|
||||
// hex encoded unicode
|
||||
cp = Integer.parseInt(e.substring(2), 16);
|
||||
} else {
|
||||
// decimal encoded unicode
|
||||
cp = Integer.parseInt(e.substring(1));
|
||||
}
|
||||
return new String(new int[] {cp},0,1);
|
||||
}
|
||||
Character knownEntity = entity.get(e);
|
||||
if(knownEntity==null) {
|
||||
// we don't know the entity so keep it encoded
|
||||
return '&' + e + ';';
|
||||
}
|
||||
return knownEntity.toString();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue