public static String unquote(String str) {
        if (str.length() == 0) {
            return str;
        }
        char quote = str.charAt(0);
        if (quote != '"' && quote != '\'') {
            return str;
        }
        if (str.charAt(str.length() - 1) != quote) {
            return str;
        }
        StringBuilder ret = new StringBuilder();
        for (int i = 1; i < str.length() - 1; ++i) {
            char c = str.charAt(i);
            if (c == '\\') {
                if (++i == str.length() - 1) {
                    break; // done
                }
                c = str.charAt(i);
                if (c == 'f') {
                    ret.append("\f");
                } else if (c == 'n') {
                    ret.append("\n");
                } else if (c == 'r') {
                    ret.append("\r");
                } else if (c == 't') {
                    ret.append("\t");
                } else if (c == 'u') {
                    if (++i > str.length() - 4) {
                        break; // done
                    }
                    try {
                        ret.append((char)Integer.parseInt(str.substring(i, i + 4), 16));
                    } catch (NumberFormatException e) {
                        throw new IllegalArgumentException(e);
                    }
                    i += 3;
                } else {
                    ret.append(c);
                }
            } else if (c == quote) {
                throw new IllegalArgumentException();
            } else {
                ret.append(c);
            }
        }
        return ret.toString();
    }
Removes leading and trailing quotation mark from the given string. This method will properly unescape whatever
content is withing the string literal as well.

@param str The string to unquote.
@return The unquoted string.
vespajlib/src/main/java/com/yahoo/javacc/UnicodeUtilities.java