| 1 | package format |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // ParseBool returns true for "1","true","yes" or false for "0","false","no" or defaultValue for any other value. |
| 9 | func ParseBool(value string, defaultValue bool) (bool, bool) { |
| 10 | switch strings.ToLower(value) { |
| 11 | case "true", "1", "yes", "y": |
| 12 | return true, true |
| 13 | case "false", "0", "no", "n": |
| 14 | return false, true |
| 15 | default: |
| 16 | return defaultValue, false |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | // PrintBool returns "Yes" if value is true, otherwise returns "No". |
| 21 | func PrintBool(value bool) string { |
| 22 | if value { |
| 23 | return "Yes" |
| 24 | } |
| 25 | |
| 26 | return "No" |
| 27 | } |
| 28 | |
| 29 | // IsNumber returns whether the specified string is number-like. |
| 30 | func IsNumber(value string) bool { |
| 31 | _, err := strconv.ParseFloat(value, 64) |
| 32 | |
| 33 | return err == nil |
| 34 | } |