separate scalar.CanParse from isBoolean

This commit is contained in:
Alex Flint 2018-04-18 21:33:46 -07:00
parent 6f2f3b4bf6
commit 74dd5a2c5a
1 changed files with 12 additions and 10 deletions

View File

@ -451,7 +451,8 @@ func setSlice(dest reflect.Value, values []string, trunc bool) error {
// canParse returns true if the type can be parsed from a string // canParse returns true if the type can be parsed from a string
func canParse(t reflect.Type) (parseable, boolean, multiple bool) { func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
parseable, boolean = isScalar(t) parseable = scalar.CanParse(t)
boolean = isBoolean(t)
if parseable { if parseable {
return return
} }
@ -466,7 +467,8 @@ func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
t = t.Elem() t = t.Elem()
} }
parseable, boolean = isScalar(t) parseable = scalar.CanParse(t)
boolean = isBoolean(t)
if parseable { if parseable {
return return
} }
@ -476,7 +478,8 @@ func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
t = t.Elem() t = t.Elem()
} }
parseable, boolean = isScalar(t) parseable = scalar.CanParse(t)
boolean = isBoolean(t)
if parseable { if parseable {
return return
} }
@ -486,17 +489,16 @@ func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
var textUnmarshalerType = reflect.TypeOf([]encoding.TextUnmarshaler{}).Elem() var textUnmarshalerType = reflect.TypeOf([]encoding.TextUnmarshaler{}).Elem()
// isScalar returns true if the type can be parsed from a single string // isBoolean returns true if the type can be parsed from a single string
func isScalar(t reflect.Type) (parseable, boolean bool) { func isBoolean(t reflect.Type) bool {
parseable = scalar.CanParse(t)
switch { switch {
case t.Implements(textUnmarshalerType): case t.Implements(textUnmarshalerType):
return parseable, false return false
case t.Kind() == reflect.Bool: case t.Kind() == reflect.Bool:
return parseable, true return true
case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Bool: case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Bool:
return parseable, true return true
default: default:
return parseable, false return false
} }
} }