photoprism/pkg/clean/name.go
Michael Mayer f5a8c5a45d Auth: Session and ACL enhancements #98 #1746
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-09-28 09:01:17 +02:00

37 lines
649 B
Go

package clean
import (
"strings"
"github.com/photoprism/photoprism/pkg/txt"
)
// Name returns the sanitized and capitalized names.
func Name(name string) string {
// Empty or too long?
if name == "" || reject(name, txt.ClipDefault) {
return ""
}
// Remove unwanted characters.
name = strings.Map(func(r rune) rune {
if r < 32 || r == 127 {
return -1
}
switch r {
case '"', '$', '%', '\\', '*', '`', ';', '<', '>', '{', '}':
return -1
}
return r
}, name)
name = strings.TrimSpace(name)
// Now empty?
if name == "" {
return ""
}
// Shorten and capitalize.
return txt.Clip(txt.Title(name), txt.ClipDefault)
}