public static String unescape(String source) {
        byte[] bytes = source.getBytes(UTF8);
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        for (int i=0; i<bytes.length; ++i) {
            if (bytes[i] != '\\') {
                result.write(bytes[i]);
                continue;
            }
            if (i + 1 == bytes.length) throw new IllegalArgumentException("Found backslash at end of input");

            if (bytes[i + 1] != (byte) 'x') {
                switch (bytes[i + 1]) {
                    case '\\' -> result.write('\\');
                    case '"' -> result.write('"');
                    case 't' -> result.write('\t');
                    case 'n' -> result.write('\n');
                    case 'r' -> result.write('\r');
                    case 'f' -> result.write('\f');
                    default -> throw new IllegalArgumentException("Illegal escape sequence \\" + ((char) bytes[i + 1]) + " found");
                }
                ++i;
                continue;
            }

            if (i + 3 >= bytes.length) throw new IllegalArgumentException("Found \\x at end of input");

            String hexdigits = "" + ((char) bytes[i + 2]) + ((char) bytes[i + 3]);
            result.write((byte) Integer.parseInt(hexdigits, 16));
            i += 3;
        }
        return result.toString(UTF8);
    }
@Test
    public void testUnescape() {
        assertEquals("abz019ABZ", StringUtilities.unescape("abz019ABZ"));
        assertEquals("\t", StringUtilities.unescape("\\t"));
        assertEquals("\n", StringUtilities.unescape("\\n"));
        assertEquals("\r", StringUtilities.unescape("\\r"));
        assertEquals("\"", StringUtilities.unescape("\\\""));
        assertEquals("\f", StringUtilities.unescape("\\f"));
        assertEquals("\\", StringUtilities.unescape("\\\\"));
        assertEquals("" + (char) 5, StringUtilities.unescape("\\x05"));
        assertEquals("\tA\ncombined\r" + ((char) 5) + "5test", StringUtilities.unescape("\\tA\\ncombined\\r\\x055test"));
        assertEquals("A space separated string", StringUtilities.unescape("A\\x20space\\x20separated\\x20string"));
    }