feature_iter_array.go 937 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package jsoniter
  2. func (iter *Iterator) ReadArray() (ret bool) {
  3. c := iter.nextToken()
  4. switch c {
  5. case 'n':
  6. iter.skipFixedBytes(3)
  7. return false // null
  8. case '[':
  9. c = iter.nextToken()
  10. if c != ']' {
  11. iter.unreadByte()
  12. return true
  13. }
  14. return false
  15. case ']':
  16. return false
  17. case ',':
  18. return true
  19. default:
  20. iter.reportError("ReadArray", "expect [ or , or ] or n, but found: "+string([]byte{c}))
  21. return
  22. }
  23. }
  24. func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool) {
  25. c := iter.nextToken()
  26. if c == '[' {
  27. c = iter.nextToken()
  28. if c != ']' {
  29. iter.unreadByte()
  30. if !callback(iter) {
  31. return false
  32. }
  33. for iter.nextToken() == ',' {
  34. if !callback(iter) {
  35. return false
  36. }
  37. }
  38. return true
  39. }
  40. return true
  41. }
  42. if c == 'n' {
  43. iter.skipFixedBytes(3)
  44. return true // null
  45. }
  46. iter.reportError("ReadArrayCB", "expect [ or n, but found: "+string([]byte{c}))
  47. return false
  48. }