Skip to content

Commit eab6a21

Browse files
committed
Added support for {gender}{skin_kolor}?{basic_emoji}
Update emoji list
1 parent e6efd33 commit eab6a21

File tree

9 files changed

+1481
-353
lines changed

9 files changed

+1481
-353
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Java
22
target
33
out
4+
/src/main/java/META-INF/
45

56
# IntelliJ files
67
*.iml
7-
.idea
8+
.idea
9+
.gitignore

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# Changelog
22

3+
## v6.1i
4+
- Added support of complex emoji sequences of type **`{gender}{skin_kolor}?{basic_emoji}`**
5+
- Due to it `emojis.json` boolean parameter `supports_fitzpatrick` was changed to `sequence_type`.<br>
6+
1 — for supporting `{basic_emoji}{skin_color}?{gender}?`<br>
7+
2 — for supporting `{gender}{skin_kolor}?{basic_emoji}` (but there are only 3 emojis of such type: person, man and woman)
8+
- Emojis list was updated to Emoji Version 13.0.
9+
<br>**+150 emojis**, not counting combinations of skin color, hair color or gender
10+
311
## v6.0i
412

513
- Ivan Ivanov forked main repository
614
- Added class `Gender`
7-
- Added understanding of complex emojies: `{basic_emoji}{skin_color}?{gender}?`
15+
- Added support of complex emoji sequences of type `{basic_emoji}{skin_color}?{gender}?`
816
- Added support of bugged VK.COM web-version emojis, where ending char `\uFE0F` is absent
917
- `EmojiParser.UnicodeCandidate` renamed to `EmojiParser.EmojiResult`. And added new fields
1018
- `EmojiParser` algorithm improvement. `getEmojiEndPos` is replaced with `getNextEmoji`<br>

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It was forked from **[emoji-java](https://github.com/vdurmont/emoji-java)**
1111
#### Reasons I forked it:
1212

1313
- ❗️ The most important reason I forked it was I have found how to improve its __speed up to 5x__ times!
14-
- My repo supports complex emojis of combination `{basic_emoji}{skin_color}?{gender}?`
14+
- ✅ This tool supports complex emoji sequences of types `{basic_emoji}{skin_color}?{gender}?` and `{gender}{skin_kolor}?{basic_emoji}`
1515
- It supports of bugged VK.COM web-version emojis, where ending char `\uFE0F` is absent
1616

1717
And of course, extend useful methods.
@@ -192,7 +192,7 @@ You can search a string of mixed emoji/non-emoji characters and have all of the
192192

193193
## Credits
194194

195-
**iris-emoji-java** is based on [github/vdurmont/emoji-java](https://github.com/vdurmont/emoji-java).
195+
**[iris-emoji-java](https://github.com/iris2iris/iris-emoji-java)** is based on [github/vdurmont/emoji-java](https://github.com/vdurmont/emoji-java).
196196

197197
And in its turn **emoji-java** originally used the data provided by the [github/gemoji project](https://github.com/github/gemoji). It is still based on it but has evolved since.
198198

src/main/java/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Class-Path: json-20170516.jar
3+

src/main/java/com/vdurmont/emoji/Emoji.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.List;
55

66
/**
7-
* This classrerуауаefefeere represents an emoji.<br>
7+
* This class represents an emoji.<br>
88
* <br>
99
* This object is immutable so it can be used safely in a multithreaded context.
1010
*
@@ -14,30 +14,35 @@
1414
public class Emoji {
1515
public final String description;
1616
public final boolean supportsFitzpatrick;
17+
public final int sequenceType;
1718
public final List<String> aliases;
1819
public final List<String> tags;
1920
public final String unicode;
2021
public final String htmlDec;
2122
public final String htmlHex;
2223

24+
public static final int SEQUENCE_BASE_SKIN_GENDER = 1;
25+
public static final int SEQUENCE_GENDER_SKIN_BASE = 2;
26+
2327
/**
2428
* Constructor for the Emoji.
2529
*
26-
* @param description The description of the emoji
27-
* @param supportsFitzpatrick Whether the emoji supports Fitzpatrick modifiers
28-
* @param aliases the aliases for this emoji
29-
* @param tags the tags associated with this emoji
30-
* @param bytes the bytes that represent the emoji
30+
* @param description The description of the emoji
31+
* @param sequenceType Whether the emoji supports Fitzpatrick modifiers
32+
* @param aliases the aliases for this emoji
33+
* @param tags the tags associated with this emoji
34+
* @param bytes the bytes that represent the emoji
3135
*/
3236
protected Emoji(
3337
String description,
34-
boolean supportsFitzpatrick,
38+
int sequenceType,
3539
List<String> aliases,
3640
List<String> tags,
3741
byte... bytes
3842
) {
3943
this.description = description;
40-
this.supportsFitzpatrick = supportsFitzpatrick;
44+
this.sequenceType = sequenceType;
45+
this.supportsFitzpatrick = sequenceType != 0;
4146
this.aliases = aliases;
4247
this.tags = tags;
4348

src/main/java/com/vdurmont/emoji/EmojiLoader.java

Lines changed: 14 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import org.json.JSONArray;
44
import org.json.JSONObject;
55

6-
import java.io.*;
6+
import java.io.BufferedReader;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.io.InputStreamReader;
710
import java.nio.charset.StandardCharsets;
811
import java.util.ArrayList;
912
import java.util.List;
@@ -55,137 +58,29 @@ private static String inputStreamToString(
5558
br.close();
5659
return sb.toString();
5760
}
58-
/*
59-
private static final String[][] gender1 = {
60-
{"adult", "\uD83E\uDDD1"}
61-
, {"male", "\uD83D\uDC68"}
62-
, {"female", "\uD83D\uDC69"}
63-
};
64-
private static final String[][] gender2 = {
65-
{"male", "\u200D♂️"}
66-
, {"female", "\u200D♀️"}
67-
};
6861

69-
private static final String[][] skins = {
70-
{"white", "\uD83C\uDFFB"}
71-
, {"cream white", "\uD83C\uDFFC"}
72-
, {"moderate brown", "\uD83C\uDFFD"}
73-
, {"dark brown", "\uD83C\uDFFE"}
74-
, {"black", "\uD83C\uDFFF"}
75-
};
76-
77-
protected static List<Emoji> buildEmojiesFromJSON(JSONObject json) throws UnsupportedEncodingException {
62+
protected static Emoji buildEmojiFromJSON(JSONObject json) {
7863
if (!json.has("emoji")) {
7964
return null;
8065
}
81-
82-
String pattern = json.getString("emoji");
83-
List<String> aliases = jsonArrayToStringList(json.getJSONArray("aliases"));
84-
EmojiPrepare[] emojies;
85-
if (pattern.indexOf('{') != -1) {
86-
boolean hasGender1 = pattern.contains("{person}");
87-
boolean hasGender2 = pattern.contains("{gender}");
88-
boolean hasSkin = pattern.contains("{skin}");
89-
var patterns = new LinkedList<EmojiPrepare>();
90-
patterns.add(new EmojiPrepare(pattern, aliases));
91-
92-
if (hasSkin) {
93-
var tmp = new LinkedList<EmojiPrepare>();
94-
for (EmojiPrepare i : patterns) {
95-
tmp.add(new EmojiPrepare(i.pattern.replace("{skin}", ""), aliases));
96-
for (String[] g : skins) {
97-
var aa = new LinkedList<String>();
98-
for (String a : i.aliases)
99-
aa.add(g[0] + ' ' + a);
100-
var newPattern = i.pattern.replace("{skin}", g[1]);
101-
tmp.add(new EmojiPrepare(newPattern, aa));
102-
}
103-
}
104-
patterns = tmp;
105-
}
106-
107-
if (hasGender1) {
108-
var tmp = new LinkedList<EmojiPrepare>();
109-
for (EmojiPrepare i : patterns)
110-
for (String[] g : gender1) {
111-
var aa = new LinkedList<String>();
112-
for (String a : i.aliases)
113-
aa.add(g[0] + ' ' + a);
114-
var newPattern = i.pattern.replace("{person}", g[1]);
115-
tmp.add(new EmojiPrepare(newPattern, aa));
116-
}
117-
patterns = tmp;
118-
}
119-
120-
if (hasGender2) {
121-
var tmp = new LinkedList<EmojiPrepare>();
122-
for (EmojiPrepare i : patterns)
123-
for (String[] g : gender2) {
124-
tmp.add(new EmojiPrepare(i.pattern.replace("{gender}", ""), aliases));
125-
var aa = new LinkedList<String>();
126-
for (String a : i.aliases)
127-
aa.add(g[0] + ' ' + a);
128-
var newPattern = i.pattern.replace("{gender}", g[1]);
129-
tmp.add(new EmojiPrepare(newPattern, aa));
130-
}
131-
patterns = tmp;
132-
}
133-
134-
135-
136-
emojies = patterns.toArray(new EmojiPrepare[0]);
137-
138-
} else
139-
emojies = new EmojiPrepare[] {new EmojiPrepare(pattern, aliases)};
140-
String description = null;
141-
if (json.has("description")) {
142-
description = json.getString("description");
143-
}
144-
boolean supportsFitzpatrick = false;
145-
if (json.has("supports_fitzpatrick")) {
146-
supportsFitzpatrick = json.getBoolean("supports_fitzpatrick");
147-
}
148-
149-
List<String> tags = jsonArrayToStringList(json.getJSONArray("tags"));
150-
151-
ArrayList<Emoji> res = new ArrayList<>();
152-
for (EmojiPrepare emoji : emojies) {
153-
byte[] bytes = emoji.pattern.getBytes(StandardCharsets.UTF_8);
154-
res.add(new Emoji(description, supportsFitzpatrick, emoji.aliases, tags, bytes));
155-
}
156-
return res;
157-
//return new Emoji(description, supportsFitzpatrick, aliases, tags, bytes);
158-
}
159-
160-
private static final class EmojiPrepare {
161-
List<String> aliases;
162-
String pattern;
163-
164-
public EmojiPrepare(String patter, List<String> aliases) {
165-
this.aliases = aliases;
166-
this.pattern = patter;
167-
}
168-
}*/
169-
170-
protected static Emoji buildEmojiFromJSON(
171-
JSONObject json
172-
) throws UnsupportedEncodingException {
173-
if (!json.has("emoji")) {
66+
var unicode = json.getString("emoji");
67+
// Lifehach to filter out old emojis map from wrong gender_base records
68+
if (unicode.startsWith("\uD83D\uDC69\u200D") || unicode.startsWith("\uD83D\uDC68\u200D"))
17469
return null;
175-
}
17670

177-
byte[] bytes = json.getString("emoji").getBytes(StandardCharsets.UTF_8);
71+
byte[] bytes = unicode.getBytes(StandardCharsets.UTF_8);
72+
17873
String description = null;
17974
if (json.has("description")) {
18075
description = json.getString("description");
18176
}
182-
boolean supportsFitzpatrick = false;
183-
if (json.has("supports_fitzpatrick")) {
184-
supportsFitzpatrick = json.getBoolean("supports_fitzpatrick");
77+
int sequenceType = 0;
78+
if (json.has("sequence_type")) {
79+
sequenceType = json.getInt("sequence_type");
18580
}
18681
List<String> aliases = jsonArrayToStringList(json.getJSONArray("aliases"));
18782
List<String> tags = jsonArrayToStringList(json.getJSONArray("tags"));
188-
return new Emoji(description, supportsFitzpatrick, aliases, tags, bytes);
83+
return new Emoji(description, sequenceType, aliases, tags, bytes);
18984
}
19085

19186
private static List<String> jsonArrayToStringList(JSONArray array) {

0 commit comments

Comments
 (0)