parseJSONLegacy is the original decoder-based JSON parsing (kept for compatibility)
(s string)
| 379 | |
| 380 | // parseJSONLegacy is the original decoder-based JSON parsing (kept for compatibility) |
| 381 | func parseJSONLegacy(s string) ([]map[string]any, error) { |
| 382 | var objs []map[string]any |
| 383 | offset := 0 |
| 384 | |
| 385 | for offset < len(s) { |
| 386 | var obj map[string]any |
| 387 | decoder := json.NewDecoder(strings.NewReader(s[offset:])) |
| 388 | |
| 389 | err := decoder.Decode(&obj) |
| 390 | switch { |
| 391 | case errors.Is(err, io.EOF): |
| 392 | return objs, nil |
| 393 | case err == nil: |
| 394 | offset += int(decoder.InputOffset()) |
| 395 | objs = append(objs, obj) |
| 396 | default: // handle the error type |
| 397 | var syntaxErr *json.SyntaxError |
| 398 | var unmarshalTypeErr *json.UnmarshalTypeError |
| 399 | |
| 400 | switch { |
| 401 | case errors.As(err, &syntaxErr): |
| 402 | offset += int(syntaxErr.Offset) |
| 403 | case errors.As(err, &unmarshalTypeErr): |
| 404 | offset += int(unmarshalTypeErr.Offset) |
| 405 | default: |
| 406 | return objs, err |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | return objs, nil |
| 412 | } |
| 413 | |
| 414 | // GetXMLFormatPreset returns a preset XML format by name, or nil if not found |
| 415 | // This is exported for use in chat.go streaming integration |
no test coverage detected