|
| 1 | +package com.ibrahimatay; |
| 2 | + |
| 3 | +import java.util.OptionalInt; |
| 4 | +import java.util.regex.Matcher; |
| 5 | +import java.util.regex.Pattern; |
| 6 | + |
| 7 | +public class UnicodeEmojiMethods { |
| 8 | + |
| 9 | + // Unicode Emoji Properties |
| 10 | + // https://bugs.openjdk.org/browse/JDK-8303018 |
| 11 | + |
| 12 | + // JDK 21 JavaDoc for java.lang.Character |
| 13 | + // https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Character.html |
| 14 | + |
| 15 | + // Unicode® Technical Standard #Emoji Character Properties |
| 16 | + // https://unicode.org/reports/tr51/#Emoji_Properties_and_Data_Files |
| 17 | + |
| 18 | + public static void main(String[] args) { |
| 19 | + String welcomeMsg = "Hey Java Developers! ☕️"; |
| 20 | + |
| 21 | + if(welcomeMsg.codePoints().anyMatch(Character::isEmoji)) { |
| 22 | + System.out.println("Message contains an emoji!"); |
| 23 | + } |
| 24 | + |
| 25 | + Matcher matcher = Pattern.compile("\\p{IsEmoji}").matcher(welcomeMsg); |
| 26 | + if(matcher.find()) { |
| 27 | + System.out.println("Message contains an emoji!"); |
| 28 | + } |
| 29 | + |
| 30 | + Matcher matcher_modifier_base = Pattern.compile("\\p{IsEmoji_Modifier_Base}").matcher(welcomeMsg); |
| 31 | + if(matcher_modifier_base.find()) { |
| 32 | + System.out.println("Message contains an emoji modifier base!"); |
| 33 | + } |
| 34 | + |
| 35 | + OptionalInt emojiOptional = welcomeMsg.codePoints().filter(Character::isEmoji).findFirst(); |
| 36 | + if (emojiOptional.isPresent()) { |
| 37 | + int emojiCodePoint = emojiOptional.getAsInt(); |
| 38 | + if (Character.isEmojiModifierBase(emojiCodePoint)) { |
| 39 | + System.out.println("Emoji can be modified"); |
| 40 | + if (Character.isEmojiModifier(emojiCodePoint)) { |
| 41 | + System.out.println("Emoji is modified"); |
| 42 | + } else { |
| 43 | + System.out.println("Emoji has not been modified"); |
| 44 | + } |
| 45 | + } else { |
| 46 | + System.out.println("Emoji cannot be modified"); |
| 47 | + } |
| 48 | + } else { |
| 49 | + System.out.println("No emoji"); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments