diff --git a/feature_iter_float.go b/feature_iter_float.go index bf9c3a4..1182ff0 100644 --- a/feature_iter_float.go +++ b/feature_iter_float.go @@ -19,11 +19,13 @@ func init() { for i := int8('0'); i <= int8('9'); i++ { floatDigits[i] = i - int8('0') } - floatDigits[','] = endOfNumber; - floatDigits[']'] = endOfNumber; - floatDigits['}'] = endOfNumber; - floatDigits[' '] = endOfNumber; - floatDigits['.'] = dotInNumber; + floatDigits[','] = endOfNumber + floatDigits[']'] = endOfNumber + floatDigits['}'] = endOfNumber + floatDigits[' '] = endOfNumber + floatDigits['\t'] = endOfNumber + floatDigits['\n'] = endOfNumber + floatDigits['.'] = dotInNumber } func (iter *Iterator) ReadFloat32() (ret float32) { @@ -99,6 +101,7 @@ func (iter *Iterator) readFloat32SlowPath() (ret float32) { str = append(str, c) continue default: + iter.head = i break load_loop } } @@ -190,6 +193,7 @@ func (iter *Iterator) readFloat64SlowPath() (ret float64) { str = append(str, c) continue default: + iter.head = i break load_loop } } diff --git a/feature_iter_object.go b/feature_iter_object.go index 46e8e46..3dd630d 100644 --- a/feature_iter_object.go +++ b/feature_iter_object.go @@ -1,5 +1,7 @@ package jsoniter +import "fmt" + func (iter *Iterator) ReadObject() (ret string) { c := iter.nextToken() switch c { @@ -22,7 +24,7 @@ func (iter *Iterator) ReadObject() (ret string) { case '}': return "" // end of object default: - iter.reportError("ReadObject", `expect { or , or } or n`) + iter.reportError("ReadObject", fmt.Sprintf(`expect { or , or } or n, but found %s`, string([]byte{c}))) return } } diff --git a/jsoniter_demo_test.go b/jsoniter_demo_test.go index ad152dd..ee8592f 100644 --- a/jsoniter_demo_test.go +++ b/jsoniter_demo_test.go @@ -21,32 +21,3 @@ func Test_iterator_api_demo(t *testing.T) { fmt.Println(total) } -type User struct { - userID int - name string - tags []string -} - -func Test_iterator_and_bind_api(t *testing.T) { - iter := ParseString(`[123, {"name": "taowen", "tags": ["crazy", "hacker"]}]`) - user := User{} - iter.ReadArray() - user.userID = iter.ReadInt() - iter.ReadArray() - iter.ReadVal(&user) - iter.ReadArray() // array end - fmt.Println(user) -} - -type TaskBidLog struct { - age int -} - -func Test2(t *testing.T) { - rawString :=` - {"id":0,"bidId":"bid01492692440885","impId":"imp0","taskId":"1024","bidPrice":80,"winPrice":0,"isWon":0,"createTime":1492692440885,"updateTime":null,"device":"","age":30,"gender":"","location":"[中国, 山西, , ]","conType":"0","os":"iOS","osv":"","brand":"","geo":"","ip":"1.68.4.193","idfa":"","waxUserid":""}` - var log TaskBidLog - err := UnmarshalFromString(rawString, &log) - fmt.Println(err) - fmt.Println(log.age) -} diff --git a/jsoniter_float_test.go b/jsoniter_float_test.go index c32e924..9d4f6b7 100644 --- a/jsoniter_float_test.go +++ b/jsoniter_float_test.go @@ -133,6 +133,15 @@ func Test_write_float64(t *testing.T) { should.Equal("abcdefg1.123456", buf.String()) } +func Test_read_float64_cursor(t *testing.T) { + should := require.New(t) + iter := ParseString("[1.23456789\n,2,3]") + should.True(iter.ReadArray()) + should.Equal(1.23456789, iter.Read()) + should.True(iter.ReadArray()) + should.Equal(float64(2), iter.Read()) +} + func Benchmark_jsoniter_float(b *testing.B) { b.ReportAllocs() input := []byte(`1.1123,`)