jsonStringField does a tiny, dependency-free extraction of a top-level string field from a JSON object. Good enough for plugin.json name/description.
(content, field string)
| 264 | // jsonStringField does a tiny, dependency-free extraction of a top-level string |
| 265 | // field from a JSON object. Good enough for plugin.json name/description. |
| 266 | func jsonStringField(content, field string) string { |
| 267 | needle := "\"" + field + "\"" |
| 268 | idx := strings.Index(content, needle) |
| 269 | if idx < 0 { |
| 270 | return "" |
| 271 | } |
| 272 | rest := content[idx+len(needle):] |
| 273 | colon := strings.Index(rest, ":") |
| 274 | if colon < 0 { |
| 275 | return "" |
| 276 | } |
| 277 | rest = rest[colon+1:] |
| 278 | q1 := strings.Index(rest, "\"") |
| 279 | if q1 < 0 { |
| 280 | return "" |
| 281 | } |
| 282 | rest = rest[q1+1:] |
| 283 | q2 := strings.Index(rest, "\"") |
| 284 | if q2 < 0 { |
| 285 | return "" |
| 286 | } |
| 287 | return rest[:q2] |
| 288 | } |