Produce a string in double quotes with backslash sequences in all the right places. A backslash will be inserted within </, producing <\/, allowing JSON text to be delivered in HTML. In JSON text, a string cannot contain a control character or an unescaped quote or backslash. @param string A String
(String string)
| 1388 | * @return A String correctly formatted for insertion in a JSON text. |
| 1389 | */ |
| 1390 | static public String quote(String string) { |
| 1391 | StringWriter sw = new StringWriter(); |
| 1392 | synchronized (sw.getBuffer()) { |
| 1393 | try { |
| 1394 | return quote(string, sw).toString(); |
| 1395 | } catch (IOException ignored) { |
| 1396 | // will never happen - we are writing to a string writer |
| 1397 | return ""; |
| 1398 | } |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | static public Writer quote(String string, Writer w) throws IOException { |
| 1403 | if (string == null || string.length() == 0) { |