Skip to content

Commit f16b9d2

Browse files
committed
Render undisplayable characters as \u literals
1 parent 234519b commit f16b9d2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/main/java/the/bytecode/club/jda/gui/PaneUpdaterThread.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public void run() {
3939
panelArea.setCodeFoldingEnabled(true);
4040
panelArea.setAntiAliasingEnabled(true);
4141
final RTextScrollPane scrollPane = new RTextScrollPane(panelArea);
42-
panelArea.setText(decompiler.decompileClassNode(viewer.cn, b));
42+
String decompileResult = decompiler.decompileClassNode(viewer.cn, b);
43+
panelArea.setText(stripUndisplayableChars(decompileResult));
4344
panelArea.setCaretPosition(0);
4445
panelArea.setEditable(viewer.isPaneEditable(paneId));
4546
scrollPane.setColumnHeaderView(new JLabel(decompiler.getName() + " Decompiler - Editable: " + panelArea.isEditable()));
@@ -56,4 +57,25 @@ public void run() {
5657
button.setEnabled(true);
5758
}
5859
}
60+
61+
private String stripUndisplayableChars(String s) {
62+
StringBuilder result = new StringBuilder();
63+
int startIdx = 0, idx = 0;
64+
while (idx < s.length()) {
65+
char c = s.charAt(idx);
66+
if (isUndisplayable(c)) {
67+
result.append(s.substring(startIdx, idx));
68+
result.append("\\u").append(Integer.toHexString(c));
69+
startIdx = idx + 1;
70+
}
71+
idx++;
72+
}
73+
if (idx > startIdx)
74+
result.append(s.substring(startIdx, idx));
75+
return result.toString();
76+
}
77+
78+
private boolean isUndisplayable(char c) {
79+
return c >= 255 || c == 127;
80+
}
5981
}

0 commit comments

Comments
 (0)