GetString returns and decodes the string addressed by keys. SYS-REQ-116
(keys ...string)
| 87 | // GetString returns and decodes the string addressed by keys. |
| 88 | // SYS-REQ-116 |
| 89 | func (rp *ReaderParser) GetString(keys ...string) (string, error) { |
| 90 | value, vt, err := rp.Get(keys...) |
| 91 | if err != nil { |
| 92 | return "", err |
| 93 | } |
| 94 | if vt != String { |
| 95 | if vt == Null { |
| 96 | return "", NullValueError |
| 97 | } |
| 98 | return "", valueTypeError("string", value) |
| 99 | } |
| 100 | if bytes.IndexByte(value, '\\') == -1 { |
| 101 | return string(value), nil |
| 102 | } |
| 103 | |
| 104 | var stackbuf [unescapeStackBufSize]byte |
| 105 | unescaped, err := unescapeConfig(rp.config, value, stackbuf[:]) |
| 106 | if err != nil { |
| 107 | return "", MalformedValueError |
| 108 | } |
| 109 | return string(unescaped), nil |
| 110 | } |
| 111 | |
| 112 | // ArrayEach incrementally iterates a root JSON array. Callback value slices are |
| 113 | // valid for the duration of the callback and must be copied if retained. |