Skip to content

Commit

Permalink
care empty string by number
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Jun 17, 2017
1 parent 50c6b57 commit 8f2bae0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ func Unmarshal(data []byte, v interface{}) error {
if !ok {
continue
}

potentiallyNull := s == "-" || s == ""
if fv.Kind() == reflect.Ptr {
if fv.IsNil() {
if s == "-" {
if potentiallyNull {
switch fv.Type().Elem().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64:
continue
Expand All @@ -127,7 +127,7 @@ func Unmarshal(data []byte, v interface{}) error {
case reflect.String:
fv.SetString(s)
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
if s == "-" {
if potentiallyNull {
continue
}
i, err := strconv.ParseInt(s, 10, 64)
Expand All @@ -137,7 +137,7 @@ func Unmarshal(data []byte, v interface{}) error {
}
fv.SetInt(i)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
if s == "-" {
if potentiallyNull {
continue
}
i, err := strconv.ParseUint(s, 10, 64)
Expand All @@ -147,7 +147,7 @@ func Unmarshal(data []byte, v interface{}) error {
}
fv.SetUint(i)
case reflect.Float32, reflect.Float64:
if s == "-" {
if potentiallyNull {
continue
}
n, err := strconv.ParseFloat(s, fv.Type().Bits())
Expand Down

0 comments on commit 8f2bae0

Please sign in to comment.