From 4857a977aa2b9d59b17e6076dcb0f1c0bc32d1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kl=C3=A4hn?= Date: Sat, 5 Oct 2024 17:38:33 +0200 Subject: [PATCH] Use Character.isEmojiPresentation(int) instead of Character.isEmoji(int) which excludes e.g. digit that are technically an emoji but do not have a representation (#1961) --- .../java/org/tweetwallfx/emoji/Emojify.java | 2 +- .../org/tweetwallfx/emoji/EmojifyTest.java | 70 ++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/emoji/src/main/java/org/tweetwallfx/emoji/Emojify.java b/emoji/src/main/java/org/tweetwallfx/emoji/Emojify.java index c11e2f691..3b2c9fa08 100644 --- a/emoji/src/main/java/org/tweetwallfx/emoji/Emojify.java +++ b/emoji/src/main/java/org/tweetwallfx/emoji/Emojify.java @@ -40,7 +40,7 @@ public static List tokenizeStringToTextAndEmoji(final String message) { for (int idx = 0; idx < codePoints.length; idx++) { var cp = codePoints[idx]; - if (Character.isEmoji(cp)) { + if (Character.isEmojiPresentation(cp)) { // we have an emoji if (idx != idxStart) { // prior to the emoji is a non-empty text diff --git a/emoji/src/test/java/org/tweetwallfx/emoji/EmojifyTest.java b/emoji/src/test/java/org/tweetwallfx/emoji/EmojifyTest.java index 27dbfe152..58feb2217 100644 --- a/emoji/src/test/java/org/tweetwallfx/emoji/EmojifyTest.java +++ b/emoji/src/test/java/org/tweetwallfx/emoji/EmojifyTest.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 TweetWallFX + * Copyright (c) 2023-2024 TweetWallFX * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -54,6 +54,74 @@ static Stream parameters() { " Awesome emojis! ", new Twemoji("1f609") } + ), + arguments( + "Wired 2.0! Create your ultimate learning environment", + new Object[]{ + "Wired 2.0! Create your ultimate learning environment" + } + ), + arguments( + "HTTP 1.0", + new Object[]{ + "HTTP 1.0" + } + ), + arguments( + "0", + new Object[]{"0"} + ), + arguments( + "1", + new Object[]{"1"} + ), + arguments( + "2", + new Object[]{"2"} + ), + arguments( + "3", + new Object[]{"3"} + ), + arguments( + "4", + new Object[]{"4"} + ), + arguments( + "5", + new Object[]{"5"} + ), + arguments( + "6", + new Object[]{"6"} + ), + arguments( + "7", + new Object[]{"7"} + ), + arguments( + "8", + new Object[]{"8"} + ), + arguments( + "9", + new Object[]{"9"} + ), + arguments( + "#", + new Object[]{"#"} + ), + arguments( + "*", + new Object[]{"*"} + ), + arguments( + "©", + new Object[]{"©"} + ), + arguments( + "®", + new Object[]{"®"} ) ); }