import org.krysalis.barcode4j.impl.code128.EAN128Bean; //导入依赖的package包/类
public static String parseEscapes(String msg) {
if (msg == null || msg.indexOf('\\') < 0)
return msg;
int len = msg.length();
StringBuffer ret = new StringBuffer(len);
char c;
for (int i = 0; i < len; ) {
c = msg.charAt(i++);
if (c != '\\' || i >= len) { //if no Escape, or if Escape is the last char!
ret.append(c);
} else {
c = msg.charAt(i++);
switch (c) {
case '\\': ret.append('\\'); break;
case '0': ret.append('\0'); break;
case 'b': ret.append('\b'); break;
case 'c':
if (i >= len || (c = msg.charAt(i++)) != 'd') {
ret.append("\\c");
} else {
ret.append(EAN128Bean.DEFAULT_CHECK_DIGIT_MARKER);
}
break;
case 'f': ret.append('\f'); break;
case 'g':
if (i >= len || (c = msg.charAt(i++)) != 's') {
ret.append("\\g");
} else {
ret.append(EAN128Bean.DEFAULT_GROUP_SEPARATOR);
}
break;
case 'n': ret.append('\n'); break;
case 'r': ret.append('\r'); break;
case 't': ret.append('\t'); break;
case 'o': ret.append(decodeChar(msg, i, i += 3, 8)); break;
case 'd': ret.append(decodeChar(msg, i, i += 3, 10)); break;
case 'x': ret.append(decodeChar(msg, i, i += 2, 16)); break;
case 'u': ret.append(decodeChar(msg, i, i += 4, 16)); break;
default: ret.append('\\').append(c); break;
}
}
}
return ret.toString();
}