photoprism/pkg/txt/strings.go

25 lines
420 B
Go
Raw Normal View History

package txt
import (
"regexp"
2019-06-13 20:26:01 +02: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
}