MCPcopy Index your code
hub / github.com/segmentio/encoding / parseObject

Method parseObject

json/parse.go:576–640  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

574}
575
576func (d decoder) parseObject(b []byte) ([]byte, []byte, Kind, error) {
577 if len(b) < 2 {
578 return nil, b[len(b):], Undefined, unexpectedEOF(b)
579 }
580
581 if b[0] != '{' {
582 return nil, b, Undefined, syntaxError(b, "expected '{' at the beginning of an object value")
583 }
584
585 var err error
586 a := b
587 n := len(b)
588 i := 0
589
590 b = b[1:]
591 for {
592 b = skipSpaces(b)
593
594 if len(b) == 0 {
595 return nil, b, Undefined, syntaxError(b, "cannot decode object from empty input")
596 }
597
598 if b[0] == '}' {
599 j := (n - len(b)) + 1
600 return a[:j], a[j:], Object, nil
601 }
602
603 if i != 0 {
604 if len(b) == 0 {
605 return nil, b, Undefined, syntaxError(b, "unexpected EOF after object field value")
606 }
607 if b[0] != ',' {
608 return nil, b, Undefined, syntaxError(b, "expected ',' after object field value but found '%c'", b[0])
609 }
610 b = skipSpaces(b[1:])
611 if len(b) == 0 {
612 return nil, b, Undefined, unexpectedEOF(b)
613 }
614 if b[0] == '}' {
615 return nil, b, Undefined, syntaxError(b, "unexpected trailing comma after object field")
616 }
617 }
618
619 _, b, _, err = d.parseString(b)
620 if err != nil {
621 return nil, b, Undefined, err
622 }
623 b = skipSpaces(b)
624
625 if len(b) == 0 {
626 return nil, b, Undefined, syntaxError(b, "unexpected EOF after object field key")
627 }
628 if b[0] != ':' {
629 return nil, b, Undefined, syntaxError(b, "expected ':' after object field key but found '%c'", b[0])
630 }
631 b = skipSpaces(b[1:])
632
633 _, b, _, err = d.parseValue(b)

Callers 1

parseValueMethod · 0.95

Calls 5

parseStringMethod · 0.95
parseValueMethod · 0.95
unexpectedEOFFunction · 0.85
syntaxErrorFunction · 0.85
skipSpacesFunction · 0.85

Tested by

no test coverage detected