File: bool.go

package info (click to toggle)
golang-gopkg-gcfg.v1 0.0~git20150907.0.0ef1a85-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 244 kB
  • ctags: 244
  • sloc: makefile: 7
file content (23 lines) | stat: -rw-r--r-- 574 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
}