Escape is a convenience helper to construct an escaped JSON string from s. The function escales HTML characters, for more control over the escape behavior and to write to a pre-allocated buffer, use AppendEscape.
(s string)
| 219 | // The function escales HTML characters, for more control over the escape |
| 220 | // behavior and to write to a pre-allocated buffer, use AppendEscape. |
| 221 | func Escape(s string) []byte { |
| 222 | // +10 for extra escape characters, maybe not enough and the buffer will |
| 223 | // be reallocated. |
| 224 | b := make([]byte, 0, len(s)+10) |
| 225 | return AppendEscape(b, s, EscapeHTML) |
| 226 | } |
| 227 | |
| 228 | // AppendEscape appends s to b with the string escaped as a JSON value. |
| 229 | // This will include the starting and ending quote characters, and the |
searching dependent graphs…