Escape returns in as a JSON string literal, including the surrounding quotation marks. SYS-REQ-014
(in string)
| 202 | // quotation marks. |
| 203 | // SYS-REQ-014 |
| 204 | func Escape(in string) []byte { |
| 205 | var stackbuf [unescapeStackBufSize]byte |
| 206 | out := stackbuf[:0] |
| 207 | out = append(out, '"') |
| 208 | |
| 209 | start := 0 |
| 210 | for i := 0; i < len(in); i++ { |
| 211 | c := in[i] |
| 212 | if c >= 0x20 && c != '"' && c != '\\' { |
| 213 | continue |
| 214 | } |
| 215 | |
| 216 | out = append(out, in[start:i]...) |
| 217 | switch c { |
| 218 | case '"', '\\': |
| 219 | out = append(out, '\\', c) |
| 220 | case '\b': |
| 221 | out = append(out, '\\', 'b') |
| 222 | case '\f': |
| 223 | out = append(out, '\\', 'f') |
| 224 | case '\n': |
| 225 | out = append(out, '\\', 'n') |
| 226 | case '\r': |
| 227 | out = append(out, '\\', 'r') |
| 228 | case '\t': |
| 229 | out = append(out, '\\', 't') |
| 230 | default: |
| 231 | out = append(out, '\\', 'u', '0', '0', lowerHex[c>>4], lowerHex[c&0x0f]) |
| 232 | } |
| 233 | start = i + 1 |
| 234 | } |
| 235 | |
| 236 | out = append(out, in[start:]...) |
| 237 | return append(out, '"') |
| 238 | } |
| 239 | |
| 240 | // SetString replaces the value at keys with val encoded as a JSON string. |
| 241 | // SYS-REQ-009 |
no outgoing calls