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

Method readObjectKey

reader_parser.go:407–435  ·  view source on GitHub ↗

SYS-REQ-116

(wanted string)

Source from the content-addressed store, hash-verified

405
406// SYS-REQ-116
407func (rp *ReaderParser) readObjectKey(wanted string) (bool, error) {
408 b, err := rp.peekByte(false)
409 if err != nil {
410 return false, err
411 }
412 if b != '"' && !(b == '\'' && rp.config.AllowSingleQuotes) {
413 return false, MalformedJsonError
414 }
415
416 // The parent prefix is no longer needed. Discarding it before retaining the
417 // key ensures that an arbitrarily late key does not grow the window.
418 rp.discardConsumed()
419 start := rp.pos
420 if err := rp.scanString(true); err != nil {
421 return false, err
422 }
423 token := rp.buf[start:rp.pos]
424 body := token[1 : len(token)-1]
425 if bytes.IndexByte(body, '\\') == -1 {
426 return string(body) == wanted, nil
427 }
428
429 var stackbuf [unescapeStackBufSize]byte
430 unescaped, err := unescapeConfig(rp.config, body, stackbuf[:])
431 if err != nil {
432 return false, err
433 }
434 return string(unescaped) == wanted, nil
435}
436
437// SYS-REQ-116
438func (rp *ReaderParser) captureValue() ([]byte, error) {

Callers 1

findObjectValueMethod · 0.95

Calls 4

peekByteMethod · 0.95
discardConsumedMethod · 0.95
scanStringMethod · 0.95
unescapeConfigFunction · 0.85

Tested by

no test coverage detected