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

Method parseArray

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

Source from the content-addressed store, hash-verified

640}
641
642func (d decoder) parseArray(b []byte) ([]byte, []byte, Kind, error) {
643 if len(b) < 2 {
644 return nil, b[len(b):], Undefined, unexpectedEOF(b)
645 }
646
647 if b[0] != '[' {
648 return nil, b, Undefined, syntaxError(b, "expected '[' at the beginning of array value")
649 }
650
651 var err error
652 a := b
653 n := len(b)
654 i := 0
655
656 b = b[1:]
657 for {
658 b = skipSpaces(b)
659
660 if len(b) == 0 {
661 return nil, b, Undefined, syntaxError(b, "missing closing ']' after array value")
662 }
663
664 if b[0] == ']' {
665 j := (n - len(b)) + 1
666 return a[:j], a[j:], Array, nil
667 }
668
669 if i != 0 {
670 if len(b) == 0 {
671 return nil, b, Undefined, syntaxError(b, "unexpected EOF after array element")
672 }
673 if b[0] != ',' {
674 return nil, b, Undefined, syntaxError(b, "expected ',' after array element but found '%c'", b[0])
675 }
676 b = skipSpaces(b[1:])
677 if len(b) == 0 {
678 return nil, b, Undefined, unexpectedEOF(b)
679 }
680 if b[0] == ']' {
681 return nil, b, Undefined, syntaxError(b, "unexpected trailing comma after object field")
682 }
683 }
684
685 _, b, _, err = d.parseValue(b)
686 if err != nil {
687 return nil, b, Undefined, err
688 }
689
690 i++
691 }
692}
693
694func (d decoder) parseValue(b []byte) ([]byte, []byte, Kind, error) {
695 if len(b) == 0 {

Callers 1

parseValueMethod · 0.95

Calls 4

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

Tested by

no test coverage detected