/** * Escape the string with given quote character. */ public static String escape(String value, char quote) { final CharSequenceTranslator escape = new LookupTranslator( new String[][]{ {Character.toString(quote), "\\" + quote}, {"\\", "\\\\"}, }).with( new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE()) ).with( JavaUnicodeEscaper.outsideOf(32, 0x7f) ); return quote + escape.translate(value) + quote; }