MCPcopy Create free account
hub / github.com/buger/jsonparser / arrayEachErr

Function arrayEachErr

parser.go:1721–1806  ·  view source on GitHub ↗

arrayEachErr also returns ArrayEach's closing-bracket offset for use by EachKeyErr while traversing array-index paths. SYS-REQ-004

(data []byte, cb func(value []byte, dataType ValueType, offset int, err error) error, keys ...string)

Source from the content-addressed store, hash-verified

1719// EachKeyErr while traversing array-index paths.
1720// SYS-REQ-004
1721func arrayEachErr(data []byte, cb func(value []byte, dataType ValueType, offset int, err error) error, keys ...string) (offset, count int, err error) {
1722 if len(data) == 0 {
1723 return -1, 0, MalformedObjectError
1724 }
1725
1726 nT := nextToken(data)
1727 if nT == -1 {
1728 return -1, 0, MalformedJsonError
1729 }
1730
1731 if len(keys) == 0 && data[nT] != '[' {
1732 return -1, 0, MalformedArrayError
1733 }
1734
1735 offset = nT + 1
1736
1737 if len(keys) > 0 {
1738 if offset = searchKeys(data, keys...); offset == -1 {
1739 return offset, 0, KeyPathNotFoundError
1740 }
1741
1742 nO := nextToken(data[offset:])
1743 if nO == -1 {
1744 return offset, 0, MalformedJsonError
1745 }
1746
1747 offset += nO
1748
1749 if data[offset] != '[' {
1750 return offset, 0, MalformedArrayError
1751 }
1752
1753 offset++
1754 }
1755
1756 nO := nextToken(data[offset:])
1757 if nO == -1 {
1758 return offset, 0, MalformedJsonError
1759 }
1760
1761 offset += nO
1762
1763 if data[offset] == ']' {
1764 return offset, 0, nil
1765 }
1766
1767 for {
1768 v, t, o, parseErr := Get(data[offset:])
1769
1770 if o == 0 {
1771 return offset, count, parseErr
1772 }
1773
1774 count++
1775 if callbackErr := cb(v, t, offset+o-len(v), parseErr); callbackErr != nil {
1776 if errors.Is(callbackErr, io.EOF) {
1777 return offset, count, nil
1778 }

Callers 2

EachKeyErrFunction · 0.85
ArrayEachErrFunction · 0.85

Calls 3

nextTokenFunction · 0.85
searchKeysFunction · 0.85
GetFunction · 0.85

Tested by

no test coverage detected