-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d92656b
commit da2f152
Showing
2 changed files
with
60 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
java-21/src/main/java/com/ibrahimatay/UnicodeEmojiMethods.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,52 @@ | ||
package com.ibrahimatay; | ||
|
||
import java.util.OptionalInt; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class UnicodeEmojiMethods { | ||
|
||
// Unicode Emoji Properties | ||
// https://bugs.openjdk.org/browse/JDK-8303018 | ||
|
||
// JDK 21 JavaDoc for java.lang.Character | ||
// https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Character.html | ||
|
||
// Unicode® Technical Standard #Emoji Character Properties | ||
// https://unicode.org/reports/tr51/#Emoji_Properties_and_Data_Files | ||
|
||
public static void main(String[] args) { | ||
String welcomeMsg = "Hey Java Developers! ☕️"; | ||
|
||
if(welcomeMsg.codePoints().anyMatch(Character::isEmoji)) { | ||
System.out.println("Message contains an emoji!"); | ||
} | ||
|
||
Matcher matcher = Pattern.compile("\\p{IsEmoji}").matcher(welcomeMsg); | ||
if(matcher.find()) { | ||
System.out.println("Message contains an emoji!"); | ||
} | ||
|
||
Matcher matcher_modifier_base = Pattern.compile("\\p{IsEmoji_Modifier_Base}").matcher(welcomeMsg); | ||
if(matcher_modifier_base.find()) { | ||
System.out.println("Message contains an emoji modifier base!"); | ||
} | ||
|
||
OptionalInt emojiOptional = welcomeMsg.codePoints().filter(Character::isEmoji).findFirst(); | ||
if (emojiOptional.isPresent()) { | ||
int emojiCodePoint = emojiOptional.getAsInt(); | ||
if (Character.isEmojiModifierBase(emojiCodePoint)) { | ||
System.out.println("Emoji can be modified"); | ||
if (Character.isEmojiModifier(emojiCodePoint)) { | ||
System.out.println("Emoji is modified"); | ||
} else { | ||
System.out.println("Emoji has not been modified"); | ||
} | ||
} else { | ||
System.out.println("Emoji cannot be modified"); | ||
} | ||
} else { | ||
System.out.println("No emoji"); | ||
} | ||
} | ||
} |