-
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored isMessageWithSingleEmoticonOnly in TextMatchers to use reg…
…ex for single emoji check Signed-off-by: Smarshal21 <[email protected]>
- Loading branch information
1 parent
ac030a2
commit f79db0b
Showing
3 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.nextcloud.talk.utils; | ||
|
||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
public final class TextMatchers { | ||
|
||
public static boolean isMessageWithSingleEmoticonOnly(@Nullable final String text) { | ||
if (text == null || text.isEmpty()) { | ||
return false; | ||
} | ||
String emojiRegex = "([\\p{So}\\p{Sk}])"; | ||
Pattern pattern = Pattern.compile(emojiRegex); | ||
Matcher matcher = pattern.matcher(text); | ||
|
||
int emojiCount = 0; | ||
while (matcher.find()) { | ||
emojiCount++; | ||
} | ||
return emojiCount == 1; | ||
} | ||
} |