mirror of
https://github.com/json-iterator/go.git
synced 2024-11-24 08:22:14 +02:00
fix readFloat64SlowPath not advancing the cursor
This commit is contained in:
parent
ccb972f58c
commit
90888390bc
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,`)
|
||||
|
Loading…
Reference in New Issue
Block a user