photoprism/pkg/txt/is.go
Michael Mayer 91acaaa573 Index shorter keywords in languages like Chinese #746
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-12-27 16:37:28 +01:00

43 lines
703 B
Go

package txt
import "unicode"
// Is reports whether the all string runes are in the specified range.
func Is(rangeTab *unicode.RangeTable, s string) bool {
if s == "" {
return false
}
for _, r := range s {
if !unicode.Is(rangeTab, r) {
return false
}
}
return true
}
// IsASCII tests if the string only contains ascii runes.
func IsASCII(s string) bool {
for i := 0; i < len(s); i++ {
if s[i] > unicode.MaxASCII {
return false
}
}
return true
}
// IsLatin reports whether the string only contains latin letters.
func IsLatin(s string) bool {
if s == "" {
return false
}
for _, r := range s {
if !unicode.Is(unicode.Latin, r) {
return false
}
}
return true
}