photoprism/pkg/txt/strings.go

25 lines
420 B
Go
Raw Normal View History

package txt
import (
"regexp"
2019-06-13 18:26:01 +00:00
"strings"
)
var ContainsNumberRegexp = regexp.MustCompile("\\d+")
// ContainsNumber returns true if string contains a number.
func ContainsNumber(s string) bool {
return ContainsNumberRegexp.MatchString(s)
}
// 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
}