1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-23 11:37:32 +02:00

Merge pull request #210 from coocood/master

add ReadNumber for Iterator.
This commit is contained in:
Tao Wen 2017-12-18 08:22:47 +09:00 committed by GitHub
commit 7b060ec866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package jsoniter package jsoniter
import ( import (
"encoding/json"
"io" "io"
"math/big" "math/big"
"strconv" "strconv"
@ -339,3 +340,8 @@ func validateFloat(str string) string {
} }
return "" return ""
} }
// ReadNumber read json.Number
func (iter *Iterator) ReadNumber() (ret json.Number) {
return json.Number(iter.readNumberAsString())
}

View File

@ -192,6 +192,13 @@ func Test_lossy_float_marshal(t *testing.T) {
should.Equal("0.123457", output) should.Equal("0.123457", output)
} }
func Test_read_number(t *testing.T) {
should := require.New(t)
iter := ParseString(ConfigDefault, `92233720368547758079223372036854775807`)
val := iter.ReadNumber()
should.Equal(`92233720368547758079223372036854775807`, string(val))
}
func Benchmark_jsoniter_float(b *testing.B) { func Benchmark_jsoniter_float(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
input := []byte(`1.1123,`) input := []byte(`1.1123,`)