-
Notifications
You must be signed in to change notification settings - Fork 2
/
query.go
73 lines (61 loc) · 1.71 KB
/
query.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
package discordemojimap
import "strings"
// ContainsEmoji returns true if that emoji is mapped to one or more key.
func ContainsEmoji(emoji string) bool {
for _, emojiInMap := range EmojiMap {
if emojiInMap == emoji {
return true
}
}
return false
}
// ContainsCode returns true if emojiCode is mapped to an emoji. The search is
// case-insensitive.
func ContainsCode(emojiCode string) bool {
if lowered := toLower(emojiCode); lowered != "" {
emojiCode = lowered
}
_, contains := EmojiMap[emojiCode]
return contains
}
// GetEmojiCodes contains all codes for an emoji in an array. If no code could
// be found, then the resulting array will be empty.
func GetEmojiCodes(emoji string) []string {
var codes []string
for code, emojiInMap := range EmojiMap {
if emojiInMap == emoji {
codes = append(codes, code)
}
}
return codes
}
// GetEmoji returns the matching emoji or an empty string in case no match was
// found for the given code.
//
// The function will search without accounting for colons. The search
// is case-insensitive.
func GetEmoji(emojiCode string) string {
if lowered := toLower(emojiCode); lowered != "" {
return EmojiMap[lowered]
}
return EmojiMap[emojiCode]
}
// GetEntriesWithPrefix returns a map of all found emojis with the given prefix.
//
// The function will search without accounting for leading colons. The search
// is case-insensitive.
func GetEntriesWithPrefix(prefix string) map[string]string {
matches := make(map[string]string)
if prefix == "" {
return matches
}
if lowered := toLower(prefix); lowered != "" {
prefix = lowered
}
for emojiCode, emoji := range EmojiMap {
if strings.HasPrefix(emojiCode, prefix) {
matches[emojiCode] = emoji
}
}
return matches
}