EscapeUtils { public static String unescape(String value) { StringBuilder result = new StringBuilder(); StringBuilder escapeSequence = new StringBuilder(4); int i = 0; while (i < value.length()) { char ch = value.charAt(i); if (ch == '\\') { i++; ch = value.charAt(i); if (ch == 'u') { i = consumeEscapeSequence(i, 4, value, escapeSequence, result); } else if (ch == 'x') { i = consumeEscapeSequence(i, 2, value, escapeSequence, result); } else { result.append(unescape(ch)); i++; } } else { result.append(ch); i++; } } return result.toString(); } private  EscapeUtils(); static String unescape(String value);  }
@Test public void test() { assertThat(EscapeUtils.unescape("foo")).isEqualTo("foo"); assertThat(EscapeUtils.unescape("\\u000B")).isEqualTo("\u000B"); assertThat(EscapeUtils.unescape("\\x0B")).isEqualTo("\u000B"); assertThat(EscapeUtils.unescape("\\b")).isEqualTo("\b"); assertThat(EscapeUtils.unescape("\\t")).isEqualTo("\t"); assertThat(EscapeUtils.unescape("\\n")).isEqualTo("\n"); assertThat(EscapeUtils.unescape("\\v")).isEqualTo("\u000B"); assertThat(EscapeUtils.unescape("\\f")).isEqualTo("\f"); assertThat(EscapeUtils.unescape("\\r")).isEqualTo("\r"); assertThat(EscapeUtils.unescape("\\\"")).isEqualTo("\""); assertThat(EscapeUtils.unescape("\\\'")).isEqualTo("\'"); assertThat(EscapeUtils.unescape("\\\\")).isEqualTo("\\"); assertThat(EscapeUtils.unescape("\\|")).isEqualTo("|"); }