|
@@ -21,6 +21,7 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
"unicode"
|
|
|
+ "unicode/utf8"
|
|
|
)
|
|
|
|
|
|
// 随机数种子
|
|
@@ -982,3 +983,25 @@ func GetArabicNumbers(str string) string {
|
|
|
}
|
|
|
return string(numbers)
|
|
|
}
|
|
|
+
|
|
|
+// 处理活动名称
|
|
|
+func TruncateActivityNameString(s string) string {
|
|
|
+ // 计算字符串总字数(按汉字、数字、字母和特殊符号计算)
|
|
|
+ totalCharCount := utf8.RuneCountInString(s)
|
|
|
+ // 如果总字数不超过18,则直接返回整个字符串
|
|
|
+ if totalCharCount <= 18 {
|
|
|
+ return s
|
|
|
+ }
|
|
|
+ // 计算前15个汉字所需的字节位置
|
|
|
+ hanziCount := 0
|
|
|
+ byteIndex := 0
|
|
|
+ for byteIndex < len(s) && hanziCount < 15 {
|
|
|
+ r, size := utf8.DecodeRuneInString(s[byteIndex:])
|
|
|
+ if r != utf8.RuneError {
|
|
|
+ hanziCount++
|
|
|
+ }
|
|
|
+ byteIndex += size
|
|
|
+ }
|
|
|
+ // 截取前15个汉字,并添加省略号
|
|
|
+ return s[:byteIndex] + "…"
|
|
|
+}
|