MCPcopy Index your code
hub / github.com/aarondl/sqlboiler / parseArray

Function parseArray

types/array.go:1176–1279  ·  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

1174//
1175// See http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO
1176func parseArray(src, del []byte) (dims []int, elems [][]byte, err error) {
1177 var depth, i int
1178
1179 if len(src) < 1 || src[0] != '{' {
1180 return nil, nil, fmt.Errorf("boil: unable to parse array; expected %q at offset %d", '{', 0)
1181 }
1182
1183Open:
1184 for i < len(src) {
1185 switch src[i] {
1186 case '{':
1187 depth++
1188 i++
1189 case '}':
1190 elems = make([][]byte, 0)
1191 goto Close
1192 default:
1193 break Open
1194 }
1195 }
1196 dims = make([]int, i)
1197
1198Element:
1199 for i < len(src) {
1200 switch src[i] {
1201 case '{':
1202 if depth == len(dims) {
1203 break Element
1204 }
1205 depth++
1206 dims[depth-1] = 0
1207 i++
1208 case '"':
1209 var elem = []byte{}
1210 var escape bool
1211 for i++; i < len(src); i++ {
1212 if escape {
1213 elem = append(elem, src[i])
1214 escape = false
1215 } else {
1216 switch src[i] {
1217 default:
1218 elem = append(elem, src[i])
1219 case '\\':
1220 escape = true
1221 case '"':
1222 elems = append(elems, elem)
1223 i++
1224 break Element
1225 }
1226 }
1227 }
1228 default:
1229 for start := i; i < len(src); i++ {
1230 if bytes.HasPrefix(src[i:], del) || src[i] == '}' {
1231 elem := src[start:i]
1232 if len(elem) == 0 {
1233 return nil, nil, fmt.Errorf("boil: unable to parse array; unexpected %q at offset %d", src[i], i)

Callers 4

scanBytesMethod · 0.85
scanLinearArrayFunction · 0.85
TestParseArrayFunction · 0.85
TestParseArrayErrorFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestParseArrayFunction · 0.68
TestParseArrayErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…