blob: 6188cb4577abc586520658f45425f1432886263f [file] [log] [blame]
khenaidoo59ce9dd2019-11-11 13:05:32 -05001package jsoniter
2
3// ReadArray read array element, tells if the array has more element to read.
4func (iter *Iterator) ReadArray() (ret bool) {
5 c := iter.nextToken()
6 switch c {
7 case 'n':
8 iter.skipThreeBytes('u', 'l', 'l')
9 return false // null
10 case '[':
11 c = iter.nextToken()
12 if c != ']' {
13 iter.unreadByte()
14 return true
15 }
16 return false
17 case ']':
18 return false
19 case ',':
20 return true
21 default:
22 iter.ReportError("ReadArray", "expect [ or , or ] or n, but found "+string([]byte{c}))
23 return
24 }
25}
26
27// ReadArrayCB read array with callback
28func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool) {
29 c := iter.nextToken()
30 if c == '[' {
31 c = iter.nextToken()
32 if c != ']' {
33 iter.unreadByte()
34 if !callback(iter) {
35 return false
36 }
37 c = iter.nextToken()
38 for c == ',' {
39 if !callback(iter) {
40 return false
41 }
42 c = iter.nextToken()
43 }
44 if c != ']' {
45 iter.ReportError("ReadArrayCB", "expect ] in the end, but found "+string([]byte{c}))
46 return false
47 }
48 return true
49 }
50 return true
51 }
52 if c == 'n' {
53 iter.skipThreeBytes('u', 'l', 'l')
54 return true // null
55 }
56 iter.ReportError("ReadArrayCB", "expect [ or n, but found "+string([]byte{c}))
57 return false
58}