From e2dfb621f224fcf393f0427e6c57b495df23a223 Mon Sep 17 00:00:00 2001 From: Tong Sun Date: Wed, 28 Jul 2021 08:51:40 -0400 Subject: [PATCH] - [#] simplify FormatEmoji() algorithm --- emoji.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/emoji.go b/emoji.go index fc5ddc7..f06745e 100644 --- a/emoji.go +++ b/emoji.go @@ -1,7 +1,7 @@ package openwechat import ( - "html" + "fmt" "regexp" "strconv" "strings" @@ -294,13 +294,11 @@ func FormatEmoji(text string) string { } value := item[0] emojiCodeStr := item[1] - emojiCode, err := strconv.ParseInt(emojiCodeStr, 16, 64) + emojiCode, err := strconv.ParseInt(emojiCodeStr, 16, 16) if err != nil { continue } - - emojiStr := html.UnescapeString("&#" + strconv.FormatInt(emojiCode, 10) + ";") - text = strings.Replace(text, value, emojiStr, -1) + text = strings.Replace(text, value, fmt.Sprintf("%c", emojiCode), -1) } return text