Module bus.extra

Class EmojiKit

java.lang.Object
org.miaixz.bus.extra.emoji.EmojiKit

public class EmojiKit extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Checks if the given string contains any emoji characters.
    static List<String>
    Extracts all emoji characters from a string.
    static com.vdurmont.emoji.Emoji
    get(String alias)
    Retrieves an Emoji object for a given alias.
    static Set<com.vdurmont.emoji.Emoji>
    Retrieves a set of all emojis associated with a given tag.
    static boolean
    Checks if the given string consists of a single emoji character.
    static String
    Removes all emoji characters from a string.
    static String
    Converts Unicode emoji characters in a string to their alias representation (e.g., :smile:).
    static String
    toAlias(String text, com.vdurmont.emoji.EmojiParser.FitzpatrickAction fitzpatrickAction)
    Converts Unicode emoji characters in a string to their alias representation, with a specified EmojiParser.FitzpatrickAction.
    static String
    toHtml(String text)
    Converts Unicode emoji characters in a string to their HTML decimal representation.
    static String
    toHtml(String text, boolean isHex)
    Converts Unicode emoji characters in a string to their HTML representation (either hexadecimal or decimal).
    static String
    Converts Unicode emoji characters in a string to their HTML hexadecimal representation.
    static String
    Converts emoji aliases (e.g., :smile:) and their HTML representations (e.g., &#128516;) in a string to their corresponding Unicode emoji characters.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EmojiKit

      public EmojiKit()
  • Method Details

    • isEmoji

      public static boolean isEmoji(String text)
      Checks if the given string consists of a single emoji character.
      Parameters:
      text - The string to be tested.
      Returns:
      true if the string is a single emoji, false otherwise.
    • containsEmoji

      public static boolean containsEmoji(String text)
      Checks if the given string contains any emoji characters.
      Parameters:
      text - The string to be tested.
      Returns:
      true if the string contains at least one emoji, false otherwise.
    • getByTag

      public static Set<com.vdurmont.emoji.Emoji> getByTag(String tag)
      Retrieves a set of all emojis associated with a given tag.
      Parameters:
      tag - The tag to search for, e.g., "happy".
      Returns:
      A Set of Emoji objects, or null if no emojis are found for the tag.
    • get

      public static com.vdurmont.emoji.Emoji get(String alias)
      Retrieves an Emoji object for a given alias.
      Parameters:
      alias - The alias to search for, e.g., "smile".
      Returns:
      The Emoji object, or null if the alias is not found.
    • toUnicode

      public static String toUnicode(String text)
      Converts emoji aliases (e.g., :smile:) and their HTML representations (e.g., &#128516;) in a string to their corresponding Unicode emoji characters.

      Examples:

        :smile: is replaced by 😄
        &#128516; 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

      public static String toAlias(String text)
      Converts Unicode emoji characters in a string to their alias representation (e.g., :smile:). The default EmojiParser.FitzpatrickAction is EmojiParser.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 specified EmojiParser.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

      public static String toHtmlHex(String text)
      Converts Unicode emoji characters in a string to their HTML hexadecimal representation.

      Example: 👦🏿 is converted to &#x1f466;

      Parameters:
      text - The string containing Unicode emoji characters.
      Returns:
      The string with Unicode emojis replaced by their HTML hexadecimal representations.
    • toHtml

      public static String toHtml(String text)
      Converts Unicode emoji characters in a string to their HTML decimal representation.

      Example: 👦🏿 is converted to &#128102;

      Parameters:
      text - The string containing Unicode emoji characters.
      Returns:
      The string with Unicode emojis replaced by their HTML decimal representations.
    • toHtml

      public static String toHtml(String text, boolean isHex)
      Converts Unicode emoji characters in a string to their HTML representation (either hexadecimal or decimal).

      Examples:

       If isHex is true: 👦🏿 is converted to &#x1f466;
       If isHex is false: 👦🏿 is converted to &#128102;
       
      Parameters:
      text - The string containing Unicode emoji characters.
      isHex - If true, converts to hexadecimal; otherwise, converts to decimal.
      Returns:
      The string with Unicode emojis replaced by their HTML representations.
    • removeAllEmojis

      public static String removeAllEmojis(String text)
      Removes all emoji characters from a string.
      Parameters:
      text - The string containing emoji characters.
      Returns:
      The string with all emoji characters removed.
    • extractEmojis

      public static List<String> extractEmojis(String text)
      Extracts all emoji characters from a string.
      Parameters:
      text - The string containing emoji characters.
      Returns:
      A List of all emoji characters found in the string.