-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmojiReference.java
150 lines (132 loc) · 5.99 KB
/
EmojiReference.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.vladsch.emoji;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
public class EmojiReference {
public static final String EMOJI_REFERENCE_TXT = "/EmojiReference.txt"; // resource path to text data file
public static final String githubUrl = "https://github.githubassets.com/images/icons/emoji/";
private static final String[] EMPTY_ARRAY = new String[0];
/**
* Browser types and their subdirectory names
*/
public enum EmojiBrowserType {
APPL("appl"),
DCM("dcm"),
EMOJI_CHEAT_SHEET("cheat"),
COMBINED_EMOJI("emojis"),
FB("fb"),
GITHUB("github"),
GMAIL("gmail"),
GOOG("goog"),
JOY("joy"),
KDDI("kddi"),
SAMS("sams"),
SB("sb"),
TWTR("twtr"),
WIND("wind"),
;
public final String subdirectory;
EmojiBrowserType(String subdirectory) {
this.subdirectory = subdirectory;
}
}
public static class Emoji {
public final String shortcut;
public String[] aliasShortcuts;
public final String category;
public String subcategory;
public final String emojiCheatSheetFile; // name part of the file no extension
public final String githubFile; // name part of the file no extension
public final String unicodeChars; // unicode char codes space separated list
public final String unicodeSampleFile; // name part of the file no extension
public final String unicodeCldr;
public String[] browserTypes;
public Emoji(String shortcut
, String[] aliasShortcuts
, String category
, String subcategory
, String emojiCheatSheetFile
, String githubFile
, String unicodeChars
, String unicodeSampleFile
, String unicodeCldr
, String[] browserTypes
) {
this.shortcut = shortcut;
this.aliasShortcuts = aliasShortcuts;
this.category = category;
this.subcategory = subcategory;
this.emojiCheatSheetFile = emojiCheatSheetFile;
this.githubFile = githubFile;
this.unicodeChars = unicodeChars;
this.unicodeSampleFile = unicodeSampleFile;
this.unicodeCldr = unicodeCldr;
this.browserTypes = browserTypes;
}
}
private static ArrayList<Emoji> emojiList = null;
public static List<Emoji> getEmojiList() {
if (emojiList == null) {
// read it in
emojiList = new ArrayList<>(3000);
final String emojiReference = EMOJI_REFERENCE_TXT;
InputStream stream = EmojiReference.class.getResourceAsStream(emojiReference);
if (stream == null) {
throw new IllegalStateException("Could not load " + emojiReference + " classpath resource");
}
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
String line;
try {
// skip first line, it is column names
line = reader.readLine();
while ((line = reader.readLine()) != null) {
String[] fields = line.split("\t");
try {
String shortcut = fields[0].charAt(0) == ' ' ? null : fields[0];
String category = fields[1].charAt(0) == ' ' ? null : fields[1];
String emojiCheatSheetFile = fields[2].charAt(0) == ' ' ? null : fields[2];
String githubFile = fields[3].charAt(0) == ' ' ? null : fields[3];
String unicodeChars = fields[4].charAt(0) == ' ' ? null : fields[4];
String unicodeSampleFile = fields[5].charAt(0) == ' ' ? null : fields[5];
String unicodeCldr = fields[6].charAt(0) == ' ' ? null : fields[6];
String subcategory = fields[7].charAt(0) == ' ' ? null : fields[7];
String[] aliasShortcuts = fields[8].charAt(0) == ' ' ? EMPTY_ARRAY : fields[8].split(",");
String[] browserTypes = fields[9].charAt(0) == ' ' ? EMPTY_ARRAY : fields[9].split(",");
final Emoji emoji = new Emoji(
shortcut
, aliasShortcuts
, category
, subcategory
, emojiCheatSheetFile
, githubFile
, unicodeChars
, unicodeSampleFile
, unicodeCldr
, browserTypes
);
emojiList.add(emoji);
//if (emoji.shortcut != null && emoji.unicodeChars == null) {
// String type = emoji.githubFile == null ? "cheatSheet " : (emoji.emojiCheatSheetFile == null ? "gitHub " : "");
// System.out.printf("Non unicode %sshortcut %s\n",type, emoji.shortcut);
//}
} catch (ArrayIndexOutOfBoundsException e) {
//e.printStackTrace();
throw new IllegalStateException("Error processing EmojiReference.txt", e);
}
}
} catch (IOException e) {
//e.printStackTrace();
throw new IllegalStateException("Error processing EmojiReference.txt", e);
}
}
return emojiList;
}
public static void main(String[] args) {
List<Emoji> emojiList = getEmojiList();
System.out.printf("Loaded %d emoji entries successfully.\n", emojiList.size());
}
}