-
Notifications
You must be signed in to change notification settings - Fork 2
/
iterator_skip_array.go
58 lines (56 loc) · 1.03 KB
/
iterator_skip_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
51
52
53
54
55
56
57
58
package jzon
func skipArrayWithStack(it *Iterator, _ byte) error {
c, err := it.nextToken()
if err != nil {
return err
}
it.head++
if c == ']' {
return nil
}
for {
switch c {
case '{':
s := stackPool.Get().(*stack).initArray()
err = skipWithStack(it, stackElementObjectBegin, s)
stackPool.Put(s)
return err
case '[':
s := stackPool.Get().(*stack).initArray()
err = skipWithStack(it, stackElementArrayBegin, s)
stackPool.Put(s)
return err
}
if err = skipFunctions[c](it, c); err != nil {
return err
}
c, err = it.nextToken()
if err != nil {
return err
}
it.head++
if c == ']' {
return nil
}
if c != ',' {
return UnexpectedByteError{got: c, exp: ']', exp2: ','}
}
c, err = it.nextToken()
if err != nil {
return err
}
it.head++
}
}
// SkipArray skips an array
func (it *Iterator) SkipArray() error {
c, err := it.nextToken()
if err != nil {
return err
}
if c != '[' {
return UnexpectedByteError{got: c, exp: '['}
}
it.head++
return skipArrayWithStack(it, c)
}