2020-01-07 16:36:49 +00:00
|
|
|
package txt
|
2019-05-16 06:41:16 +00:00
|
|
|
|
|
|
|
import (
|
2019-12-08 14:05:35 +00:00
|
|
|
"regexp"
|
2019-06-13 18:26:01 +00:00
|
|
|
"strings"
|
2019-05-16 06:41:16 +00:00
|
|
|
)
|
|
|
|
|
2019-12-13 02:07:26 +00:00
|
|
|
var ContainsNumberRegexp = regexp.MustCompile("\\d+")
|
|
|
|
|
2020-01-12 13:00:56 +00:00
|
|
|
// ContainsNumber returns true if string contains a number.
|
2019-12-13 02:07:26 +00:00
|
|
|
func ContainsNumber(s string) bool {
|
|
|
|
return ContainsNumberRegexp.MatchString(s)
|
|
|
|
}
|
|
|
|
|
2020-01-31 14:29:06 +00:00
|
|
|
// Bool casts a string to bool.
|
|
|
|
func Bool(s string) bool {
|
|
|
|
s = strings.TrimSpace(s)
|
|
|
|
|
|
|
|
if s == "" || s == "0" || s == "false" || s == "no" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|