public static String unescape(String str) {
        if (str == null) {
            return null;
        }
        int len = str.length();
        StringWriter writer = new StringWriter(len);
        StringBuilder unicode = new StringBuilder(4);
        boolean hadSlash = false;
        boolean inUnicode = false;
        for (int i = 0; i < len; i++) {
            char ch = str.charAt(i);
            if (inUnicode) {
                unicode.append(ch);
                if (unicode.length() == 4) {
                    try {
                        int value = Integer.parseInt(unicode.toString(), 16);
                        writer.write((char) value);
                        unicode.setLength(0);
                        inUnicode = false;
                        hadSlash = false;
                    } catch (NumberFormatException nfe) {
                        throw new JsonPathException("Unable to parse unicode value: " + unicode, nfe);
                    }
                }
                continue;
            }
            if (hadSlash) {
                hadSlash = false;
                switch (ch) {
                    case '\\':
                        writer.write('\\');
                        break;
                    case '\'':
                        writer.write('\'');
                        break;
                    case '\"':
                        writer.write('"');
                        break;
                    case 'r':
                        writer.write('\r');
                        break;
                    case 'f':
                        writer.write('\f');
                        break;
                    case 't':
                        writer.write('\t');
                        break;
                    case 'n':
                        writer.write('\n');
                        break;
                    case 'b':
                        writer.write('\b');
                        break;
                    case 'u':
                    {
                        inUnicode = true;
                        break;
                    }
                    default :
                        writer.write(ch);
                        break;
                }
                continue;
            } else if (ch == '\\') {
                hadSlash = true;
                continue;
            }
            writer.write(ch);
        }
        if (hadSlash) {
            writer.write('\\');
        }
        return writer.toString();
    }
@Test
    public void testUnescape() {
        Assertions.assertNull(Utils.unescape(null));

        Assertions.assertEquals("foo", Utils.unescape("foo"));
        Assertions.assertEquals("\\", Utils.unescape("\\"));
        Assertions.assertEquals("\\", Utils.unescape("\\\\"));
        Assertions.assertEquals("\'", Utils.unescape("\\\'"));
        Assertions.assertEquals("\"", Utils.unescape("\\\""));
        Assertions.assertEquals("\r", Utils.unescape("\\r"));
        Assertions.assertEquals("\f", Utils.unescape("\\f"));
        Assertions.assertEquals("\t", Utils.unescape("\\t"));
        Assertions.assertEquals("\n", Utils.unescape("\\n"));
        Assertions.assertEquals("\b", Utils.unescape("\\b"));
        Assertions.assertEquals("a", Utils.unescape("\\a"));
        Assertions.assertEquals("\uffff", Utils.unescape("\\uffff"));
    }