forked from json-iterator/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_iter_array.go
50 lines (48 loc) · 937 Bytes
/
feature_iter_array.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package jsoniter
func (iter *Iterator) ReadArray() (ret bool) {
c := iter.nextToken()
switch c {
case 'n':
iter.skipFixedBytes(3)
return false // null
case '[':
c = iter.nextToken()
if c != ']' {
iter.unreadByte()
return true
}
return false
case ']':
return false
case ',':
return true
default:
iter.reportError("ReadArray", "expect [ or , or ] or n, but found: "+string([]byte{c}))
return
}
}
func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool) {
c := iter.nextToken()
if c == '[' {
c = iter.nextToken()
if c != ']' {
iter.unreadByte()
if !callback(iter) {
return false
}
for iter.nextToken() == ',' {
if !callback(iter) {
return false
}
}
return true
}
return true
}
if c == 'n' {
iter.skipFixedBytes(3)
return true // null
}
iter.reportError("ReadArrayCB", "expect [ or n, but found: "+string([]byte{c}))
return false
}