Coder Social home page Coder Social logo

emoji-java's Introduction

emoji-java

Build Status Coverage Status License Info

The missing emoji library for java.

emoji-java is a lightweight java library that helps you use Emojis in your java applications.

How to get it?

Via Maven:
<dependency>
  <groupId>com.vdurmont</groupId>
  <artifactId>emoji-java</artifactId>
  <version>5.1.1</version>
</dependency>

You can also download the project, build it with mvn clean install and add the generated jar to your buildpath.

Via Gradle:
compile 'com.vdurmont:emoji-java:5.1.1'
Via Direct Download:

How to use it?

EmojiManager

The EmojiManager provides several static methods to search through the emojis database:

  • getForTag returns all the emojis for a given tag
  • getForAlias returns the emoji for an alias
  • getAll returns all the emojis
  • isEmoji checks if a string is an emoji
  • containsEmoji checks if a string contains any emoji

You can also query the metadata:

  • getAllTags returns the available tags

Or get everything:

  • getAll returns all the emojis

Emoji model

An Emoji is a POJO (plain old java object), which provides the following methods:

  • getUnicode returns the unicode representation of the emoji
  • getUnicode(Fitzpatrick) returns the unicode representation of the emoji with the provided Fitzpatrick modifier. If the emoji doesn't support the Fitzpatrick modifiers, this method will throw an UnsupportedOperationException. If the provided Fitzpatrick is null, this method will return the unicode of the emoji.
  • getDescription returns the (optional) description of the emoji
  • getAliases returns a list of aliases for this emoji
  • getTags returns a list of tags for this emoji
  • getHtmlDecimal returns an html decimal representation of the emoji
  • getHtmlHexadecimal returns an html decimal representation of the emoji
  • supportsFitzpatrick returns true if the emoji supports the Fitzpatrick modifiers, else false

Fitzpatrick modifiers

Some emojis now support the use of Fitzpatrick modifiers that gives the choice between 5 shades of skin tones:

Modifier Type
🏻 type_1_2
🏼 type_3
🏽 type_4
🏾 type_5
🏿 type_6

We defined the format of the aliases including a Fitzpatrick modifier as:

:ALIAS|TYPE:

A few examples:

:boy|type_1_2:
:swimmer|type_4:
:santa|type_6:

EmojiParser

To unicode

To replace all the aliases and the html representations found in a string by their unicode, use EmojiParser#parseToUnicode(String).

For example:

String str = "An :grinning:awesome :smiley:string &#128516;with a few :wink:emojis!";
String result = EmojiParser.parseToUnicode(str);
System.out.println(result);
// Prints:
// "An 😀awesome 😃string 😄with a few 😉emojis!"

To aliases

To replace all the emoji's unicodes found in a string by their aliases, use EmojiParser#parseToAliases(String).

For example:

String str = "An 😀awesome 😃string with a few 😉emojis!";
String result = EmojiParser.parseToAliases(str);
System.out.println(result);
// Prints:
// "An :grinning:awesome :smiley:string with a few :wink:emojis!"

By default, the aliases will parse and include any Fitzpatrick modifier that would be provided. If you want to remove or ignore the Fitzpatrick modifiers, use EmojiParser#parseToAliases(String, FitzpatrickAction). Examples:

String str = "Here is a boy: \uD83D\uDC66\uD83C\uDFFF!";
System.out.println(EmojiParser.parseToAliases(str));
System.out.println(EmojiParser.parseToAliases(str, FitzpatrickAction.PARSE));
// Prints twice: "Here is a boy: :boy|type_6:!"
System.out.println(EmojiParser.parseToAliases(str, FitzpatrickAction.REMOVE));
// Prints: "Here is a boy: :boy:!"
System.out.println(EmojiParser.parseToAliases(str, FitzpatrickAction.IGNORE));
// Prints: "Here is a boy: :boy:🏿!"

To html

To replace all the emoji's unicodes found in a string by their html representation, use EmojiParser#parseToHtmlDecimal(String) or EmojiParser#parseToHtmlHexadecimal(String).

For example:

String str = "An 😀awesome 😃string with a few 😉emojis!";

String resultDecimal = EmojiParser.parseToHtmlDecimal(str);
System.out.println(resultDecimal);
// Prints:
// "An &#128512;awesome &#128515;string with a few &#128521;emojis!"

String resultHexadecimal = EmojiParser.parseToHtmlHexadecimal(str);
System.out.println(resultHexadecimal);
// Prints:
// "An &#x1f600;awesome &#x1f603;string with a few &#x1f609;emojis!"

By default, any Fitzpatrick modifier will be removed. If you want to ignore the Fitzpatrick modifiers, use EmojiParser#parseToAliases(String, FitzpatrickAction). Examples:

String str = "Here is a boy: \uD83D\uDC66\uD83C\uDFFF!";
System.out.println(EmojiParser.parseToHtmlDecimal(str));
System.out.println(EmojiParser.parseToHtmlDecimal(str, FitzpatrickAction.PARSE));
System.out.println(EmojiParser.parseToHtmlDecimal(str, FitzpatrickAction.REMOVE));
// Print 3 times: "Here is a boy: &#128102;!"
System.out.println(EmojiParser.parseToHtmlDecimal(str, FitzpatrickAction.IGNORE));
// Prints: "Here is a boy: &#128102;🏿!"

The same applies for the methods EmojiParser#parseToHtmlHexadecimal(String) and EmojiParser#parseToHtmlHexadecimal(String, FitzpatrickAction).

Remove emojis

You can easily remove emojis from a string using one of the following methods:

  • EmojiParser#removeAllEmojis(String): removes all the emojis from the String
  • EmojiParser#removeAllEmojisExcept(String, Collection<Emoji>): removes all the emojis from the String, except the ones in the Collection
  • EmojiParser#removeEmojis(String, Collection<Emoji>): removes the emojis in the Collection from the String

For example:

String str = "An 😀awesome 😃string with a few 😉emojis!";
Collection<Emoji> collection = new ArrayList<Emoji>();
collection.add(EmojiManager.getForAlias("wink")); // This is 😉

System.out.println(EmojiParser.removeAllEmojis(str));
System.out.println(EmojiParser.removeAllEmojisExcept(str, collection));
System.out.println(EmojiParser.removeEmojis(str, collection));

// Prints:
// "An awesome string with a few emojis!"
// "An awesome string with a few 😉emojis!"
// "An 😀awesome 😃string with a few emojis!"

Extract Emojis from a string

You can search a string of mixed emoji/non-emoji characters and have all of the emoji characters returned as a Collection.

  • EmojiParser#extractEmojis(String): returns all emojis as a Collection. This will include duplicates if emojis are present more than once.

Credits

emoji-java originally used the data provided by the github/gemoji project. It is still based on it but has evolved since.

Available Emojis

See a table of the available emojis and their aliases HERE.

emoji-java's People

Contributors

0lumide avatar ankitkariryaa avatar b1rdex avatar billygalbreath avatar cbedoy avatar freva avatar frindly avatar gidim avatar jtobard avatar miquelbeltran avatar niij avatar roberterdin avatar sheigutn avatar sullis avatar t4deon avatar tapchicoma avatar vdurmont avatar whitecat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emoji-java's Issues

Emoji problem like \uE30f or \uExxx this is iOS code?

hello
i have some trouble,when is use your sdk insert emoji to mysql,some emoji like \uE401 or \uExxx
cannot trans like emoji.json emoji's description to mysql.

i think how to update emoji.json and i search google the emoji's list is a picture... embarrass..

so,i want to help, the start with \uExxx 's emoji, how to trans when use your emoji-java

!!wait I saw some different such as the emojis.json have tags is medicine
emoji is \uD83d\uDC8A
the picture is\uE30f
why..... get got some people's nicknime is \uExxx .... im..... im surrender...

image

Parsing no longer works when exported as jar file

Hello,

I'm using EmojiParser.parseToAliases(message) to convert emojis to to their aliases.

I'm reading messages from a third-party application which contain emojis.

I have two applications set up, one which I'm running from IntelliJ and one which is being exported as a .jar fille and executed via java -ver blah.jar

Whilst the pure Java application successfully parses the emoji to an alias, the exact same code exported as a .jar does not parse the emoji at all and still returns the emoji from EmojiParser.parseToAliases().

Happy to share some more code, thanks.

Missing emoji

Hello,

Apple added a bunch more emoji in October (http://blog.emojipedia.org/ios-9-1-emoji-changelog/). I tried to test by outputting all of them, extracting the message from my phone with TouchCopy and then running the result through your parser. Pretty good overall, but I noticed a few that were missing.

Also, I noticed a few that don't get picked up but which seem to have symbols already in a few editors, like ☺☮✡. Can we get these picked up by your parser too? In my project, these files are being saved to ANSI Latin 1 and I would like replace all symbols with some textual representation.

EmojiTest.java.txt

Rob
:)

getting all emojis from string

Hi,

Is there a better way to extract all emojis from a string?
This is what i'm doing atm

    public ArrayList<String> getAllEmojis(String str) {
        ArrayList<String> emojis = new ArrayList<>();
        for (Emoji emoji : EmojiManager.getAll()) {
            if (str.contains(emoji.getUnicode()))
                emojis.add(emoji.getUnicode());
        }
        return emojis;
    }

New artifact with extractEmojis?

I'm very interested in using extractEmojis however it was recently added and the current (3.2.0) artifact on Maven Central doesn't contain it.
Any idea when a new artifact is going to be published?

Compatibility with emoji with modifiers

In some emoji, it seems that there can be a modifier attached to give a standard emoji a certain color or appearance. This is similar to a Fitzpatrick modifier but seems to be handled a bit differently. One example of this is how state flags could be handled (see article here) Is there any plan to support something like this?

Here is one example of an emoji that renders in Android N but that the parser does not support well:
image

What Android N renders it as normally:
image

What Android N renders through the parser:
image

Note that this functionality is being added as part of Android N. The bottom image is what renders on M and below.
Please let me know if you have any questions.

v3.1.3 Source Doesn't Include #45 (Added emojis introduced in Unicode 9.0)

According to v3.1.3 release note (v3.1.3...master), pull request #45 is included. And when I do "git clone ...", I do see additional 72 emojis added by #45, which results in total 1347 emojis.

But I see only 1275 emojis (i.e. 72 emojis missing) if I do one of the following.

  1. In Gradle, add "compile 'com.vdurmont:emoji-java:3.1.3'".
  2. Download "https://github.com/vdurmont/emoji-java/archive/v3.1.3.tar.gz" and check "src/main/resources/emojis.json" file.
  3. Download "https://github.com/vdurmont/emoji-java/archive/v3.1.3.zip" and check "src/main/resources/emojis.json" file.
  4. Download "https://github.com/vdurmont/emoji-java/releases/download/v3.1.3/emoji-java-3.1.3.jar" and use "compile files('libs/emoji-java-3.1.3.jar')" in Gradle.

It looks like the 3.1.3 tag is placed at a wrong place.

* a616dd3 (HEAD -> master, origin/master, origin/HEAD) Update README include location of direct download in how to git, and download of necessary dependencies. (#55)
* 3ace39c Added emojis introduced in Unicode 9.0 (#45)
* 261dc28 Fixed tag of the Poland flag (#43)
* f06c0e3 (tag: v3.1.3) Release v3.1.3 <-- ??
__
sol

Wrong fitzpatrick settings, causes crash

Hi.

I have following snippet of code in the app:

            EmojiParser.parseFromUnicode(inputText, new EmojiParser.EmojiTransformer() {
            @Override
            public String transform(EmojiParser.UnicodeCandidate unicodeCandidate) {
                final String emoji = unicodeCandidate.hasFitzpatrick() ?
                        unicodeCandidate.getEmoji().getUnicode(unicodeCandidate.getFitzpatrick()) :
                        unicodeCandidate.getEmoji().getUnicode();
                // some other stuff that app is doing with emoji
                return "";
            }
        });

The problem is that unicodeCandidate.getEmoji().getUnicode(unicodeCandidate.getFitzpatrick() is crashing with following exception:

java.lang.UnsupportedOperationException: Cannot get the unicode with a fitzpatrick modifier, the emoji doesn't support fitzpatrick.
at com.vdurmont.emoji.Emoji.getUnicode(Emoji.java:137)

I suspect that emoji.json sets that this emoji doesn't support Fitzpatrick modifier, but actually it is.

I've taken Emoji 4.0 test list from here and run this method against every emoji.
Here is a list of emojis that are failing:

java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏻 1f575 1f3fb
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏼 1f575 1f3fc
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏽 1f575 1f3fd
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏾 1f575 1f3fe
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏿 1f575 1f3ff
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏻‍♂️ 1f575 1f3fb 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏻‍♂ 1f575 1f3fb 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏼‍♂️ 1f575 1f3fc 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏼‍♂ 1f575 1f3fc 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏽‍♂️ 1f575 1f3fd 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏽‍♂ 1f575 1f3fd 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏾‍♂️ 1f575 1f3fe 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏾‍♂ 1f575 1f3fe 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏿‍♂️ 1f575 1f3ff 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏿‍♂ 1f575 1f3ff 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏻‍♀️ 1f575 1f3fb 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏻‍♀ 1f575 1f3fb 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏼‍♀️ 1f575 1f3fc 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏼‍♀ 1f575 1f3fc 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏽‍♀️ 1f575 1f3fd 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏽‍♀ 1f575 1f3fd 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏾‍♀️ 1f575 1f3fe 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏾‍♀ 1f575 1f3fe 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏿‍♀️ 1f575 1f3ff 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🕵🏿‍♀ 1f575 1f3ff 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🏂🏻 1f3c2 1f3fb
java.lang.UnsupportedOperationException: Failed for emoji: 🏂🏼 1f3c2 1f3fc
java.lang.UnsupportedOperationException: Failed for emoji: 🏂🏽 1f3c2 1f3fd
java.lang.UnsupportedOperationException: Failed for emoji: 🏂🏾 1f3c2 1f3fe
java.lang.UnsupportedOperationException: Failed for emoji: 🏂🏿 1f3c2 1f3ff
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏻 1f6a3 1f3fb
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏼 1f6a3 1f3fc
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏽 1f6a3 1f3fd
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏾 1f6a3 1f3fe
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏿 1f6a3 1f3ff
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏻‍♂️ 1f6a3 1f3fb 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏻‍♂ 1f6a3 1f3fb 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏼‍♂️ 1f6a3 1f3fc 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏼‍♂ 1f6a3 1f3fc 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏽‍♂️ 1f6a3 1f3fd 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏽‍♂ 1f6a3 1f3fd 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏾‍♂️ 1f6a3 1f3fe 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏾‍♂ 1f6a3 1f3fe 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏿‍♂️ 1f6a3 1f3ff 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏿‍♂ 1f6a3 1f3ff 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏻‍♀️ 1f6a3 1f3fb 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏻‍♀ 1f6a3 1f3fb 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏼‍♀️ 1f6a3 1f3fc 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏼‍♀ 1f6a3 1f3fc 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏽‍♀️ 1f6a3 1f3fd 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏽‍♀ 1f6a3 1f3fd 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏾‍♀️ 1f6a3 1f3fe 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏾‍♀ 1f6a3 1f3fe 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏿‍♀️ 1f6a3 1f3ff 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🚣🏿‍♀ 1f6a3 1f3ff 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏻 26f9 1f3fb
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏼 26f9 1f3fc
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏽 26f9 1f3fd
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏾 26f9 1f3fe
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏿 26f9 1f3ff
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏻‍♂️ 26f9 1f3fb 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏻‍♂ 26f9 1f3fb 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏼‍♂️ 26f9 1f3fc 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏼‍♂ 26f9 1f3fc 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏽‍♂️ 26f9 1f3fd 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏽‍♂ 26f9 1f3fd 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏾‍♂️ 26f9 1f3fe 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏾‍♂ 26f9 1f3fe 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏿‍♂️ 26f9 1f3ff 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏿‍♂ 26f9 1f3ff 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏻‍♀️ 26f9 1f3fb 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏻‍♀ 26f9 1f3fb 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏼‍♀️ 26f9 1f3fc 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏼‍♀ 26f9 1f3fc 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏽‍♀️ 26f9 1f3fd 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏽‍♀ 26f9 1f3fd 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏾‍♀️ 26f9 1f3fe 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏾‍♀ 26f9 1f3fe 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏿‍♀️ 26f9 1f3ff 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: ⛹🏿‍♀ 26f9 1f3ff 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏻 1f3cb 1f3fb
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏼 1f3cb 1f3fc
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏽 1f3cb 1f3fd
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏾 1f3cb 1f3fe
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏿 1f3cb 1f3ff
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏻‍♂️ 1f3cb 1f3fb 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏻‍♂ 1f3cb 1f3fb 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏼‍♂️ 1f3cb 1f3fc 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏼‍♂ 1f3cb 1f3fc 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏽‍♂️ 1f3cb 1f3fd 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏽‍♂ 1f3cb 1f3fd 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏾‍♂️ 1f3cb 1f3fe 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏾‍♂ 1f3cb 1f3fe 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏿‍♂️ 1f3cb 1f3ff 200d 2642 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏿‍♂ 1f3cb 1f3ff 200d 2642
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏻‍♀️ 1f3cb 1f3fb 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏻‍♀ 1f3cb 1f3fb 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏼‍♀️ 1f3cb 1f3fc 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏼‍♀ 1f3cb 1f3fc 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏽‍♀️ 1f3cb 1f3fd 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏽‍♀ 1f3cb 1f3fd 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏾‍♀️ 1f3cb 1f3fe 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏾‍♀ 1f3cb 1f3fe 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏿‍♀️ 1f3cb 1f3ff 200d 2640 fe0f
java.lang.UnsupportedOperationException: Failed for emoji: 🏋🏿‍♀ 1f3cb 1f3ff 200d 2640
java.lang.UnsupportedOperationException: Failed for emoji: 🛌🏻 1f6cc 1f3fb
java.lang.UnsupportedOperationException: Failed for emoji: 🛌🏼 1f6cc 1f3fc
java.lang.UnsupportedOperationException: Failed for emoji: 🛌🏽 1f6cc 1f3fd
java.lang.UnsupportedOperationException: Failed for emoji: 🛌🏾 1f6cc 1f3fe
java.lang.UnsupportedOperationException: Failed for emoji: 🛌🏿 1f6cc 1f3ff

Remove All Emojis not remove complete

I have a issue when use EmojiParser.removeAllEmojis() method.

The String unicode is "Name ❤️ lastname". After using this method, the returned string is "Name Lastname", but between names, have a another chars that not is blank spaces.

java.lang.NoClassDefFoundError

Hi, Would you please help me with this exception. if possible. Thanks in advance.

no_class_found_error

i am using compile 'com.vdurmont:emoji-java:3.1.3' in gradle file.

getAllEmojis returns duplicate emojis

I think this returns duplicate Emojis - maybe return a Set of some kind?

public static Collection<Emoji> getAll() {
    return EMOJIS_BY_ALIAS.values();
}

Exception in EmojiParser

Just had this exception and I don't know how to fix it.

I run it on Java 1.6:

java.lang.ExceptionInInitializerError at com.vdurmont.emoji.EmojiParser.getEmojiEndPos(EmojiParser.java:420) at com.vdurmont.emoji.EmojiParser.getUnicodeCandidates(EmojiParser.java:382) at com.vdurmont.emoji.EmojiParser.parseFromUnicode(EmojiParser.java:355) at com.vdurmont.emoji.EmojiParser.parseToHtmlDecimal(EmojiParser.java:213) at com.vdurmont.emoji.EmojiParser.parseToHtmlDecimal(EmojiParser.java:172) at com.zwischengas.resource.teaser.auto2.AutoTeaserPage2016Resource.addElementsForRead(AutoTeaserPage2016Resource.java:754) at com.zwischengas.resource.GeneralZwischengasResource.getContentXML(GeneralZwischengasResource.java:590) at com.zwischengas.resource.GeneralZwischengasResource.getView(GeneralZwischengasResource.java:416) at org.wyona.yanel.servlet.YanelServlet.getContent(YanelServlet.java:599) at org.wyona.yanel.servlet.YanelServlet.doGet(YanelServlet.java:429) at org.wyona.yanel.servlet.YanelServlet.service(YanelServlet.java:333) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.wyona.yanel.servlet.communication.YanelFilter.doFilter(YanelFilter.java:37) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:695) Caused by: java.lang.NullPointerException at java.io.Reader.<init>(Reader.java:61) at java.io.InputStreamReader.<init>(InputStreamReader.java:55) at com.vdurmont.emoji.EmojiLoader.inputStreamToString(EmojiLoader.java:51) at com.vdurmont.emoji.EmojiLoader.loadEmojis(EmojiLoader.java:36) at com.vdurmont.emoji.EmojiManager.<clinit>(EmojiManager.java:29)

Wrong HTML Codes

Some emojis, are a combination of several emojis seperated by the zero width joiner \U200D, such as

family (man, man, boy)
family (man, man, girl)
family (man, man, girl, boy)
family (man, man, boy, boy)
family (man, man, girl, girl)

but when computing the HTML Codes, you use Character.codePointAt(this.unicode, 0) which gets only the first code point, and as a result all the examples above all have the same HTML code as the man emoji, which is &#128104;

"Ear" and "Nose" should support fitzpatrick modifier

They don't, in the json. But they do on iOS.

Code change:
line 1040:
{
"emoji": "👂",
"description": "ear",
"supports_fitzpatrick": true,
"aliases": [
"ear"
],
"tags": [
"hear",
"sound",
"listen"
]
},

line 1065:
{
"emoji": "👃",
"description": "nose",
"supports_fitzpatrick": true,
"aliases": [
"nose"
],
"tags": [
"smell"
]
},

parseToAliases not work

Version: 3.1.3

The string "\uD83D\uDC69\u200D❤️\u200D\uD83D\uDC69"
should be resolved by parseToAliases to 👩‍❤️‍💋‍👩 (:couplekiss_woman_woman:)
but parsed into :woman:‍:heart::kiss::woman: instead.

New Emoji's Not Yet Added?

Hi! It appears that the emoji database is current as of Unicode 8.0. Unicode 9.0 and above emojis are not supported? Can someone please confirm that is the case?
In addition, is the emoji database still based on gemoji? Gemoji's emoji registry has not been updated for 5 months.
Updating emoji.json is very quick and easy and I can submit a commit right away.

Downloadable Jar Library

There should be a jar file in the project that can just be downloaded. Some people don't have or use maven or gradle.

ExceptionInInitializerError when Running emoji-java using the code

I was trying to run your application using the source code and it keeps throwing me ExceptionInInitializerError. Here's the exception I see.
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.vdurmont.emoji.EmojiParser.parseToAliases(EmojiParser.java:53)
at com.vdurmont.emoji.EmojiParser.parseToAliases(EmojiParser.java:28)
at com.vdurmont.emoji.MainClass.main(MainClass.java:8)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException: source
at com.vdurmont.emoji.EmojiManager.(EmojiManager.java:39)
... 3 more
Caused by: java.lang.NullPointerException: source
at java.util.Scanner.makeReadable(Scanner.java:629)
at java.util.Scanner.(Scanner.java:622)
at com.vdurmont.emoji.EmojiLoader.inputStreamToString(EmojiLoader.java:45)
at com.vdurmont.emoji.EmojiLoader.loadEmojis(EmojiLoader.java:33)
at com.vdurmont.emoji.EmojiManager.(EmojiManager.java:25)
... 3 more

I'm passing the correct file path to emojis.json file, but still it fails to read from the stream. I could not find much info by debuging the code, so though of posting here to get your view on why this happens.
Thank you in advance!

Memory Leak

EmojiLoader:InputStreamToString has a Scanner that's never closed.

In applications that stay alive and call this project completely from scratch, it's possible this will eventually cause a failure.

U+263A Emoticon does not get detected or removed

The ☺(:relaxed:) emoji (U+263A), does not get removed if you call EmojiParser::removeAllEmojis. This is probably because it's in the 2600-26FF (Miscellaneous Symbols) block. At least android does encode the :relaxed: emoji as (U+263A).

Backwards Compatibility

I don't know if this is an 'issue' or not, but using this library to parse for, say, an Android device will have non-optimal results if a Unicode 8.0 emoji comes in.

Though fitzpatrick modifiers can be removed, 'unsupported' emoji may want to have an alternative (for example, for those parsing from, and then back to, emoji). A zipper-face emoji could be transformed to a regular face, as one example.

This issue will hopefully EVENTUALLY be overcome by events when Android has up-to-date emoji support, but will also be necessary for at least some time for iOS devices without the latest update after they are added, after Unicode 9.0 comes out sometime this year.

There is an error in repackaged after running

5-Mar-2017 16:08:34.911 SEVERE [http-nio-8080-exec-8] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [spring] in context with path [evy_interfaces] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.vdurmont.emoji.EmojiManager] with root cause
java.lang.NoClassDefFoundError: Could not initialize class com.vdurmont.emoji.EmojiManager

why:After repackaging, found itself without a jar (org.json)

EmojiManager doesn't detect emoji with fitzpatric modifier

Currently I was checking missing emoji in json from emoji test data and found out that

        emoji = "\uD83E\uDD30\uD83C\uDFFB"; \\Pregnant woman light skin tone
        assertTrue("Asserting for emoji: " + emoji, EmojiManager.isEmoji(emoji));

fails, cause EmojiManager doesn't detect emoji with fitzpatric modifier.

isEmoji not detecting multiple emoji

If you pass a string containing a single emoji to the isEmoji method, it returns true as expected
but if you pass a sttring containing only two emojis, it returns false

EmojiManager.isEmoji("😄");  //returns true
EmojiManager.isEmoji("😄😃"); //returns false

Is this the intentional behaviour?

:-1: cannot be parsed to Unicode

:-1: currently cannot be parsed to 👎 (doesn't replace :-1: with the 👎 unicode). I think this is pretty similar to a closed isssue about 👍 . Parsing :+1: to 👍 still works.

Parsing :thumbsdown: works fine, but when I parse the thumbsdown unicode to alias, it returns as :-1:. Parsing this result back to unicode fails and just returns as :-1:.

Missing Fitzgerald types

Is there a reason that person_with_ball and weight_lifter have supports_fitzpatrick set to false?

Also, ✌️ and ☝️ and 🙇 didn't have the setting.

I'm working on a branch and after I hear back I can make a pull request.

run with -Xss256k get stack overflow exception

I get stack overflow exception when run following test with -Xss256k:


public class EmojiTest {
    public static void main(String[] args) {
        String str = "An 😀awesome 😃string with a few 😉emojis!";

        String resultDecimal = EmojiParser.parseToHtmlDecimal(str);
        System.out.println(resultDecimal);
    }
}

and the cause is EmojiLoader.inputStreamToString method, which used \A as delimiter to read content from emojis.json.


 private static String inputStreamToString(InputStream stream) {
        Scanner s = new Scanner(stream, "UTF-8").useDelimiter("\\A");
        return s.hasNext() ? s.next() : "";
    }

I don't know why you use a scanner to read the content.
Why not just read the whole file with BuffredReader, which consumes less resource and is much more clearer?

Custom replacement policy

Currently there is no (simple) way to customize the replacement of unicode emojis, for example, if someone wants to change the prefix and suffixes used by parseToAlias(), one would actually have to not only re-implement the entire parseToAlias(), but also copy over the EmojiTrie(because the Matchesenum inside it is package-private).

I propose to define EmojiTransformerinterface that requires a String transform(UnicodeCandidate unicodeCandidate). Then make a general transformation method:

    public static String parseFromUnicode(String input, EmojiTransformer transformer) {
        int prev = 0;
        StringBuilder sb = new StringBuilder();
        List<UnicodeCandidate> replacements = getUnicodeCandidates(input);
        for(UnicodeCandidate candidate : replacements) {
            sb.append(input.substring(prev, candidate.startIndex));

            sb.append(transformer.transform(candidate));
            prev = candidate.getEndIndexWithFitzpatrick();
        }

        return sb.append(input.substring(prev)).toString();
    }

Now any transformation can performed by sending in EmojiTransformer instance. As a proof-of-concept, I changed all from-unicode parsers in EmojiParser to use this model:

    public static String parseToAliases(String input, final FitzpatrickAction fitzpatrickAction) {
        EmojiTransformer emojiTransformer = new EmojiTransformer() {
            public String transform(UnicodeCandidate unicodeCandidate) {
                switch (fitzpatrickAction) {
                    default:
                    case PARSE:
                        if(unicodeCandidate.hasFitzpatrick()) {
                            return ":" + unicodeCandidate.getEmoji().getAliases().get(0) + "|" +
                                    unicodeCandidate.getFitzpatrickType() + ":";
                        }

                    case REMOVE:
                    return ":" + unicodeCandidate.getEmoji().getAliases().get(0) + ":";

                    case IGNORE:
                    return ":" + unicodeCandidate.getEmoji().getAliases().get(0) + ":" +
                                unicodeCandidate.getFitzpatrickUnicode();

                }
            }
        };

        return parseFromUnicode(input, emojiTransformer);
    }


    public static String parseToHtmlDecimal(String input, final FitzpatrickAction fitzpatrickAction) {
        EmojiTransformer emojiTransformer = new EmojiTransformer() {
            public String transform(UnicodeCandidate unicodeCandidate) {
                switch (fitzpatrickAction) {
                    default:
                    case PARSE:
                    case REMOVE:
                        return unicodeCandidate.getEmoji().getHtmlDecimal();

                    case IGNORE:
                        return unicodeCandidate.getEmoji().getHtmlDecimal() + unicodeCandidate.getFitzpatrickUnicode();
                }
            }
        };

        return parseFromUnicode(input, emojiTransformer);
    }


    public static String parseToHtmlHexadecimal(String input, final FitzpatrickAction fitzpatrickAction) {
        EmojiTransformer emojiTransformer = new EmojiTransformer() {
            public String transform(UnicodeCandidate unicodeCandidate) {
                switch (fitzpatrickAction) {
                    default:
                    case PARSE:
                    case REMOVE:
                        return unicodeCandidate.getEmoji().getHtmlHexidecimal();

                    case IGNORE:
                        return unicodeCandidate.getEmoji().getHtmlHexidecimal() + unicodeCandidate.getFitzpatrickUnicode();
                }
            }
        };

        return parseFromUnicode(input, emojiTransformer);
    }


    public static String removeAllEmojis(String str) {
        EmojiTransformer emojiTransformer = new EmojiTransformer() {
            public String transform(UnicodeCandidate unicodeCandidate) {
                return "";
            }
        };

        return parseFromUnicode(str, emojiTransformer);
    }


    public static String removeEmojis(String str, final Collection<Emoji> emojisToRemove) {
        EmojiTransformer emojiTransformer = new EmojiTransformer() {
            public String transform(UnicodeCandidate unicodeCandidate) {
                if (! emojisToRemove.contains(unicodeCandidate.getEmoji())) {
                    return unicodeCandidate.getEmoji().getUnicode() + unicodeCandidate.getFitzpatrickUnicode();
                }
                return "";
            }
        };

        return parseFromUnicode(str, emojiTransformer);
    }


    public static String removeAllEmojisExcept(String str, final Collection<Emoji> emojisToKeep) {
        EmojiTransformer emojiTransformer = new EmojiTransformer() {
            public String transform(UnicodeCandidate unicodeCandidate) {
                if (emojisToKeep.contains(unicodeCandidate.getEmoji())) {
                    return unicodeCandidate.getEmoji().getUnicode() + unicodeCandidate.getFitzpatrickUnicode();
                }
                return "";
            }
        };

        return parseFromUnicode(str, emojiTransformer);
    }

I then ran a quick performance test on this for fun, and for 10k tweets the results were inconclusive, for 1m tweets the new method was twice as fast, so I went all-in and tested with 82.5m tweets and got:

Took 433510ms with the new method against 1099736ms with the old method

Only disadvantage with this method is that it doesn't look super pretty, but in Java 8 i looks way nicer, for example:

String parsed = EmojiParser.parseFromUnicode("test", e -> " ||" + e.getEmoji().getAliases().get(0) + "|| ");

Which replaces Here is a boy: \uD83D\uDC66! to Here is a boy: ||boy|| !

I'm not sure if there are better ways of doing this, if you like this one, I can submit a pull request.

Add old style emoji

Hello,
First of all, I want to thank you for your work, it's really useful.

From what I have seen, the library misses the old style emoji transformation, like the simple
:) that should translate into 😄
... and similar.
You can find here a list:

(":-)", 0x1F60A)
(":)", 0x1F60A)
(":-(", 0x1F61E)
(":(", 0x1F61E)
(":-D", 0x1F603)
(":D", 0x1F603)
(";-)", 0x1F609)
(";)", 0x1F609)
(":-P", 0x1F61C)
(":P", 0x1F61C)
(":-p", 0x1F61C)
(":p", 0x1F61C)
(":-*", 0x1F618)
(":*", 0x1F618)
("<3", 0x2764)
(":3", 0x2764)
(">:[", 0x1F621)
(":'|", 0x1F625)
(":-[", 0x1F629)
(":'(", 0x1F62D)
("=O", 0x1F631)
("xD", 0x1F601)
(":')", 0x1F602)
(":-/", 0x1F612)
(":/", 0x1F612)
(":-|", 0x1F614)
(":|", 0x1F614)
("*_*", 0x1F60D)

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.