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

Function arrayEachErr

parser.go:1815–1900  ·  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

1813// EachKeyErr while traversing array-index paths.
1814// SYS-REQ-004
1815func arrayEachErr(data []byte, cb func(value []byte, dataType ValueType, offset int, err error) error, keys ...string) (offset, count int, err error) {
1816 if len(data) == 0 {
1817 return -1, 0, MalformedObjectError
1818 }
1819
1820 nT := nextToken(data)
1821 if nT == -1 {
1822 return -1, 0, MalformedJsonError
1823 }
1824
1825 if len(keys) == 0 && data[nT] != '[' {
1826 return -1, 0, MalformedArrayError
1827 }
1828
1829 offset = nT + 1
1830
1831 if len(keys) > 0 {
1832 if offset = searchKeys(data, keys...); offset == -1 {
1833 return offset, 0, KeyPathNotFoundError
1834 }
1835
1836 nO := nextToken(data[offset:])
1837 if nO == -1 {
1838 return offset, 0, MalformedJsonError
1839 }
1840
1841 offset += nO
1842
1843 if data[offset] != '[' {
1844 return offset, 0, MalformedArrayError
1845 }
1846
1847 offset++
1848 }
1849
1850 nO := nextToken(data[offset:])
1851 if nO == -1 {
1852 return offset, 0, MalformedJsonError
1853 }
1854
1855 offset += nO
1856
1857 if data[offset] == ']' {
1858 return offset, 0, nil
1859 }
1860
1861 for {
1862 v, t, o, parseErr := Get(data[offset:])
1863
1864 if o == 0 {
1865 return offset, count, parseErr
1866 }
1867
1868 count++
1869 if callbackErr := cb(v, t, offset+o-len(v), parseErr); callbackErr != nil {
1870 if errors.Is(callbackErr, io.EOF) {
1871 return offset, count, nil
1872 }

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