Replaces special characters in a String for creation of a quoted macro String. Does not add quotes.
(String str)
| 220 | |
| 221 | /** Replaces special characters in a String for creation of a quoted macro String. Does not add quotes. */ |
| 222 | public static String fixString (String str) { |
| 223 | StringBuilder sb = new StringBuilder(); |
| 224 | char c; |
| 225 | for (int i=0; i<str.length(); i++) { |
| 226 | c = str.charAt(i); |
| 227 | if (c =='\\' || c=='"') |
| 228 | sb.append("\\"+c); |
| 229 | else if (c == '\n') |
| 230 | sb.append("\\n"); |
| 231 | else if (c < ' ' || c > '~' && c < 0xa0) { |
| 232 | sb.append('\\'); |
| 233 | String octal = Integer.toString(c,8); |
| 234 | while (octal.length()<3) |
| 235 | octal = '0' + octal; |
| 236 | sb.append(octal); |
| 237 | } else |
| 238 | sb.append(c); |
| 239 | } |
| 240 | return new String(sb); |
| 241 | } |
| 242 | |
| 243 | public static void record(String method, String arg) { |
| 244 | if (IJ.debugMode) IJ.log("record: "+method+" "+arg); |
no test coverage detected