fun jQuote(s: String?): String? { if (s == null) { return "null" } val ln = s.length val b = StringBuilder(ln + 4) b.append('"') for (i in 0 until ln) { val c = s[i] if (c == '"') { b.append("\\\"") } else if (c == '\\') { b.append("\\\\") } else if (c.code < 0x20) { if (c == '\n') { b.append("\\n") } else if (c == '\r') { b.append("\\r") } else if (c == '\f') { b.append("\\f") } else if (c == '\b') { b.append("\\b") } else if (c == '\t') { b.append("\\t") } else { b.append("\\u00") var x = c.code / 0x10 b.append(toHexDigit(x)) x = c.code and 0xF b.append(toHexDigit(x)) } } else { b.append(c) } } b.append('"') return b.toString() }
Quotes string as Java Language string literal . Returns string < code > '' null '' < /code > if < code > s < /code > is < code > null < /code > .