|
3 | 3 | import org.json.JSONArray; |
4 | 4 | import org.json.JSONObject; |
5 | 5 |
|
6 | | -import java.io.*; |
| 6 | +import java.io.BufferedReader; |
| 7 | +import java.io.IOException; |
| 8 | +import java.io.InputStream; |
| 9 | +import java.io.InputStreamReader; |
7 | 10 | import java.nio.charset.StandardCharsets; |
8 | 11 | import java.util.ArrayList; |
9 | 12 | import java.util.List; |
@@ -55,137 +58,29 @@ private static String inputStreamToString( |
55 | 58 | br.close(); |
56 | 59 | return sb.toString(); |
57 | 60 | } |
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 | | - }; |
68 | 61 |
|
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) { |
78 | 63 | if (!json.has("emoji")) { |
79 | 64 | return null; |
80 | 65 | } |
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")) |
174 | 69 | return null; |
175 | | - } |
176 | 70 |
|
177 | | - byte[] bytes = json.getString("emoji").getBytes(StandardCharsets.UTF_8); |
| 71 | + byte[] bytes = unicode.getBytes(StandardCharsets.UTF_8); |
| 72 | + |
178 | 73 | String description = null; |
179 | 74 | if (json.has("description")) { |
180 | 75 | description = json.getString("description"); |
181 | 76 | } |
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"); |
185 | 80 | } |
186 | 81 | List<String> aliases = jsonArrayToStringList(json.getJSONArray("aliases")); |
187 | 82 | 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); |
189 | 84 | } |
190 | 85 |
|
191 | 86 | private static List<String> jsonArrayToStringList(JSONArray array) { |
|
0 commit comments