Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support numerical keycap emoji by including 2 byte runes #16

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/tmdvs/Go-Emoji-Utils/utils"
)

// SearchResult - Occurence of an emoji in a string
// SearchResult - Occurrence of an emoji in a string
type SearchResult struct {
Match interface{}
Occurrences int
Expand All @@ -28,7 +28,7 @@ func (results SearchResults) IndexOf(result interface{}) int {
return -1
}

// Find a specific emoji character within a srting
// Find a specific emoji character within a string
func Find(emojiString string, input string) (result SearchResult, err error) {

// Firstly we'll grab the emoji record for the emoji we're looking for
Expand Down Expand Up @@ -65,7 +65,7 @@ func FindAll(input string) (detectedEmojis SearchResults) {
// Loop over each "word" in the string
for index, r := range runes {

// If this index has been flaged as a modifier we do
// If this index has been flagged as a modifier we do
// not want to process it again
if detectedModifiers[index] {
continue
Expand All @@ -75,8 +75,8 @@ func FindAll(input string) (detectedEmojis SearchResults) {
hexKey := utils.RunesToHexKey([]rune{r})

// Ignore any basic runes, we'll get funny partials
// that we dont care about
if len(hexKey) < 4 {
// that we don't care about
if len(hexKey) < 2 {
continue
}

Expand All @@ -93,13 +93,13 @@ func FindAll(input string) (detectedEmojis SearchResults) {
if len(potentialMatches) == 1 {
break
} else if len(potentialMatches) == 0 {
// We didnt find anything, so we'll check if its a single rune emoji
// We didn't find anything, so we'll check if its a single rune emoji
// Reset to original hexKey
if _, match := Emojis[previousKey]; match {
potentialMatches[previousKey] = Emojis[previousKey]
}

// Definately no modifiers
// Definitely no modifiers
detectedModifiers = map[int]bool{}

break
Expand Down Expand Up @@ -138,7 +138,7 @@ func FindAll(input string) (detectedEmojis SearchResults) {
Match: e,
Occurrences: 1,
Locations: [][]int{
[]int{index, index + emojiRuneLength},
{index, index + emojiRuneLength},
},
})
}
Expand Down
8 changes: 8 additions & 0 deletions tests/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func TestContinuousEmoji(t *testing.T) {
assert.Equal(t, "abc", emojiRemoved, "There should be no emoji")
}

func TestNumericalKeycaps(t *testing.T) {
str := "0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣🔟"
matches := emoji.FindAll(str)
totalUniqueEmoji := len(matches)

assert.Equal(t, 11, totalUniqueEmoji, "There should be 11 unique emoji")
}

func TestRemoveAllEmojiChinese(t *testing.T) {

str := "起坎特在🇫🇷队的作用更 哈哈哈"
Expand Down
Loading