mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 11:47:24 +01:00
Adding secret emojis to reactions
This commit is contained in:
@@ -106,4 +106,27 @@ object EmojiCoder {
|
||||
val decodedArray = ByteArray(decoded.size) { decoded[it].toByte() }
|
||||
return String(decodedArray, Charsets.UTF_8)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun cropToFirstMessage(text: String): String {
|
||||
val decoded = mutableListOf<Int>()
|
||||
|
||||
var i = 0
|
||||
while (i < text.length) {
|
||||
val codePoint = text.codePointAt(i)
|
||||
val byte = fromVariationSelector(codePoint)
|
||||
|
||||
if (byte == null && decoded.isNotEmpty()) {
|
||||
break
|
||||
} else if (byte == null) {
|
||||
i += Character.charCount(codePoint) // Advance index by correct number of chars
|
||||
continue
|
||||
}
|
||||
|
||||
decoded.add(byte)
|
||||
i += Character.charCount(codePoint) // Advance index by correct number of chars
|
||||
}
|
||||
|
||||
return text.substring(0, i)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ class EmojiCoderTest {
|
||||
)
|
||||
|
||||
val HELLO_WORLD = "\uD83D\uDE00\uDB40\uDD38\uDB40\uDD55\uDB40\uDD5C\uDB40\uDD5C\uDB40\uDD5F\uDB40\uDD1C\uDB40\uDD10\uDB40\uDD47\uDB40\uDD5F\uDB40\uDD62\uDB40\uDD5C\uDB40\uDD54\uDB40\uDD11"
|
||||
val HELLO_WORLD_WITH_EXTRAS = HELLO_WORLD + "askfasdf"
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,6 +56,11 @@ class EmojiCoderTest {
|
||||
assertEquals("Hello, World!", EmojiCoder.decode(HELLO_WORLD))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCrop() {
|
||||
assertEquals(HELLO_WORLD, EmojiCoder.cropToFirstMessage(HELLO_WORLD_WITH_EXTRAS))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEncodeDecode() {
|
||||
for (emoji in EMOJI_LIST) {
|
||||
|
||||
Reference in New Issue
Block a user