-
Notifications
You must be signed in to change notification settings - Fork 14
/
utils.go
56 lines (45 loc) · 1.11 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package utils
import (
"encoding/json"
"strings"
"unicode"
"github.com/number571/go-peer/cmd/hidden_lake/applications/messenger/web"
)
type sEmojis struct {
Emojis []struct {
Emoji string `json:"emoji"`
Shortname string `json:"shortname"`
} `json:"emojis"`
}
var (
gEmojiReplacer *strings.Replacer
)
func init() {
emojiSimple := new(sEmojis)
if err := json.Unmarshal(web.GEmojiSimpleJSON, emojiSimple); err != nil {
panic(err)
}
emoji := new(sEmojis)
if err := json.Unmarshal(web.GEmojiJSON, emoji); err != nil {
panic(err)
}
replacerList := make([]string, 0, len(emojiSimple.Emojis)+len(emoji.Emojis))
for _, emoji := range emojiSimple.Emojis {
replacerList = append(replacerList, emoji.Shortname, emoji.Emoji)
}
for _, emoji := range emoji.Emojis {
replacerList = append(replacerList, emoji.Shortname, emoji.Emoji)
}
gEmojiReplacer = strings.NewReplacer(replacerList...)
}
func ReplaceTextToEmoji(pS string) string {
return gEmojiReplacer.Replace(pS)
}
func HasNotWritableCharacters(pS string) bool {
for _, c := range pS {
if !unicode.IsGraphic(c) {
return true
}
}
return false
}