photoprism/pkg/txt/clip.go
Michael Mayer 4efa383c57 API: Proof-of-concept for form handling
We don't want to directly write to models so that only selected fields can be changed and values can be validated for security reasons.

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-02-02 03:36:00 +01:00

18 lines
219 B
Go

package txt
import "strings"
func Clip(s string, size int) string {
if s == "" {
return ""
}
s = strings.TrimSpace(s)
runes := []rune(s)
if len(runes) > size {
s = string(runes[0 : size-1])
}
return s
}