photoprism/pkg/txt/strings.go
Michael Mayer 4976788c5b Backend: Add list of small words #361
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-06-24 07:38:08 +02:00

36 lines
674 B
Go

package txt
import (
"regexp"
"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
}
// ASCII returns true if the string only contains ascii chars without whitespace, numbers, and punctuation marks.
func ASCII(s string) bool {
for _, r := range s {
if (r < 65 || r > 90) && (r < 97 || r > 122) {
return false
}
}
return true
}