(String s)
| 38 | } |
| 39 | |
| 40 | public static String fromPrintString(String s) { |
| 41 | if(s.equals("null")) return null; |
| 42 | if(s.charAt(0) != '"') throw new IllegalStateException("Bad string " + s); |
| 43 | if(s.charAt(s.length() - 1) != '"') throw new IllegalStateException("Bad string " + s); |
| 44 | StringBuilder b = new StringBuilder(); |
| 45 | for(int i = 1; i < s.length() - 1; /* nothing */) { |
| 46 | char c = s.charAt(i++); |
| 47 | if(c == '\\') { |
| 48 | if(i < s.length() - 1) { |
| 49 | c = s.charAt(i++); |
| 50 | if(c == '"') { |
| 51 | b.append('"'); |
| 52 | } else if(c == '\\') { |
| 53 | b.append('\\'); |
| 54 | } else if(c == 'n') { |
| 55 | b.append('\n'); |
| 56 | } else if(c == 't') { |
| 57 | b.append('\t'); |
| 58 | } else if(c == 'r') { |
| 59 | b.append('\r'); |
| 60 | } else if(c == 'b') { |
| 61 | b.append('\b'); |
| 62 | } else if(c == 'f') { |
| 63 | b.append('\f'); |
| 64 | } else if(c == 'v') { |
| 65 | b.append((char) 11); |
| 66 | } else if(c == 'a') { |
| 67 | b.append((char) 7); |
| 68 | } else if(c == 'x') { |
| 69 | if(i + 1 < s.length() - 1) { |
| 70 | String digits = s.substring(i, i + 2); |
| 71 | i += 2; |
| 72 | b.append((char) Integer.parseInt(digits, 16)); |
| 73 | } else { |
| 74 | return null; // error |
| 75 | } |
| 76 | } else { |
| 77 | return null; // error |
| 78 | } |
| 79 | } else { |
| 80 | return null; // error |
| 81 | } |
| 82 | } else { |
| 83 | b.append(c); |
| 84 | } |
| 85 | } |
| 86 | return b.toString(); |
| 87 | } |
| 88 | |
| 89 | private StringUtils() {} |
| 90 | } |
no test coverage detected