mirror of
https://github.com/json-iterator/go.git
synced 2024-11-24 08:22:14 +02:00
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package jsoniter
|
|
|
|
// ReadArray read array element, tells if the array has more element to read.
|
|
func (iter *Iterator) ReadArray() (ret bool) {
|
|
c := iter.nextToken()
|
|
switch c {
|
|
case 'n':
|
|
iter.skipThreeBytes('u', 'l', 'l')
|
|
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
|
|
}
|
|
}
|
|
|
|
// ReadArrayCB read array with callback
|
|
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.skipThreeBytes('u', 'l', 'l')
|
|
return true // null
|
|
}
|
|
iter.ReportError("ReadArrayCB", "expect [ or n, but found: "+string([]byte{c}))
|
|
return false
|
|
}
|