public static String quote(String str, char quote) {
        StringBuilder ret = new StringBuilder();
        ret.append(quote);
        for (int i = 0; i < str.length(); ++i) {
            char c = str.charAt(i);
            if (c == quote) {
                ret.append("\\").append(c);
            } else {
                ret.append(escape(c));
            }
        }
        ret.append(quote);
        return ret.toString();
    }
Adds a leading and trailing double quotation mark to the given string. This will escape whatever content is
within the string literal.

@param str   The string to quote.
@param quote The quote character.
@return The quoted string.
vespajlib/src/main/java/com/yahoo/javacc/UnicodeUtilities.java