SYS-REQ-002, SYS-REQ-071, SYS-REQ-072, SYS-REQ-073, SYS-REQ-074 GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols If key data type do not match, it will return an error.
(data []byte, keys ...string)
| 1237 | // GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols |
| 1238 | // If key data type do not match, it will return an error. |
| 1239 | func GetString(data []byte, keys ...string) (val string, err error) { |
| 1240 | v, t, _, e := Get(data, keys...) |
| 1241 | |
| 1242 | if e != nil { |
| 1243 | return "", e |
| 1244 | } |
| 1245 | |
| 1246 | if t != String { |
| 1247 | if t == Null { |
| 1248 | return "", NullValueError |
| 1249 | } |
| 1250 | return "", fmt.Errorf("Value is not a string: %s", string(v)) |
| 1251 | } |
| 1252 | |
| 1253 | // If no escapes return raw content |
| 1254 | if bytes.IndexByte(v, '\\') == -1 { |
| 1255 | return string(v), nil |
| 1256 | } |
| 1257 | |
| 1258 | return ParseString(v) |
| 1259 | } |
| 1260 | |
| 1261 | // GetFloat returns the value retrieved by `Get`, cast to a float64 if possible. |
| 1262 | // The offset is the same as in `Get`. |
searching dependent graphs…