1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-27 08:30:57 +02:00

change all negative convert to uint 0

This commit is contained in:
Xargin 2017-07-04 17:02:46 +08:00
parent 712ddb1942
commit 4ea96ac7c3
4 changed files with 12 additions and 15 deletions

View File

@ -99,8 +99,11 @@ func (any *stringAny) ToUint64() uint64 {
startPos := 0
endPos := 0
// uint skip flag, is this correct?
if any.val[0] == '+' || any.val[0] == '-' {
if any.val[0] == '-' {
return 0
}
if any.val[0] == '+' {
startPos = 1
}

View File

@ -21,9 +21,6 @@ func init() {
}
func (iter *Iterator) ReadUint() uint {
if iter.buf[iter.head] == '-' && len(iter.buf) > 1 {
iter.buf = iter.buf[1:]
}
return uint(iter.ReadUint64())
}
@ -107,9 +104,6 @@ func (iter *Iterator) ReadInt32() (ret int32) {
}
func (iter *Iterator) ReadUint32() (ret uint32) {
if iter.buf[iter.head] == '-' && len(iter.buf) > 1 {
iter.buf = iter.buf[1:]
}
return iter.readUint32(iter.nextToken())
}
@ -221,9 +215,6 @@ func (iter *Iterator) ReadInt64() (ret int64) {
}
func (iter *Iterator) ReadUint64() uint64 {
if iter.buf[iter.head] == '-' && len(iter.buf) > 1 {
iter.buf = iter.buf[1:]
}
return iter.readUint64(iter.nextToken())
}

View File

@ -8,6 +8,7 @@ import (
)
var boolConvertMap = map[string]bool{
"null": false,
"true": true,
"false": false,

View File

@ -9,6 +9,7 @@ import (
)
var intConvertMap = map[string]int{
"null": 0,
"321.1": 321,
"-321.1": -321,
`"1.1"`: 1,
@ -58,10 +59,10 @@ func Test_read_any_to_int(t *testing.T) {
}
var uintConvertMap = map[string]int{
"null": 0,
"321.1": 321,
`"1.1"`: 1,
`"-123.1"`: 123,
`"-123.1"`: 0,
"0.0": 0,
"0": 0,
`"0"`: 0,
@ -73,6 +74,7 @@ var uintConvertMap = map[string]int{
`"false"`: 0,
`"true123"`: 0,
`"123true"`: 123,
`"-123true"`: 0,
`"1.2332e6"`: 1,
`""`: 0,
"+": 0,
@ -82,8 +84,8 @@ var uintConvertMap = map[string]int{
"[1,2]": 1,
"{}": 0,
"{1,2}": 0,
"-1.1": 1,
"-321.1": 321,
"-1.1": 0,
"-321.1": 0,
}
func Test_read_any_to_uint(t *testing.T) {