Escape returns in as a JSON string literal, including the surrounding quotation marks. SYS-REQ-014
(in string)
| 228 | // quotation marks. |
| 229 | // SYS-REQ-014 |
| 230 | func Escape(in string) []byte { |
| 231 | var stackbuf [unescapeStackBufSize]byte |
| 232 | out := stackbuf[:0] |
| 233 | out = append(out, '"') |
| 234 | |
| 235 | start := 0 |
| 236 | for i := 0; i < len(in); i++ { |
| 237 | c := in[i] |
| 238 | if c >= 0x20 && c != '"' && c != '\\' { |
| 239 | continue |
| 240 | } |
| 241 | |
| 242 | out = append(out, in[start:i]...) |
| 243 | switch c { |
| 244 | case '"', '\\': |
| 245 | out = append(out, '\\', c) |
| 246 | case '\b': |
| 247 | out = append(out, '\\', 'b') |
| 248 | case '\f': |
| 249 | out = append(out, '\\', 'f') |
| 250 | case '\n': |
| 251 | out = append(out, '\\', 'n') |
| 252 | case '\r': |
| 253 | out = append(out, '\\', 'r') |
| 254 | case '\t': |
| 255 | out = append(out, '\\', 't') |
| 256 | default: |
| 257 | out = append(out, '\\', 'u', '0', '0', lowerHex[c>>4], lowerHex[c&0x0f]) |
| 258 | } |
| 259 | start = i + 1 |
| 260 | } |
| 261 | |
| 262 | out = append(out, in[start:]...) |
| 263 | return append(out, '"') |
| 264 | } |
| 265 | |
| 266 | // SetString replaces the value at keys with val encoded as a JSON string. |
| 267 | // SYS-REQ-009 |
no outgoing calls