1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

fixes code point appends to string builder

This commit is contained in:
John J. Aylward 2016-09-22 16:10:49 -04:00
parent c11e09959c
commit f58a0f4684

View file

@ -119,8 +119,8 @@ public class XML {
*/ */
public static String escape(String string) { public static String escape(String string) {
StringBuilder sb = new StringBuilder(string.length()); StringBuilder sb = new StringBuilder(string.length());
for (final int c : codePointIterator(string)) { for (final int cp : codePointIterator(string)) {
switch (c) { switch (cp) {
case '&': case '&':
sb.append("&"); sb.append("&");
break; break;
@ -137,12 +137,12 @@ public class XML {
sb.append("'"); sb.append("'");
break; break;
default: default:
if (Character.isISOControl(c)) { if (Character.isISOControl(cp)) {
sb.append("&#x"); sb.append("&#x");
sb.append(Integer.toHexString(c)); sb.append(Integer.toHexString(cp));
sb.append(";"); sb.append(";");
} else { } else {
sb.append(new String(Character.toChars(c))); sb.appendCodePoint(cp);
} }
} }
} }
@ -173,7 +173,7 @@ public class XML {
// decimal encoded unicode // decimal encoded unicode
cp = Integer.parseInt(entity.substring(1)); cp = Integer.parseInt(entity.substring(1));
} }
sb.append(new String(Character.toChars(cp))); sb.appendCodePoint(cp);
} else { } else {
if ("quot".equalsIgnoreCase(entity)) { if ("quot".equalsIgnoreCase(entity)) {
sb.append('"'); sb.append('"');