java.lang.Object
org.miaixz.bus.extra.emoji.EmojiKit
A utility class for handling emoji characters, based on the emoji-java library. For detailed documentation and a list
of aliases, please refer to the emoji-java project:
https://github.com/vdurmont/emoji-java
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsEmoji(String text) Checks if the given string contains any emoji characters.extractEmojis(String text) Extracts all emoji characters from a string.static com.vdurmont.emoji.EmojiRetrieves anEmojiobject for a given alias.static Set<com.vdurmont.emoji.Emoji> Retrieves a set of all emojis associated with a given tag.static booleanChecks if the given string consists of a single emoji character.static StringremoveAllEmojis(String text) Removes all emoji characters from a string.static StringConverts Unicode emoji characters in a string to their alias representation (e.g.,:smile:).static StringConverts Unicode emoji characters in a string to their alias representation, with a specifiedEmojiParser.FitzpatrickAction.static StringConverts Unicode emoji characters in a string to their HTML decimal representation.static StringConverts Unicode emoji characters in a string to their HTML representation (either hexadecimal or decimal).static StringConverts Unicode emoji characters in a string to their HTML hexadecimal representation.static StringConverts emoji aliases (e.g.,:smile:) and their HTML representations (e.g.,😄) in a string to their corresponding Unicode emoji characters.
-
Constructor Details
-
EmojiKit
public EmojiKit()
-
-
Method Details
-
isEmoji
Checks if the given string consists of a single emoji character.- Parameters:
text- The string to be tested.- Returns:
trueif the string is a single emoji,falseotherwise.
-
containsEmoji
Checks if the given string contains any emoji characters.- Parameters:
text- The string to be tested.- Returns:
trueif the string contains at least one emoji,falseotherwise.
-
getByTag
Retrieves a set of all emojis associated with a given tag.- Parameters:
tag- The tag to search for, e.g., "happy".- Returns:
- A
SetofEmojiobjects, or null if no emojis are found for the tag.
-
get
Retrieves anEmojiobject for a given alias.- Parameters:
alias- The alias to search for, e.g., "smile".- Returns:
- The
Emojiobject, or null if the alias is not found.
-
toUnicode
Converts emoji aliases (e.g.,:smile:) and their HTML representations (e.g.,😄) in a string to their corresponding Unicode emoji characters.Examples:
:smile:is replaced by😄😄is replaced by😄:boy|type_6:is replaced by👦🏿- Parameters:
text- The string containing emoji aliases or HTML representations.- Returns:
- The string with aliases and HTML representations replaced by Unicode characters.
-
toAlias
Converts Unicode emoji characters in a string to their alias representation (e.g.,:smile:). The defaultEmojiParser.FitzpatrickActionisEmojiParser.FitzpatrickAction.PARSE, which includes the Fitzpatrick modifier type in the alias.Example:
😄is converted to:smile:With
EmojiParser.FitzpatrickAction.PARSE:👦🏿is converted to:boy|type_6:With
EmojiParser.FitzpatrickAction.REMOVE:👦🏿is converted to:boy:With
EmojiParser.FitzpatrickAction.IGNORE:👦🏿is converted to:boy:🏿- Parameters:
text- The string containing Unicode emoji characters.- Returns:
- The string with Unicode emojis replaced by their aliases.
-
toAlias
public static String toAlias(String text, com.vdurmont.emoji.EmojiParser.FitzpatrickAction fitzpatrickAction) Converts Unicode emoji characters in a string to their alias representation, with a specifiedEmojiParser.FitzpatrickAction.- Parameters:
text- The string containing Unicode emoji characters.fitzpatrickAction- The action to perform for Fitzpatrick modifiers.- Returns:
- The string with Unicode emojis replaced by their aliases.
-
toHtmlHex
Converts Unicode emoji characters in a string to their HTML hexadecimal representation.Example:
👦🏿is converted to👦- Parameters:
text- The string containing Unicode emoji characters.- Returns:
- The string with Unicode emojis replaced by their HTML hexadecimal representations.
-
toHtml
Converts Unicode emoji characters in a string to their HTML decimal representation.Example:
👦🏿is converted to👦- Parameters:
text- The string containing Unicode emoji characters.- Returns:
- The string with Unicode emojis replaced by their HTML decimal representations.
-
toHtml
Converts Unicode emoji characters in a string to their HTML representation (either hexadecimal or decimal).Examples:
If isHex is true:
👦🏿is converted to👦If isHex is false:👦🏿is converted to👦- Parameters:
text- The string containing Unicode emoji characters.isHex- Iftrue, converts to hexadecimal; otherwise, converts to decimal.- Returns:
- The string with Unicode emojis replaced by their HTML representations.
-
removeAllEmojis
Removes all emoji characters from a string.- Parameters:
text- The string containing emoji characters.- Returns:
- The string with all emoji characters removed.
-
extractEmojis
Extracts all emoji characters from a string.- Parameters:
text- The string containing emoji characters.- Returns:
- A
Listof all emoji characters found in the string.
-