Created
November 24, 2025 15:38
-
-
Save psinetron/3c9adc35fb086003fb5c4f315a5cf1b8 to your computer and use it in GitHub Desktop.
Main Emoji EN
This file contains hidden or 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
| /** | |
| * An object containing information about the emoji being processed. | |
| */ | |
| data class Emoji(val emoji: String, @DrawableRes val resource: Int) | |
| /** | |
| * A list of emojis we can customize | |
| */ | |
| val EMOJIS: List<Emoji> = listOf( | |
| Emoji("\ud83d\ude42", R.drawable.simple_smile), // π | |
| Emoji("\ud83d\udc69\u200d\ud83d\udcbb", R.drawable.female_engineer), // π©βπ» | |
| Emoji("\ud83d\ude0e", R.drawable.smiling_with_sunglasses) // π | |
| ) | |
| /** | |
| * Generates a regular expression to find all emoji from a list. | |
| */ | |
| fun List<Emoji>.toRegex(): Regex { | |
| val pattern = joinToString(separator = "|") { emoji -> | |
| Regex.escape(emoji.emoji) | |
| } | |
| return Regex(pattern) | |
| } | |
| /** | |
| * Gets an Emoji object based on the found emoji text | |
| */ | |
| fun List<Emoji>.getEmojiByText(emojiText: String): Emoji? { | |
| return firstOrNull { it.emoji == emojiText } | |
| } | |
| /** | |
| * Finds all occurrences of an emoji from a list in text. | |
| */ | |
| fun List<Emoji>.findEmojisInText(text: String): List<EmojiRange> { | |
| return toRegex().findAll(text).mapNotNull { match -> | |
| getEmojiByText(match.value)?.let { emoji -> | |
| EmojiRange(emoji, match.range) | |
| } | |
| }.toList() | |
| } | |
| data class EmojiRange( | |
| val emoji: Emoji, | |
| val range: IntRange, | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment