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

Function EachKeyErr

parser.go:784–1010  ·  view source on GitHub ↗

EachKeyErr finds the requested paths and allows the callback to stop iteration by returning an error. io.EOF stops iteration gracefully. SYS-REQ-008

(data []byte, cb func(idx int, value []byte, vt ValueType, err error) error, paths ...[]string)

Source from the content-addressed store, hash-verified

782// iteration by returning an error. io.EOF stops iteration gracefully.
783// SYS-REQ-008
784func EachKeyErr(data []byte, cb func(idx int, value []byte, vt ValueType, err error) error, paths ...[]string) error {
785 var x struct{}
786 var level, pathsMatched, i int
787 ln := len(data)
788
789 pathFlags := make([]bool, stackArraySize)[:]
790 if len(paths) > cap(pathFlags) {
791 pathFlags = make([]bool, len(paths))[:]
792 }
793 pathFlags = pathFlags[0:len(paths)]
794
795 var maxPath int
796 for _, p := range paths {
797 if len(p) > maxPath {
798 maxPath = len(p)
799 }
800 }
801
802 pathsBuf := make([]string, stackArraySize)[:]
803 if maxPath > cap(pathsBuf) {
804 pathsBuf = make([]string, maxPath)[:]
805 }
806 pathsBuf = pathsBuf[0:maxPath]
807
808 for i < ln {
809 switch data[i] {
810 case '"':
811 i++
812 keyBegin := i
813
814 strEnd, keyEscaped := stringEnd(data[i:])
815 if strEnd == -1 {
816 return nil
817 }
818 i += strEnd
819
820 keyEnd := i - 1
821
822 valueOffset := nextToken(data[i:])
823 if valueOffset == -1 {
824 return nil
825 }
826
827 i += valueOffset
828
829 if data[i] == ':' {
830 match := -1
831 key := data[keyBegin:keyEnd]
832
833 var keyUnesc []byte
834 if !keyEscaped {
835 keyUnesc = key
836 } else {
837 var stackbuf [unescapeStackBufSize]byte
838 if ku, unescapeErr := Unescape(key, stackbuf[:]); unescapeErr != nil {
839 return nil
840 } else {
841 keyUnesc = ku

Callers 1

TestEachKeyErrFunction · 0.85

Calls 10

stringEndFunction · 0.85
nextTokenFunction · 0.85
UnescapeFunction · 0.85
sameTreeFunction · 0.85
GetFunction · 0.85
arrayEachErrFunction · 0.85
searchKeysFunction · 0.85
blockEndFunction · 0.85
bytesToStringFunction · 0.70
equalStrFunction · 0.70

Tested by 1

TestEachKeyErrFunction · 0.68