|
@@ -791,3 +791,16 @@ func IsWxBrowser(Request *http.Request) bool {
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+//
|
|
|
+func ShortenTxt(length int, fixed, shorten string) string {
|
|
|
+ if len([]rune(fixed)) > length {
|
|
|
+ return ""
|
|
|
+ } else if len([]rune(fixed+shorten)) <= length {
|
|
|
+ return shorten
|
|
|
+ }
|
|
|
+ if limit := length - len([]rune(fixed)) - 3; limit >= 0 && limit <= len([]rune(shorten)) {
|
|
|
+ return string([]rune(shorten)[:limit]) + "..."
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|