update Result.Bool to use golang bool parsing

golang has several tools that already parse boolean values in the standard library. 
Specifically strconv.ParseBool(string)
https://golang.org/pkg/strconv/#ParseBool
"ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error."

This change returns any matching ParseBool string to that boolean value, or if the string is not one of those values, the error being thrown, returns a false.
This commit is contained in:
deef 2020-05-30 06:16:06 -04:00 committed by GitHub
parent f042915ca1
commit 7db3b02e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -106,7 +106,8 @@ func (t Result) Bool() bool {
case True: case True:
return true return true
case String: case String:
return t.Str != "" && t.Str != "0" && t.Str != "false" b, err := strconv.ParseBool(t.Str)
return !(!b || err != nil)
case Number: case Number:
return t.Num != 0 return t.Num != 0
} }