-
Notifications
You must be signed in to change notification settings - Fork 2
/
gmoji.go
80 lines (61 loc) · 1.15 KB
/
gmoji.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package gmoji
import (
"fmt"
"strings"
"unicode"
)
type Gmoji string
func Parse(input string) string {
var matched strings.Builder
var output strings.Builder
for _, r := range input {
if r != ':' {
if matched.Len() == 0 {
output.WriteRune(r)
continue
}
matched.WriteRune(r)
if unicode.IsSpace(r) {
output.WriteString(matched.String())
matched.Reset()
}
continue
}
if matched.Len() == 0 {
matched.WriteRune(r)
continue
}
match := matched.String()
alias := match + ":"
if code, ok := find(alias); ok {
output.WriteString(code)
matched.Reset()
continue
}
output.WriteString(match)
matched.Reset()
matched.WriteRune(r)
}
if matched.Len() != 0 {
output.WriteString(matched.String())
matched.Reset()
}
return output.String()
}
func find(alias string) (string, bool) {
if code, ok := gmojiMap[alias]; ok {
return code, true
}
return "", false
}
func Print(str string) {
fmt.Print(Parse(str))
}
func Println(str string) {
fmt.Println(Parse(str))
}
/*
O------------------------------------O
O License: MIT | Copyright 2020-2021 O
O------------------------------------O
*/