vdurmont / emoji-java Goto Github PK
View Code? Open in Web Editor NEWThe missing emoji library for Java :heart:
License: MIT License
The missing emoji library for Java :heart:
License: MIT License
From the json in master:
{
"emoji": "❤️",
"description": "heavy black heart",
"aliases": [
"heart"
],
"tags": [
"love"
]
},
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.
Rob
:)
It seems like the 😎 emoji isn't being parsed correctly for me. Is this a known issue?
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?
There are a bunch of new emojis in iOS 10.2 (see http://blog.emojipedia.org/ios-10-2-emoji-changelog/) and it does not seem the parser recognizes them.
All the new emojis are here: http://emojipedia.org/apple/ios-10.2/new/
There should be a jar file in the project that can just be downloaded. Some people don't have or use maven or gradle.
NG (no good) is one unicode point, and the Nigerian flag is 2. Regional Indicator N + Regional Indicator G together ought make, and do make (on Mac, anyays, when put together) the Nigerian flag.
But the quared NG (http://www.iemoji.com/view/emoji/558/symbols/squared-ng) when run through this system is recognized as the Nigerian flag. Can't tell why.
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.
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.
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!
Android 6.0.1 and iOS 9.3 include emoji that are not currently covered by this project.
I'll update this as I discover which specific ones, but for now:
Flag for St. Vincent and the Grenadines: http://emojipedia.org/flag-for-st-vincent-grenadines/
I download release and add the jar to my build path.
Then I add code:
String input = "A string 😄with a \uD83D\uDC66\uD83C\uDFFFfew 😉emojis!";
String result = EmojiParser.removeAllEmojis(input);
I get the error: NoClassDefFoundError: org/json/JSONArray
I found http://mvnrepository.com/artifact/org.json/json/20080701 which has a JSONArray class. But is that the correct JSONArray?
Could this emoji be included? 😂
It is a common one in social media
http://apps.timwhitlock.info/unicode/inspect?s=%F0%9F%98%82
Thanks!!
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"
]
},
it i have to emojiis one by one of instance:
����
the output is
:grinning:��
while the result should be :
:grinning::joy
:
Apple added new emoji's this month (April). Will they be added in a certain timeframe?
http://blog.emojipedia.org/apple-2015-emoji-changelog-ios-os-x
EmojiParser#parseToUnicode(String)
should convert the :tm:
alias to a Trademark symbol, however, it converts it to a Turkmenistan flag.
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...
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)
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?
I think this returns duplicate Emojis - maybe return a Set of some kind?
public static Collection<Emoji> getAll() {
return EMOJIS_BY_ALIAS.values();
}
using parseToUnicode, I can not parse back " : +1:" to 👍。
:-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:
.
It is possible to force rendering of emojis as text: http://mts.io/2015/04/21/unicode-symbol-render-text-emoji/
It would be nice (even though not necessarily widely used :) ) to have this as an option or as a separate API call such as toTextEmoji
Hi when I call EmojiParser.parseToAliases() for example "😀😃"
I have this result :
😀��
But if use it like this "😀 😃" it works !
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
Currently emoji.json missing definition for 1665 emoji from unicode 9.0 standard. Need to add them as well.
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.
We should have:
BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
(Posting an issue because I cannot take care of it right now so if someone wants to send a PR, this one is easy 😄 )
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).
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.
Hi, can you please tell me if you are referencing all the emoticons that are here :
https://www.webpagefx.com/tools/emoji-cheat-sheet/
I'm especially intersted in the slack ones ;-p
Thanks in advance for your answer.
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?
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:
What Android N renders it as normally:
What Android N renders through the parser:
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.
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;
}
I have a working project no recognizing apple emojis. No recognizing emojis is 1995 emoji year.
It lists "http://unicode.org/emoji/charts/full-emoji-list.html"
It currently does not.
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 👨
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 Matches
enum inside it is package-private).
I propose to define EmojiTransformer
interface 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.
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.
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)
3.0.0 is ok, but the newer version 3.1.0 and 3.1.1 dose not work.
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.
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
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!
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.
Is there any chance that the rest of the emojis in Emoji 5.0 that currently aren't available, to be added?
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.
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.
shortnames are as folows :family_mwg: and 👦
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.