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

Function arrayEachErr

parser.go:1761–1846  ·  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

1759// EachKeyErr while traversing array-index paths.
1760// SYS-REQ-004
1761func arrayEachErr(data []byte, cb func(value []byte, dataType ValueType, offset int, err error) error, keys ...string) (offset, count int, err error) {
1762 if len(data) == 0 {
1763 return -1, 0, MalformedObjectError
1764 }
1765
1766 nT := nextToken(data)
1767 if nT == -1 {
1768 return -1, 0, MalformedJsonError
1769 }
1770
1771 if len(keys) == 0 && data[nT] != '[' {
1772 return -1, 0, MalformedArrayError
1773 }
1774
1775 offset = nT + 1
1776
1777 if len(keys) > 0 {
1778 if offset = searchKeys(data, keys...); offset == -1 {
1779 return offset, 0, KeyPathNotFoundError
1780 }
1781
1782 nO := nextToken(data[offset:])
1783 if nO == -1 {
1784 return offset, 0, MalformedJsonError
1785 }
1786
1787 offset += nO
1788
1789 if data[offset] != '[' {
1790 return offset, 0, MalformedArrayError
1791 }
1792
1793 offset++
1794 }
1795
1796 nO := nextToken(data[offset:])
1797 if nO == -1 {
1798 return offset, 0, MalformedJsonError
1799 }
1800
1801 offset += nO
1802
1803 if data[offset] == ']' {
1804 return offset, 0, nil
1805 }
1806
1807 for {
1808 v, t, o, parseErr := Get(data[offset:])
1809
1810 if o == 0 {
1811 return offset, count, parseErr
1812 }
1813
1814 count++
1815 if callbackErr := cb(v, t, offset+o-len(v), parseErr); callbackErr != nil {
1816 if errors.Is(callbackErr, io.EOF) {
1817 return offset, count, nil
1818 }

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