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

Function arrayEachErr

parser.go:1702–1787  ·  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

1700// EachKeyErr while traversing array-index paths.
1701// SYS-REQ-004
1702func arrayEachErr(data []byte, cb func(value []byte, dataType ValueType, offset int, err error) error, keys ...string) (offset, count int, err error) {
1703 if len(data) == 0 {
1704 return -1, 0, MalformedObjectError
1705 }
1706
1707 nT := nextToken(data)
1708 if nT == -1 {
1709 return -1, 0, MalformedJsonError
1710 }
1711
1712 if len(keys) == 0 && data[nT] != '[' {
1713 return -1, 0, MalformedArrayError
1714 }
1715
1716 offset = nT + 1
1717
1718 if len(keys) > 0 {
1719 if offset = searchKeys(data, keys...); offset == -1 {
1720 return offset, 0, KeyPathNotFoundError
1721 }
1722
1723 nO := nextToken(data[offset:])
1724 if nO == -1 {
1725 return offset, 0, MalformedJsonError
1726 }
1727
1728 offset += nO
1729
1730 if data[offset] != '[' {
1731 return offset, 0, MalformedArrayError
1732 }
1733
1734 offset++
1735 }
1736
1737 nO := nextToken(data[offset:])
1738 if nO == -1 {
1739 return offset, 0, MalformedJsonError
1740 }
1741
1742 offset += nO
1743
1744 if data[offset] == ']' {
1745 return offset, 0, nil
1746 }
1747
1748 for {
1749 v, t, o, parseErr := Get(data[offset:])
1750
1751 if o == 0 {
1752 return offset, count, parseErr
1753 }
1754
1755 count++
1756 if callbackErr := cb(v, t, offset+o-len(v), parseErr); callbackErr != nil {
1757 if errors.Is(callbackErr, io.EOF) {
1758 return offset, count, nil
1759 }

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