-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## PR - Added `strconv.ParseBool` which is like the std libraries `ParseBool` but with some additional cases added and should be a drop in replacement. - Updated/extended `Options` SQL decoding abilitys
- Loading branch information
Dean Karn
authored
Jun 14, 2023
1 parent
f910bd5
commit ab6d6f3
Showing
5 changed files
with
220 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package strconvext | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
// ParseBool returns the boolean value represented by the string. It extends the std library parse bool with a few more | ||
// valid options. | ||
// | ||
// It accepts 1, t, T, true, TRUE, True, on, yes, ok as true values and 0, f, F, false, FALSE, False, off, no as false. | ||
func ParseBool(str string) (bool, error) { | ||
switch str { | ||
case "1", "t", "T", "true", "TRUE", "True", "on", "yes", "ok": | ||
return true, nil | ||
case "", "0", "f", "F", "false", "FALSE", "False", "off", "no": | ||
return false, nil | ||
} | ||
// strconv.NumError mimicking exactly the strconv.ParseBool(..) error and type | ||
// to ensure compatibility with std library. | ||
return false, &strconv.NumError{Func: "ParseBool", Num: string([]byte(str)), Err: strconv.ErrSyntax} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters