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

Function searchKeysConfig

parser.go:413–566  ·  view source on GitHub ↗

SYS-REQ-115

(config Config, data []byte, keys ...string)

Source from the content-addressed store, hash-verified

411
412// SYS-REQ-115
413func searchKeysConfig(config Config, data []byte, keys ...string) int {
414 keyLevel := 0
415 level := 0
416 i := 0
417 ln := len(data)
418 lk := len(keys)
419 lastMatched := true
420
421 if lk == 0 {
422 return 0
423 }
424
425 var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings
426
427 for i < ln {
428 switch data[i] {
429 case '"', '\'':
430 quote := data[i]
431 if quote == '\'' && !config.AllowSingleQuotes {
432 break
433 }
434 i++
435 keyBegin := i
436
437 strEnd, keyEscaped := stringEndConfig(config, data[i:], quote)
438 if strEnd == -1 {
439 return -1
440 }
441 i += strEnd
442 keyEnd := i - 1
443
444 valueOffset := nextTokenConfig(config, data[i:])
445 if valueOffset == -1 {
446 return -1
447 }
448
449 i += valueOffset
450
451 // if string is a key
452 if data[i] == ':' {
453 if level < 1 {
454 return -1
455 }
456
457 key := data[keyBegin:keyEnd]
458
459 // for unescape: if there are no escape sequences, this is cheap; if there are, it is a
460 // bit more expensive, but causes no allocations unless len(key) > unescapeStackBufSize
461 var keyUnesc []byte
462 if !keyEscaped {
463 keyUnesc = key
464 } else if ku, err := unescapeConfig(config, key, stackbuf[:]); err != nil {
465 return -1
466 } else {
467 keyUnesc = ku
468 }
469
470 if level <= len(keys) {

Callers 4

searchKeysFunction · 0.85
internalGetConfigFunction · 0.85
arrayEachConfigFunction · 0.85
objectEachConfigFunction · 0.85

Calls 6

stringEndConfigFunction · 0.85
nextTokenConfigFunction · 0.85
unescapeConfigFunction · 0.85
blockEndConfigFunction · 0.85
arrayEachConfigFunction · 0.85
equalStrFunction · 0.70

Tested by

no test coverage detected