/** * Removes XML escapes from the string. * * @param string * string to remove escapes from * @return string with converted entities */ public static String unescape(String string) { StringBuilder sb = new StringBuilder(string.length()); for (int i = 0, length = string.length(); i < length; i++) { char c = string.charAt(i); if (c == '&') { final int semic = string.indexOf(';', i); if (semic > i) { final String entity = string.substring(i + 1, semic); sb.append(XMLTokener.unescapeEntity(entity)); // skip past the entity we just parsed. i += entity.length() + 1; } else { // this shouldn't happen in most cases since the parser // errors on unclosed entries. sb.append(c); } } else { // not part of an entity sb.append(c); } } return sb.toString(); }
/** * Return the next entity. These entities are translated to Characters: * <code>& ' > < "</code>. * @param ampersand An ampersand character. * @return A Character or an entity String if the entity is not recognized. * @throws JSONException If missing ';' in XML entity. */ public Object nextEntity(char ampersand) throws JSONException { StringBuilder sb = new StringBuilder(); for (;;) { char c = next(); if (Character.isLetterOrDigit(c) || c == '#') { sb.append(Character.toLowerCase(c)); } else if (c == ';') { break; } else { throw syntaxError("Missing ';' in XML entity: &" + sb); } } String string = sb.toString(); return unescapeEntity(string); }
/** * Removes XML escapes from the string. * * @param string * string to remove escapes from * @return string with converted entities */ public static String unescape(String string) { StringBuilder sb = new StringBuilder(string.length()); for (int i = 0, length = string.length(); i < length; i++) { char c = string.charAt(i); if (c == '&') { final int semic = string.indexOf(';', i); if (semic > i) { final String entity = string.substring(i + 1, semic); sb.append(XMLTokener.unescapeEntity(entity)); // skip past the entity we just parsed. i += entity.length() + 1; } else { // this shouldn't happen in most cases since the parser // errors on unclosed entries. sb.append(c); } } else { // not part of an entity sb.append(c); } } return sb.toString(); }
/** * Return the next entity. These entities are translated to Characters: * <code>& ' > < "</code>. * @param ampersand An ampersand character. * @return A Character or an entity String if the entity is not recognized. * @throws JSONException If missing ';' in XML entity. */ public Object nextEntity(@SuppressWarnings("unused") char ampersand) throws JSONException { StringBuilder sb = new StringBuilder(); for (;;) { char c = next(); if (Character.isLetterOrDigit(c) || c == '#') { sb.append(Character.toLowerCase(c)); } else if (c == ';') { break; } else { throw syntaxError("Missing ';' in XML entity: &" + sb); } } String string = sb.toString(); return unescapeEntity(string); }
/** * Removes XML escapes from the string. * * @param string * string to remove escapes from * @return string with converted entities */ public static String unescape(String string) { StringBuilder sb = new StringBuilder(string.length()); for (int i = 0, length = string.length(); i < length; i++) { char c = string.charAt(i); if (c == '&') { final int semic = string.indexOf(';', i); if (semic > i) { final String entity = string.substring(i + 1, semic); sb.append(XMLTokener.unescapeEntity(entity)); // skip past the entity we just parsed. i += entity.length() + 1; } else { // this shouldn't happen in most cases since the parser // errors on unclosed entries. sb.append(c); } } else { // not part of an entity sb.append(c); } } return sb.toString(); }
/** * Return the next entity. These entities are translated to Characters: * <code>& ' > < "</code>. * @param ampersand An ampersand character. * @return A Character or an entity String if the entity is not recognized. * @throws JSONException If missing ';' in XML entity. */ public Object nextEntity(@SuppressWarnings("unused") char ampersand) throws JSONException { StringBuilder sb = new StringBuilder(); for (;;) { char c = next(); if (Character.isLetterOrDigit(c) || c == '#') { sb.append(Character.toLowerCase(c)); } else if (c == ';') { break; } else { throw syntaxError("Missing ';' in XML entity: &" + sb); } } String string = sb.toString(); return unescapeEntity(string); }