forked from rivo/uniseg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemojiDetector.go
54 lines (46 loc) · 1.02 KB
/
emojiDetector.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
package uniseg
import (
"unicode/utf8"
)
func EmojiCount(str string) int {
if len(str) == 0 {
return 0
}
emjCnt, state := 0, -1
c := ""
for len(str) > 0 {
c, str, _, state = StepString(str, state)
r, _ := utf8.DecodeRuneInString(c)
if property(graphemeCodePoints, r) == prExtendedPictographic ||
property(graphemeCodePoints, r) == prRegionalIndicator {
emjCnt += 1
}
}
return emjCnt
}
func ContinuousEmojiCount(str string) int {
if len(str) == 0 {
return 0
}
continuous, state, maxContinue := 0, -1, 0
c := ""
for len(str) > 0 {
c, str, _, state = StepString(str, state)
r, _ := utf8.DecodeRuneInString(c)
if property(graphemeCodePoints, r) == prExtendedPictographic ||
property(graphemeCodePoints, r) == prRegionalIndicator ||
property(graphemeCodePoints, r) == prEmojiPresentation {
continuous += 1
maxContinue = maxInt(maxContinue, continuous)
} else if c != " " {
continuous = 0
}
}
return maxContinue
}
func maxInt(a, b int) int {
if a > b {
return a
}
return b
}