2020-02-02 02:00:47 +01:00
|
|
|
package txt
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
2020-04-26 14:31:33 +02:00
|
|
|
const (
|
2020-04-26 16:22:29 +02:00
|
|
|
ClipDefault = 160
|
|
|
|
ClipSlug = 80
|
|
|
|
ClipKeyword = 40
|
|
|
|
ClipDescription = 16000
|
2020-04-26 14:31:33 +02:00
|
|
|
)
|
|
|
|
|
2020-02-02 02:00:47 +01:00
|
|
|
func Clip(s string, size int) string {
|
2020-04-26 14:31:33 +02:00
|
|
|
s = strings.TrimSpace(s)
|
|
|
|
|
|
|
|
if s == "" || size <= 0 {
|
2020-02-02 02:00:47 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
runes := []rune(s)
|
|
|
|
|
|
|
|
if len(runes) > size {
|
2020-02-02 03:36:00 +01:00
|
|
|
s = string(runes[0 : size-1])
|
2020-02-02 02:00:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|