Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Fix JSONEncoder for non-printable characters #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static String encode(String text) {
if ((null == text) || (text.length() == 0)) {
return text;
}
Formatter formatter = new java.util.Formatter();
StringBuffer result = new StringBuffer();
Formatter formatter = new java.util.Formatter(result);
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
switch (c) {
Expand All @@ -79,12 +79,13 @@ public static String encode(String text) {
break;
default:
if (c < ' ') { // TODO: what about c > 255 ???
result.append(formatter.format("\\u%04X", (int)c));
formatter.format("\\u%04X", (int)c);
} else {
result.append(c);
}
}
}
formatter.close();
return result.toString();
}
}