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

Function blockEnd

parser.go:330–357  ·  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

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

Callers 6

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

Calls 1

stringEndFunction · 0.85

Tested by 2

TestBlockEndSentinelFunction · 0.68