commit
1079cf47fe
32
emoji.go
32
emoji.go
@ -284,19 +284,25 @@ var Emoji = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FormatEmoji(text string) string {
|
func FormatEmoji(text string) string {
|
||||||
if result := emojiRegexp.FindAllStringSubmatch(text, -1); len(result) != 0 {
|
result := emojiRegexp.FindAllStringSubmatch(text, -1)
|
||||||
for _, item := range result {
|
if len(result) == 0 {
|
||||||
value := item[0]
|
return text
|
||||||
var builder strings.Builder
|
|
||||||
builder.WriteString(`\U`)
|
|
||||||
times := 10 - len(item[1]) - 2
|
|
||||||
for i := 0; i < times; i++ {
|
|
||||||
builder.WriteString("0")
|
|
||||||
}
|
|
||||||
u := strings.ToUpper(item[1])
|
|
||||||
builder.WriteString(u)
|
|
||||||
text = strings.ReplaceAll(text, value, builder.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, item := range result {
|
||||||
|
if len(item) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
value := item[0]
|
||||||
|
emojiCodeStr := item[1]
|
||||||
|
emojiCode, err := strconv.ParseInt(emojiCodeStr, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
emojiStr := html.UnescapeString("&#" + strconv.FormatInt(emojiCode, 10) + ";")
|
||||||
|
text = strings.Replace(text, value, emojiStr, -1)
|
||||||
|
}
|
||||||
|
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user