MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / decodeEscaped

Method decodeEscaped

ij/src/main/java/ij/util/Tools.java:449–468  ·  view source on GitHub ↗

Decodes backslash-escaped characters from the String until the character 'delim' is found. With 'delim'=-1, does not search for a delimiter, with 'delim'=(char)-2, (unescaped) whitespace, commas and semicolons are interpreted as delimiters. Also decodes unicode backslash-u???? characters

(String str, char delim)

Source from the content-addressed store, hash-verified

447 * whitespace, commas and semicolons are interpreted as delimiters.
448 * Also decodes unicode backslash-u???? characters */
449 public static String decodeEscaped(String str, char delim) {
450 StringBuilder sb = new StringBuilder();
451 for (int i=0; i<str.length(); i++) {
452 char c = str.charAt(i);
453 if ((delim == (char)-2 && isDelimiter(c)) || c == delim) break;
454 if (c == '\\' && i+1 < str.length()) { //escaped by backslash
455 i++;
456 c = str.charAt(i);
457 if (c == 'u' && i+4 < str.length())
458 try {
459 c = (char)Integer.parseInt(str.substring(i+1, i+5), 16);
460 i += 4;
461 } catch (NumberFormatException e) {}
462 else
463 c = withBackslash(c); // decodes backslash-t for tab etc.
464 }
465 sb.append(c);
466 }
467 return sb.toString();
468 }
469
470 private static boolean isDelimiter(char c) {
471 return Character.isWhitespace(c) || c==',' || c==';';

Callers 1

getStringFromListMethod · 0.95

Calls 8

isDelimiterMethod · 0.95
withBackslashMethod · 0.95
charAtMethod · 0.80
parseIntMethod · 0.80
substringMethod · 0.80
lengthMethod · 0.65
appendMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected