summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2018-04-18 21:33:46 -0700
committerAlex Flint <[email protected]>2018-04-18 21:33:46 -0700
commit74dd5a2c5adaae3e3e12734219ed5e1ab2450447 (patch)
treeb9cc728873d0bb83f012388ce43d841aeaddc6d8 /parse.go
parent6f2f3b4bf6c3fb40a0d2200ce6affee56cf781d8 (diff)
separate scalar.CanParse from isBoolean
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/parse.go b/parse.go
index e272b59..80f013c 100644
--- a/parse.go
+++ b/parse.go
@@ -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
func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
- parseable, boolean = isScalar(t)
+ parseable = scalar.CanParse(t)
+ boolean = isBoolean(t)
if parseable {
return
}
@@ -466,7 +467,8 @@ func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
t = t.Elem()
}
- parseable, boolean = isScalar(t)
+ parseable = scalar.CanParse(t)
+ boolean = isBoolean(t)
if parseable {
return
}
@@ -476,7 +478,8 @@ func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
t = t.Elem()
}
- parseable, boolean = isScalar(t)
+ parseable = scalar.CanParse(t)
+ boolean = isBoolean(t)
if parseable {
return
}
@@ -486,17 +489,16 @@ func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
var textUnmarshalerType = reflect.TypeOf([]encoding.TextUnmarshaler{}).Elem()
-// isScalar returns true if the type can be parsed from a single string
-func isScalar(t reflect.Type) (parseable, boolean bool) {
- parseable = scalar.CanParse(t)
+// isBoolean returns true if the type can be parsed from a single string
+func isBoolean(t reflect.Type) bool {
switch {
case t.Implements(textUnmarshalerType):
- return parseable, false
+ return false
case t.Kind() == reflect.Bool:
- return parseable, true
+ return true
case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Bool:
- return parseable, true
+ return true
default:
- return parseable, false
+ return false
}
}