|
@@ -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)
|
|
|
+
|
|
|
+ if totalCharCount <= 18 {
|
|
|
+ return s
|
|
|
+ }
|
|
|
+
|
|
|
+ hanziCount := 0
|
|
|
+ byteIndex := 0
|
|
|
+ for byteIndex < len(s) && hanziCount < 15 {
|
|
|
+ r, size := utf8.DecodeRuneInString(s[byteIndex:])
|
|
|
+ if r != utf8.RuneError {
|
|
|
+ hanziCount++
|
|
|
+ }
|
|
|
+ byteIndex += size
|
|
|
+ }
|
|
|
+
|
|
|
+ return s[:byteIndex] + "…"
|
|
|
+}
|