MCPcopy Create free account
hub / github.com/Hiro420/NikkeTools / toPrintString

Method toPrintString

UnLuac/src/unluac/util/StringUtils.java:5–38  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

3public class StringUtils {
4
5 public static String toPrintString(String s) {
6 if(s == null) return "null";
7 StringBuilder b = new StringBuilder();
8 b.append('"');
9 for(int i = 0; i < s.length(); i++) {
10 char c = s.charAt(i);
11 int ci = (int)c;
12 if(c == '"') {
13 b.append("\\\"");
14 } else if(c == '\\') {
15 b.append("\\\\");
16 } else if(ci >= 32 && ci <= 126) {
17 b.append(c);
18 } else if(c == '\n') {
19 b.append("\\n");
20 } else if(c == '\t') {
21 b.append("\\t");
22 } else if(c == '\r') {
23 b.append("\\r");
24 } else if(c == '\b') {
25 b.append("\\b");
26 } else if(c == '\f') {
27 b.append("\\f");
28 } else if(ci == 11) {
29 b.append("\\v");
30 } else if(ci == 7) {
31 b.append("\\a");
32 } else {
33 b.append(String.format("\\x%02x", ci));
34 }
35 }
36 b.append('"');
37 return b.toString();
38 }
39
40 public static String fromPrintString(String s) {
41 if(s.equals("null")) return null;

Callers 2

disassembleMethod · 0.95
toPrintStringMethod · 0.95

Calls 2

lengthMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected