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

Function blockEnd

parser.go:331–358  ·  view source on GitHub ↗

SYS-REQ-046 Find end of the data structure, array or object. For array openSym and closeSym will be '[' and ']', for object '{' and '}'

(data []byte, openSym byte, closeSym byte)

Source from the content-addressed store, hash-verified

329// Find end of the data structure, array or object.
330// For array openSym and closeSym will be '[' and ']', for object '{' and '}'
331func blockEnd(data []byte, openSym byte, closeSym byte) int {
332 level := 0
333 i := 0
334 ln := len(data)
335
336 for i < ln {
337 switch data[i] {
338 case '"': // If inside string, skip it
339 se, _ := stringEnd(data[i+1:])
340 if se == -1 {
341 return -1
342 }
343 i += se
344 case openSym: // If open symbol, increase level
345 level++
346 case closeSym: // If close symbol, increase level
347 level--
348
349 // If we have returned to the original level, we're done
350 if level == 0 {
351 return i + 1
352 }
353 }
354 i++
355 }
356
357 return -1
358}
359
360// SYS-REQ-001, SYS-REQ-020, SYS-REQ-021, SYS-REQ-022, SYS-REQ-023, SYS-REQ-047, SYS-REQ-111
361func searchKeys(data []byte, keys ...string) int {

Callers 7

findKeyStartFunction · 0.85
searchKeysFunction · 0.85
EachKeyFunction · 0.85
EachKeyErrFunction · 0.85
getTypeFunction · 0.85
TestBlockEndSentinelFunction · 0.85

Calls 1

stringEndFunction · 0.85

Tested by 2

TestBlockEndSentinelFunction · 0.68