diff options
| author | Alex Flint <[email protected]> | 2018-04-18 21:33:46 -0700 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2018-04-18 21:33:46 -0700 |
| commit | 74dd5a2c5adaae3e3e12734219ed5e1ab2450447 (patch) | |
| tree | b9cc728873d0bb83f012388ce43d841aeaddc6d8 /parse.go | |
| parent | 6f2f3b4bf6c3fb40a0d2200ce6affee56cf781d8 (diff) | |
separate scalar.CanParse from isBoolean
Diffstat (limited to 'parse.go')
| -rw-r--r-- | parse.go | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -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 } } |
