Class EmojiParser
- java.lang.Object
-
- com.vdurmont.emoji.EmojiParser
-
public class EmojiParser extends Object
Provides methods to parse strings with emojis.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceEmojiParser.EmojiTransformerstatic classEmojiParser.FitzpatrickActionEnum used to indicate what should be done when a Fitzpatrick modifier is found.static classEmojiParser.UnicodeCandidate
-
Constructor Summary
Constructors Constructor Description EmojiParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull List<String>extractEmojis(@NotNull String input)Parses all emoji by unicode in the given string.static @NotNull StringparseFromUnicode(@NotNull String input, @NotNull EmojiParser.EmojiTransformer transformer)Detects all unicode emojis in input string and replaces them with the return value of transformer.transform()static @NotNull StringparseToAliases(@NotNull String input)SeeparseToAliases(String, FitzpatrickAction)with the actionEmojiParser.FitzpatrickAction.PARSE.static @NotNull StringparseToAliases(@NotNull String input, @NotNull EmojiParser.FitzpatrickAction fitzpatrickAction)Replaces the emoji's unicode occurrences by one of their alias (between 2 ':').static @NotNull StringparseToHtmlDecimal(@NotNull String input)SeeparseToHtmlDecimal(String, FitzpatrickAction)with the actionEmojiParser.FitzpatrickAction.PARSEstatic @NotNull StringparseToHtmlDecimal(String input, EmojiParser.FitzpatrickAction fitzpatrickAction)Replaces the emoji's unicode occurrences by their html representation.static @NotNull StringparseToHtmlHexadecimal(@NotNull String input)SeeparseToHtmlHexadecimal(String, FitzpatrickAction)with the actionEmojiParser.FitzpatrickAction.PARSEstatic @NotNull StringparseToHtmlHexadecimal(@NotNull String input, @NotNull EmojiParser.FitzpatrickAction fitzpatrickAction)Replaces the emoji's unicode occurrences by their html hex representation.static @NotNull StringparseToUnicode(@NotNull String input)Replaces the emoji's aliases (between 2 ':') occurrences and the html representations by their unicode.static @NotNull StringremoveAllEmojis(@NotNull String str)Removes all emojis from a Stringstatic @NotNull StringremoveAllEmojisExcept(@NotNull String str, @NotNull Collection<? extends Emoji> emojisToKeep)Removes all the emojis in a String except a provided setstatic @NotNull StringremoveEmojis(@NotNull String str, @NotNull Collection<? extends Emoji> emojisToRemove)Removes a set of emojis from a Stringstatic @NotNull StringreplaceAllEmojis(@NotNull String str, @NotNull String replacementString)Replace all emojis with character
-
-
-
Method Detail
-
parseToAliases
@NotNull public static @NotNull String parseToAliases(@NotNull @NotNull String input)
SeeparseToAliases(String, FitzpatrickAction)with the actionEmojiParser.FitzpatrickAction.PARSE.- Parameters:
input- the string to parse- Returns:
- the string with the emojis replaced by their alias.
-
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_6When 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 parsefitzpatrickAction- 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 processreplacementString- 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(@NotNull @NotNull String input)
SeeparseToHtmlDecimal(String, FitzpatrickAction)with the actionEmojiParser.FitzpatrickAction.PARSE- Parameters:
input- the string to parse- Returns:
- the string with the emojis replaced by their html decimal representation.
-
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 parsefitzpatrickAction- 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)
SeeparseToHtmlHexadecimal(String, FitzpatrickAction)with the actionEmojiParser.FitzpatrickAction.PARSE- Parameters:
input- the string to parse- Returns:
- the string with the emojis replaced by their html hex 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 parsefitzpatrickAction- 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 processemojisToRemove- 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 processemojisToKeep- 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 processtransformer- emoji transformer to apply to each emoji- Returns:
- input string with all emojis transformed
-
-