github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/iterator_skip_array.go (about) 1 package jzon 2 3 func skipArrayWithStack(it *Iterator, _ byte) error { 4 c, err := it.nextToken() 5 if err != nil { 6 return err 7 } 8 it.head++ 9 if c == ']' { 10 return nil 11 } 12 for { 13 switch c { 14 case '{': 15 s := stackPool.Get().(*stack).initArray() 16 err = skipWithStack(it, stackElementObjectBegin, s) 17 stackPool.Put(s) 18 return err 19 case '[': 20 s := stackPool.Get().(*stack).initArray() 21 err = skipWithStack(it, stackElementArrayBegin, s) 22 stackPool.Put(s) 23 return err 24 } 25 if err = skipFunctions[c](it, c); err != nil { 26 return err 27 } 28 c, err = it.nextToken() 29 if err != nil { 30 return err 31 } 32 it.head++ 33 if c == ']' { 34 return nil 35 } 36 if c != ',' { 37 return UnexpectedByteError{got: c, exp: ']', exp2: ','} 38 } 39 c, err = it.nextToken() 40 if err != nil { 41 return err 42 } 43 it.head++ 44 } 45 } 46 47 // SkipArray skips an array 48 func (it *Iterator) SkipArray() error { 49 c, err := it.nextToken() 50 if err != nil { 51 return err 52 } 53 if c != '[' { 54 return UnexpectedByteError{got: c, exp: '['} 55 } 56 it.head++ 57 return skipArrayWithStack(it, c) 58 }