QuotedString quotes and escapes a SUP string for serialization in accordance with the SUP spec. It was copied and modified [with attribution](https://github.com/brimdata/super/blob/main/acknowledgments.txt) from the encoding/json package in the Go source code.
(s string)
| 26 | // [with attribution](https://github.com/brimdata/super/blob/main/acknowledgments.txt) |
| 27 | // from the encoding/json package in the Go source code. |
| 28 | func QuotedString(s string) string { |
| 29 | var b strings.Builder |
| 30 | b.WriteByte('"') |
| 31 | for k := 0; k < len(s); { |
| 32 | if c := s[k]; c < utf8.RuneSelf { |
| 33 | if safeSet[c] { |
| 34 | b.WriteByte(c) |
| 35 | k++ |
| 36 | continue |
| 37 | } |
| 38 | b.WriteByte('\\') |
| 39 | switch c { |
| 40 | case '\\', '"': |
| 41 | b.WriteByte(c) |
| 42 | case '\b': |
| 43 | b.WriteByte('b') |
| 44 | case '\f': |
| 45 | b.WriteByte('f') |
| 46 | case '\n': |
| 47 | b.WriteByte('n') |
| 48 | case '\r': |
| 49 | b.WriteByte('r') |
| 50 | case '\t': |
| 51 | b.WriteByte('t') |
| 52 | default: |
| 53 | // ASCII control codes other than above |
| 54 | b.WriteString(`u00`) |
| 55 | b.WriteByte(hexdigits[c>>4]) |
| 56 | b.WriteByte(hexdigits[c&0xF]) |
| 57 | } |
| 58 | k++ |
| 59 | continue |
| 60 | } |
| 61 | r, size := utf8.DecodeRuneInString(s[k:]) |
| 62 | if r == utf8.RuneError && size == 1 { |
| 63 | // XXX return an error. See issue #3455. |
| 64 | b.WriteString(`\ufffd`) |
| 65 | k += size |
| 66 | continue |
| 67 | } |
| 68 | b.WriteRune(r) |
| 69 | k += size |
| 70 | } |
| 71 | b.WriteByte('"') |
| 72 | return b.String() |
| 73 | } |
| 74 | |
| 75 | func Unhex(b byte) byte { |
| 76 | switch { |
no test coverage detected