photoprism/pkg/clean/codec.go

24 lines
379 B
Go
Raw Permalink Normal View History

package clean
import (
"strings"
)
// Codec removes non-alphanumeric characters from a string and returns it.
func Codec(s string) string {
if s == "" {
return ""
}
// Remove unwanted characters.
s = strings.Map(func(r rune) rune {
if (r < '0' || r > '9') && (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') && r != '_' {
return -1
}
return r
}, s)
return s
}