Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (adapter *Decoder) More() bool {
if iter.Error != nil {
return false
}
c := iter.nextToken()
c := iter.NextToken()
if c == 0 {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion any.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (iter *Iterator) ReadAny() Any {
}

func (iter *Iterator) readAny() Any {
c := iter.nextToken()
c := iter.NextToken()
switch c {
case '"':
iter.unreadByte()
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (cfg *frozenConfig) UnmarshalFromString(str string, v interface{}) error {
iter := cfg.BorrowIterator(data)
defer cfg.ReturnIterator(iter)
iter.ReadVal(v)
c := iter.nextToken()
c := iter.NextToken()
if c == 0 {
if iter.Error == io.EOF {
return nil
Expand All @@ -346,7 +346,7 @@ func (cfg *frozenConfig) Unmarshal(data []byte, v interface{}) error {
iter := cfg.BorrowIterator(data)
defer cfg.ReturnIterator(iter)
iter.ReadVal(v)
c := iter.nextToken()
c := iter.NextToken()
if c == 0 {
if iter.Error == io.EOF {
return nil
Expand Down
6 changes: 3 additions & 3 deletions iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (iter *Iterator) ResetBytes(input []byte) *Iterator {

// WhatIsNext gets ValueType of relatively next json element
func (iter *Iterator) WhatIsNext() ValueType {
valueType := valueTypes[iter.nextToken()]
valueType := valueTypes[iter.NextToken()]
iter.unreadByte()
return valueType
}
Expand All @@ -167,7 +167,7 @@ func (iter *Iterator) skipWhitespacesWithoutLoadMore() bool {
}

func (iter *Iterator) isObjectEnd() bool {
c := iter.nextToken()
c := iter.NextToken()
if c == ',' {
return false
}
Expand All @@ -178,7 +178,7 @@ func (iter *Iterator) isObjectEnd() bool {
return true
}

func (iter *Iterator) nextToken() byte {
func (iter *Iterator) NextToken() byte {
// a variation of skip whitespaces, returning the next non-whitespace token
for {
for i := iter.head; i < iter.tail; i++ {
Expand Down
12 changes: 6 additions & 6 deletions iter_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package jsoniter

// ReadArray read array element, tells if the array has more element to read.
func (iter *Iterator) ReadArray() (ret bool) {
c := iter.nextToken()
c := iter.NextToken()
switch c {
case 'n':
iter.skipThreeBytes('u', 'l', 'l')
return false // null
case '[':
c = iter.nextToken()
c = iter.NextToken()
if c != ']' {
iter.unreadByte()
return true
Expand All @@ -26,25 +26,25 @@ func (iter *Iterator) ReadArray() (ret bool) {

// ReadArrayCB read array with callback
func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool) {
c := iter.nextToken()
c := iter.NextToken()
if c == '[' {
if !iter.incrementDepth() {
return false
}
c = iter.nextToken()
c = iter.NextToken()
if c != ']' {
iter.unreadByte()
if !callback(iter) {
iter.decrementDepth()
return false
}
c = iter.nextToken()
c = iter.NextToken()
for c == ',' {
if !callback(iter) {
iter.decrementDepth()
return false
}
c = iter.nextToken()
c = iter.NextToken()
}
if c != ']' {
iter.ReportError("ReadArrayCB", "expect ] in the end, but found "+string([]byte{c}))
Expand Down
4 changes: 2 additions & 2 deletions iter_float.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (iter *Iterator) ReadBigInt() (ret *big.Int) {

//ReadFloat32 read float32
func (iter *Iterator) ReadFloat32() (ret float32) {
c := iter.nextToken()
c := iter.NextToken()
if c == '-' {
return -iter.readPositiveFloat32()
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (iter *Iterator) readFloat32SlowPath() (ret float32) {

// ReadFloat64 read float64
func (iter *Iterator) ReadFloat64() (ret float64) {
c := iter.nextToken()
c := iter.NextToken()
if c == '-' {
return -iter.readPositiveFloat64()
}
Expand Down
16 changes: 8 additions & 8 deletions iter_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (iter *Iterator) ReadInt() int {

// ReadInt8 read int8
func (iter *Iterator) ReadInt8() (ret int8) {
c := iter.nextToken()
c := iter.NextToken()
if c == '-' {
val := iter.readUint32(iter.readByte())
if val > math.MaxInt8+1 {
Expand All @@ -57,7 +57,7 @@ func (iter *Iterator) ReadInt8() (ret int8) {

// ReadUint8 read uint8
func (iter *Iterator) ReadUint8() (ret uint8) {
val := iter.readUint32(iter.nextToken())
val := iter.readUint32(iter.NextToken())
if val > math.MaxUint8 {
iter.ReportError("ReadUint8", "overflow: "+strconv.FormatInt(int64(val), 10))
return
Expand All @@ -67,7 +67,7 @@ func (iter *Iterator) ReadUint8() (ret uint8) {

// ReadInt16 read int16
func (iter *Iterator) ReadInt16() (ret int16) {
c := iter.nextToken()
c := iter.NextToken()
if c == '-' {
val := iter.readUint32(iter.readByte())
if val > math.MaxInt16+1 {
Expand All @@ -86,7 +86,7 @@ func (iter *Iterator) ReadInt16() (ret int16) {

// ReadUint16 read uint16
func (iter *Iterator) ReadUint16() (ret uint16) {
val := iter.readUint32(iter.nextToken())
val := iter.readUint32(iter.NextToken())
if val > math.MaxUint16 {
iter.ReportError("ReadUint16", "overflow: "+strconv.FormatInt(int64(val), 10))
return
Expand All @@ -96,7 +96,7 @@ func (iter *Iterator) ReadUint16() (ret uint16) {

// ReadInt32 read int32
func (iter *Iterator) ReadInt32() (ret int32) {
c := iter.nextToken()
c := iter.NextToken()
if c == '-' {
val := iter.readUint32(iter.readByte())
if val > math.MaxInt32+1 {
Expand All @@ -115,7 +115,7 @@ func (iter *Iterator) ReadInt32() (ret int32) {

// ReadUint32 read uint32
func (iter *Iterator) ReadUint32() (ret uint32) {
return iter.readUint32(iter.nextToken())
return iter.readUint32(iter.NextToken())
}

func (iter *Iterator) readUint32(c byte) (ret uint32) {
Expand Down Expand Up @@ -218,7 +218,7 @@ func (iter *Iterator) readUint32(c byte) (ret uint32) {

// ReadInt64 read int64
func (iter *Iterator) ReadInt64() (ret int64) {
c := iter.nextToken()
c := iter.NextToken()
if c == '-' {
val := iter.readUint64(iter.readByte())
if val > math.MaxInt64+1 {
Expand All @@ -237,7 +237,7 @@ func (iter *Iterator) ReadInt64() (ret int64) {

// ReadUint64 read uint64
func (iter *Iterator) ReadUint64() uint64 {
return iter.readUint64(iter.nextToken())
return iter.readUint64(iter.NextToken())
}

func (iter *Iterator) readUint64(c byte) (ret uint64) {
Expand Down
42 changes: 21 additions & 21 deletions iter_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
// If object ended, returns empty string.
// Otherwise, returns the field name.
func (iter *Iterator) ReadObject() (ret string) {
c := iter.nextToken()
c := iter.NextToken()
switch c {
case 'n':
iter.skipThreeBytes('u', 'l', 'l')
return "" // null
case '{':
c = iter.nextToken()
c = iter.NextToken()
if c == '"' {
iter.unreadByte()
field := iter.ReadString()
c = iter.nextToken()
c = iter.NextToken()
if c != ':' {
iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
}
Expand All @@ -32,7 +32,7 @@ func (iter *Iterator) ReadObject() (ret string) {
return
case ',':
field := iter.ReadString()
c = iter.nextToken()
c = iter.NextToken()
if c != ':' {
iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
}
Expand All @@ -48,7 +48,7 @@ func (iter *Iterator) ReadObject() (ret string) {
// CaseInsensitive
func (iter *Iterator) readFieldHash() int64 {
hash := int64(0x811c9dc5)
c := iter.nextToken()
c := iter.NextToken()
if c != '"' {
iter.ReportError("readFieldHash", `expect ", but found `+string([]byte{c}))
return 0
Expand All @@ -66,7 +66,7 @@ func (iter *Iterator) readFieldHash() int64 {
hash ^= int64(b)
hash *= 0x1000193
}
c = iter.nextToken()
c = iter.NextToken()
if c != ':' {
iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c}))
return 0
Expand All @@ -75,7 +75,7 @@ func (iter *Iterator) readFieldHash() int64 {
}
if b == '"' {
iter.head = i + 1
c = iter.nextToken()
c = iter.NextToken()
if c != ':' {
iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c}))
return 0
Expand Down Expand Up @@ -109,36 +109,36 @@ func calcHash(str string, caseSensitive bool) int64 {

// ReadObjectCB read object with callback, the key is ascii only and field name not copied
func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool {
c := iter.nextToken()
c := iter.NextToken()
var field string
if c == '{' {
if !iter.incrementDepth() {
return false
}
c = iter.nextToken()
c = iter.NextToken()
if c == '"' {
iter.unreadByte()
field = iter.ReadString()
c = iter.nextToken()
c = iter.NextToken()
if c != ':' {
iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
}
if !callback(iter, field) {
iter.decrementDepth()
return false
}
c = iter.nextToken()
c = iter.NextToken()
for c == ',' {
field = iter.ReadString()
c = iter.nextToken()
c = iter.NextToken()
if c != ':' {
iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
}
if !callback(iter, field) {
iter.decrementDepth()
return false
}
c = iter.nextToken()
c = iter.NextToken()
}
if c != '}' {
iter.ReportError("ReadObjectCB", `object not ended with }`)
Expand All @@ -164,16 +164,16 @@ func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool {

// ReadMapCB read map with callback, the key can be any string
func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool {
c := iter.nextToken()
c := iter.NextToken()
if c == '{' {
if !iter.incrementDepth() {
return false
}
c = iter.nextToken()
c = iter.NextToken()
if c == '"' {
iter.unreadByte()
field := iter.ReadString()
if iter.nextToken() != ':' {
if iter.NextToken() != ':' {
iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c}))
iter.decrementDepth()
return false
Expand All @@ -182,10 +182,10 @@ func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool {
iter.decrementDepth()
return false
}
c = iter.nextToken()
c = iter.NextToken()
for c == ',' {
field = iter.ReadString()
if iter.nextToken() != ':' {
if iter.NextToken() != ':' {
iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c}))
iter.decrementDepth()
return false
Expand All @@ -194,7 +194,7 @@ func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool {
iter.decrementDepth()
return false
}
c = iter.nextToken()
c = iter.NextToken()
}
if c != '}' {
iter.ReportError("ReadMapCB", `object not ended with }`)
Expand All @@ -219,9 +219,9 @@ func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool {
}

func (iter *Iterator) readObjectStart() bool {
c := iter.nextToken()
c := iter.NextToken()
if c == '{' {
c = iter.nextToken()
c = iter.NextToken()
if c == '}' {
return false
}
Expand Down
6 changes: 3 additions & 3 deletions iter_skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "fmt"
// ReadNil reads a json object as nil and
// returns whether it's a nil or not
func (iter *Iterator) ReadNil() (ret bool) {
c := iter.nextToken()
c := iter.NextToken()
if c == 'n' {
iter.skipThreeBytes('u', 'l', 'l') // null
return true
Expand All @@ -16,7 +16,7 @@ func (iter *Iterator) ReadNil() (ret bool) {

// ReadBool reads a json object as BoolValue
func (iter *Iterator) ReadBool() (ret bool) {
c := iter.nextToken()
c := iter.NextToken()
if c == 't' {
iter.skipThreeBytes('r', 'u', 'e')
return true
Expand Down Expand Up @@ -70,7 +70,7 @@ func (iter *Iterator) stopCapture() []byte {

// Skip skips a json object and positions to relatively the next json object
func (iter *Iterator) Skip() {
c := iter.nextToken()
c := iter.NextToken()
switch c {
case '"':
iter.skipString()
Expand Down
4 changes: 2 additions & 2 deletions iter_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// ReadString read string from iterator
func (iter *Iterator) ReadString() (ret string) {
c := iter.nextToken()
c := iter.NextToken()
if c == '"' {
for i := iter.head; i < iter.tail; i++ {
c := iter.buf[i]
Expand Down Expand Up @@ -114,7 +114,7 @@ func (iter *Iterator) readEscapedChar(c byte, str []byte) []byte {
// ReadStringAsSlice read string from iterator without copying into string form.
// The []byte can not be kept, as it will change after next iterator call.
func (iter *Iterator) ReadStringAsSlice() (ret []byte) {
c := iter.nextToken()
c := iter.NextToken()
if c == '"' {
for i := iter.head; i < iter.tail; i++ {
// require ascii string and no escape
Expand Down
Loading