Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/generatecharacter/CharacterName.java
32287 views
1
package build.tools.generatecharacter;
2
3
import java.io.*;
4
import java.nio.*;
5
import java.util.*;
6
import java.util.zip.*;
7
8
public class CharacterName {
9
10
public static void main(String[] args) {
11
FileReader reader = null;
12
try {
13
if (args.length != 2) {
14
System.err.println("Usage: java CharacterName UnicodeData.txt uniName.dat");
15
System.exit(1);
16
}
17
18
reader = new FileReader(args[0]);
19
BufferedReader bfr = new BufferedReader(reader);
20
String line = null;
21
22
StringBuilder namePool = new StringBuilder();
23
byte[] cpPoolBytes = new byte[0x100000];
24
ByteBuffer cpBB = ByteBuffer.wrap(cpPoolBytes);
25
int lastCp = 0;
26
int cpNum = 0;
27
28
while ((line = bfr.readLine()) != null) {
29
if (line.startsWith("#"))
30
continue;
31
UnicodeSpec spec = UnicodeSpec.parse(line);
32
if (spec != null) {
33
int cp = spec.getCodePoint();
34
String name = spec.getName();
35
cpNum++;
36
if (name.equals("<control>") && spec.getOldName() != null) {
37
if (spec.getOldName().length() != 0)
38
name = spec.getOldName();
39
else
40
continue;
41
} else if (name.startsWith("<")) {
42
/*
43
3400 <CJK Ideograph Extension A, First>
44
4db5 <CJK Ideograph Extension A, Last>
45
4e00 <CJK Ideograph, First>
46
9fc3 <CJK Ideograph, Last>
47
ac00 <Hangul Syllable, First>
48
d7a3 <Hangul Syllable, Last>
49
d800 <Non Private Use High Surrogate, First>
50
db7f <Non Private Use High Surrogate, Last>
51
db80 <Private Use High Surrogate, First>
52
dbff <Private Use High Surrogate, Last>
53
dc00 <Low Surrogate, First>
54
dfff <Low Surrogate, Last>
55
e000 <Private Use, First>
56
f8ff <Private Use, Last>
57
20000 <CJK Ideograph Extension B, First>
58
2a6d6 <CJK Ideograph Extension B, Last>
59
f0000 <Plane 15 Private Use, First>
60
ffffd <Plane 15 Private Use, Last>
61
*/
62
continue;
63
}
64
65
if (cp == lastCp + 1) {
66
cpBB.put((byte)name.length());
67
} else {
68
cpBB.put((byte)0); // segment start flag
69
cpBB.putInt((name.length() << 24) | (cp & 0xffffff));
70
}
71
namePool.append(name);
72
lastCp = cp;
73
}
74
}
75
76
byte[] namePoolBytes = namePool.toString().getBytes("ASCII");
77
int cpLen = cpBB.position();
78
int total = cpLen + namePoolBytes.length;
79
80
DataOutputStream dos = new DataOutputStream(
81
new DeflaterOutputStream(
82
new FileOutputStream(args[1])));
83
dos.writeInt(total); // total
84
dos.writeInt(cpLen); // nameOff
85
dos.write(cpPoolBytes, 0, cpLen);
86
dos.write(namePoolBytes);
87
dos.close();
88
89
} catch (Throwable e) {
90
System.out.println("Unexpected exception:");
91
e.printStackTrace();
92
} finally {
93
if (reader != null) {
94
try {
95
reader.close();
96
} catch (Throwable ee) { ee.printStackTrace(); }
97
}
98
}
99
}
100
}
101
102