Class EmojiParser


  • public class EmojiParser
    extends Object
    Provides methods to parse strings with emojis.
    • Constructor Detail

      • EmojiParser

        public EmojiParser()
    • Method Detail

      • parseToAliases

        @NotNull
        public static @NotNull String parseToAliases​(@NotNull
                                                     @NotNull String input,
                                                     @NotNull
                                                     @NotNull EmojiParser.FitzpatrickAction fitzpatrickAction)
        Replaces the emoji's unicode occurrences by one of their alias (between 2 ':').
        Example: 😄 will be replaced by :smile:

        When a fitzpatrick modifier is present with a PARSE action, a "|" will be appended to the alias, with the fitzpatrick type.
        Example: 👦🏿 will be replaced by :boy|type_6:
        The fitzpatrick types are: type_1_2, type_3, type_4, type_5, type_6

        When a fitzpatrick modifier is present with a REMOVE action, the modifier will be deleted.
        Example: 👦🏿 will be replaced by :boy:

        When a fitzpatrick modifier is present with a IGNORE action, the modifier will be ignored.
        Example: 👦🏿 will be replaced by :boy:🏿

        Parameters:
        input - The string to parse
        fitzpatrickAction - The action to apply for the fitzpatrick modifiers
        Returns:
        the string with the emojis replaced by their alias.
      • replaceAllEmojis

        @NotNull
        public static @NotNull String replaceAllEmojis​(@NotNull
                                                       @NotNull String str,
                                                       @NotNull
                                                       @NotNull String replacementString)
        Replace all emojis with character
        Parameters:
        str - The string to process
        replacementString - Replacement the string that will replace all the emojis
        Returns:
        the string with replaced character
      • parseToUnicode

        @NotNull
        public static @NotNull String parseToUnicode​(@NotNull
                                                     @NotNull String input)
        Replaces the emoji's aliases (between 2 ':') occurrences and the html representations by their unicode.

        Examples

        :smile: will be replaced by 😄
        😄 will be replaced by 😄
        :boy|type_6: will be replaced by 👦🏿
        Parameters:
        input - the string to parse
        Returns:
        the string with the aliases and html representations replaced by their unicode.
      • parseToHtmlDecimal

        @NotNull
        public static @NotNull String parseToHtmlDecimal​(String input,
                                                         EmojiParser.FitzpatrickAction fitzpatrickAction)
        Replaces the emoji's unicode occurrences by their html representation.
        Example: 😄 will be replaced by 😄

        When a fitzpatrick modifier is present with a PARSE or REMOVE action, the modifier will be deleted from the string.
        Example: 👦🏿 will be replaced by 👦

        When a fitzpatrick modifier is present with a IGNORE action, the modifier will be ignored and will remain in the string.
        Example: 👦🏿 will be replaced by 👦🏿

        Parameters:
        input - the string to parse
        fitzpatrickAction - the action to apply for the fitzpatrick modifiers
        Returns:
        the string with the emojis replaced by their html decimal representation.
      • parseToHtmlHexadecimal

        @NotNull
        public static @NotNull String parseToHtmlHexadecimal​(@NotNull
                                                             @NotNull String input,
                                                             @NotNull
                                                             @NotNull EmojiParser.FitzpatrickAction fitzpatrickAction)
        Replaces the emoji's unicode occurrences by their html hex representation.
        Example: 👦 will be replaced by 👦

        When a fitzpatrick modifier is present with a PARSE or REMOVE action, the modifier will be deleted.
        Example: 👦🏿 will be replaced by 👦

        When a fitzpatrick modifier is present with a IGNORE action, the modifier will be ignored and will remain in the string.
        Example: 👦🏿 will be replaced by 👦🏿

        Parameters:
        input - the string to parse
        fitzpatrickAction - the action to apply for the fitzpatrick modifiers
        Returns:
        the string with the emojis replaced by their html hex representation.
      • removeAllEmojis

        @NotNull
        public static @NotNull String removeAllEmojis​(@NotNull
                                                      @NotNull String str)
        Removes all emojis from a String
        Parameters:
        str - the string to process
        Returns:
        the string without any emoji
      • removeEmojis

        @NotNull
        public static @NotNull String removeEmojis​(@NotNull
                                                   @NotNull String str,
                                                   @NotNull
                                                   @NotNull Collection<? extends Emoji> emojisToRemove)
        Removes a set of emojis from a String
        Parameters:
        str - the string to process
        emojisToRemove - the emojis to remove from this string
        Returns:
        the string without the emojis that were removed
      • removeAllEmojisExcept

        @NotNull
        public static @NotNull String removeAllEmojisExcept​(@NotNull
                                                            @NotNull String str,
                                                            @NotNull
                                                            @NotNull Collection<? extends Emoji> emojisToKeep)
        Removes all the emojis in a String except a provided set
        Parameters:
        str - the string to process
        emojisToKeep - the emojis to keep in this string
        Returns:
        the string without the emojis that were removed
      • parseFromUnicode

        @NotNull
        public static @NotNull String parseFromUnicode​(@NotNull
                                                       @NotNull String input,
                                                       @NotNull
                                                       @NotNull EmojiParser.EmojiTransformer transformer)
        Detects all unicode emojis in input string and replaces them with the return value of transformer.transform()
        Parameters:
        input - the string to process
        transformer - emoji transformer to apply to each emoji
        Returns:
        input string with all emojis transformed
      • extractEmojis

        @NotNull
        public static @NotNull List<String> extractEmojis​(@NotNull
                                                          @NotNull String input)
        Parses all emoji by unicode in the given string.
        Parameters:
        input - Input string to parse
        Returns:
        List of String unicode emoji