photoprism/pkg/txt/clip.go
Michael Mayer 4e172c450a Improve feedback form
Signed-off-by: Michael Mayer <michael@lastzero.net>
2020-10-05 07:40:11 +02:00

34 lines
460 B
Go

package txt
import "strings"
const (
ClipDefault = 160
ClipSlug = 80
ClipKeyword = 40
ClipDescription = 16000
)
func Clip(s string, size int) string {
s = strings.TrimSpace(s)
if s == "" || size <= 0 {
return ""
}
runes := []rune(s)
if len(runes) > size {
s = string(runes[0 : size-1])
}
return s
}
func TrimLen(s string, size int) string {
if len(s) < size || size < 4 {
return s
}
return Clip(s, size-3) + "..."
}