MCPcopy Index your code
hub / github.com/lib/pq / parseArray

Function parseArray

array.go:789–892  ·  view source on GitHub ↗

parseArray extracts the dimensions and elements of an array represented in text format. Only representations emitted by the backend are supported. Notably, whitespace around brackets and delimiters is significant, and NULL is case-sensitive. See http://www.postgresql.org/docs/current/static/arrays.

(src, del []byte)

Source from the content-addressed store, hash-verified

787//
788// See http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO
789func parseArray(src, del []byte) (dims []int, elems [][]byte, err error) {
790 var depth, i int
791
792 if len(src) < 1 || src[0] != '{' {
793 return nil, nil, fmt.Errorf("pq: unable to parse array; expected %q at offset %d", '{', 0)
794 }
795
796Open:
797 for i < len(src) {
798 switch src[i] {
799 case '{':
800 depth++
801 i++
802 case '}':
803 elems = make([][]byte, 0)
804 goto Close
805 default:
806 break Open
807 }
808 }
809 dims = make([]int, i)
810
811Element:
812 for i < len(src) {
813 switch src[i] {
814 case '{':
815 if depth == len(dims) {
816 break Element
817 }
818 depth++
819 dims[depth-1] = 0
820 i++
821 case '"':
822 var elem = []byte{}
823 var escape bool
824 for i++; i < len(src); i++ {
825 if escape {
826 elem = append(elem, src[i])
827 escape = false
828 } else {
829 switch src[i] {
830 default:
831 elem = append(elem, src[i])
832 case '\\':
833 escape = true
834 case '"':
835 elems = append(elems, elem)
836 i++
837 break Element
838 }
839 }
840 }
841 default:
842 for start := i; i < len(src); i++ {
843 if bytes.HasPrefix(src[i:], del) || src[i] == '}' {
844 elem := src[start:i]
845 if len(elem) == 0 {
846 return nil, nil, fmt.Errorf("pq: unable to parse array; unexpected %q at offset %d", src[i], i)

Callers 5

scanBytesMethod · 0.85
scanLinearArrayFunction · 0.85
FuzzParseArrayFunction · 0.85
TestArrayParseFunction · 0.85
TestArrayParseErrorFunction · 0.85

Calls

no outgoing calls

Tested by 3

FuzzParseArrayFunction · 0.68
TestArrayParseFunction · 0.68
TestArrayParseErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…