1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-19 14:05:03 +08:00

fix: limitedString

减少内存使用
This commit is contained in:
wdvxdr 2021-03-28 19:06:42 +08:00
parent 5429292357
commit 5b0c693aba
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6

View File

@ -14,12 +14,14 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)
@ -1378,10 +1380,15 @@ func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) MSG {
}
func limitedString(str string) string {
if strings.Count(str, "") <= 10 {
if utf8.RuneCountInString(str) <= 10 {
return str
}
limited := []rune(str)
limited = limited[:10]
b := utils.S2B(str)
limited := make([]rune, 0, 10)
for i := 0; i < 10; i++ {
decodeRune, size := utf8.DecodeRune(b)
b = b[size:]
limited = append(limited, decodeRune)
}
return string(limited) + " ..."
}