mirror of
https://gitea.com/Sirherobrine23/tea.git
synced 2024-08-21 00:27:24 +00:00
6cff3b1cc7
Merge branch 'master' into vendor-migrate-go-git Merge branch 'master' into vendor-migrate-go-git migrate src-d/go-git -> go-git/go-git Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/128 Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
24 lines
574 B
Go
24 lines
574 B
Go
package types
|
|
|
|
// BoolValues defines the name and value mappings for ParseBool.
|
|
var BoolValues = map[string]interface{}{
|
|
"true": true, "yes": true, "on": true, "1": true,
|
|
"false": false, "no": false, "off": false, "0": false,
|
|
}
|
|
|
|
var boolParser = func() *EnumParser {
|
|
ep := &EnumParser{}
|
|
ep.AddVals(BoolValues)
|
|
return ep
|
|
}()
|
|
|
|
// ParseBool parses bool values according to the definitions in BoolValues.
|
|
// Parsing is case-insensitive.
|
|
func ParseBool(s string) (bool, error) {
|
|
v, err := boolParser.Parse(s)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return v.(bool), nil
|
|
}
|