这本手册里的字符与汉字编码列表由下面的程式所生成。
1
/** *//**
2
* GB2312Unicde.java
3
* Copyright (c) 1997-2003 by Dr. Herong Yang
4
*/
5
import java.io.*;
6
import java.nio.*;
7
import java.nio.charset.*;
8
class GB2312Unicde
{
9
static OutputStream out = null;
10
static char hexDigit[] =
{'0', '1', '2', '3', '4', '5', '6', '7',
11
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
12
static int b_out[] =
{201,267,279,293,484,587,625,657,734,782,827,
13
874,901,980,5590};
14
static int e_out[] =
{216,268,280,294,494,594,632,694,748,794,836,
15
894,903,994,5594};
16
public static void main(String[] args)
{
17
try
{
18
out = new FileOutputStream("gb2312.gb");
19
writeCode();
20
out.close();
21
} catch (IOException e)
{
22
System.out.println(e.toString());
23
}
24
}
25
public static void writeCode() throws IOException
{
26
boolean reserved = false;
27
String name = null;
28
// GB2312 is not supported by JDK. So I am using GBK.
29
CharsetDecoder gbdc = Charset.forName("GBK").newDecoder();
30
CharsetEncoder uxec = Charset.forName("UTF-16BE").newEncoder();
31
CharsetEncoder u8ec = Charset.forName("UTF-8").newEncoder();
32
ByteBuffer gbbb = null;
33
ByteBuffer uxbb = null;
34
ByteBuffer u8bb = null;
35
CharBuffer cb = null;
36
int count = 0;
37
for (int i=1; i<=94; i++)
{
38
// Defining row settings
39
if (i>=1 && i<=9)
{
40
reserved = false;
41
name = "Graphic symbols";
42
} else if (i>=10 && i<=15)
{
43
reserved = true;
44
name = "Reserved";
45
} else if (i>=16 && i<=55)
{
46
reserved = false;
47
name = "Level 1 characters";
48
} else if (i>=56 && i<=87)
{
49
reserved = false;
50
name = "Level 2 characters";
51
} else if (i>=88 && i<=94)
{
52
reserved = true;
53
name = "Reserved";
54
}
55
// writing row title
56
writeln();
57
writeString("<p>");
58
writeNumber(i);
59
writeString(" Row: "+name);
60
writeln();
61
writeString("</p>");
62
writeln();
63
if (!reserved)
{
64
writeln();
65
writeHeader();
66
// looping through all characters in one row
67
for (int j=1; j<=94; j++)
{
68
byte hi = (byte)(0xA0 + i);
69
byte lo = (byte)(0xA0 + j);
70
if (validGB(i,j))
{
71
// getting GB, UTF-16BE, UTF-8 codes
72
gbbb = ByteBuffer.wrap(new byte[]
{hi,lo});
73
try
{
74
cb = gbdc.decode(gbbb);
75
uxbb = uxec.encode(cb);
76
cb.rewind();
77
u8bb = u8ec.encode(cb);
78
} catch (CharacterCodingException e)
{
79
cb = null;
80
uxbb = null;
81
u8bb = null;
82
}
83
} else
{
84
cb = null;
85
uxbb = null;
86
u8bb = null;
87
}
88
writeNumber(i);
89
writeNumber(j);
90
writeString(" ");
91
if (cb!=null)
{
92
writeByte(hi);
93
writeByte(lo);
94
writeString(" ");
95
writeHex(hi);
96
writeHex(lo);
97
count++;
98
} else
{
99
writeGBSpace();
100
writeString(" null");
101
}
102
writeString(" ");
103
writeByteBuffer(uxbb,2);
104
writeString(" ");
105
writeByteBuffer(u8bb,3);
106
if (j%2 == 0)
{
107
writeln();
108
} else
{
109
writeString(" ");
110
}
111
}
112
writeFooter();
113
}
114
}
115
System.out.println("Number of GB characters worte: "+count);
116
}
117
public static void writeln() throws IOException
{
118
out.write(0x0D);
119
out.write(0x0A);
120
}
121
public static void writeByte(byte b) throws IOException
{
122
out.write(b & 0xFF);
123
}
124
public static void writeByteBuffer(ByteBuffer b, int l)
125
throws IOException
{
126
int i = 0;
127
if (b==null)
{
128
writeString("null");
129
i = 2;
130
} else
{
131
for (i=0; i<b.limit(); i++) writeHex(b.get(i));
132
}
133
for (int j=i; j<l; j++) writeString(" ");
134
}
135
public static void writeGBSpace() throws IOException
{
136
out.write(0xA1);
137
out.write(0xA1);
138
}
139
public static void writeString(String s) throws IOException
{
140
if (s!=null)
{
141
for (int i=0; i<s.length(); i++)
{
142
out.write((int) (s.charAt(i) & 0xFF));
143
}
144
}
145
}
146
public static void writeNumber(int i) throws IOException
{
147
String s = "00" + String.valueOf(i);
148
writeString(s.substring(s.length()-2,s.length()));
149
}
150
public static void writeHex(byte b) throws IOException
{
151
out.write((int) hexDigit[(b >> 4) & 0x0F]);
152
out.write((int) hexDigit[b & 0x0F]);
153
}
154
public static void writeHeader() throws IOException
{
155
writeString("<pre>");
156
writeln();
157
writeString("Q.W. ");
158
writeGBSpace();
159
writeString(" GB Uni. UTF-8 ");
160
writeString(" ");
161
writeString("Q.W. ");
162
writeGBSpace();
163
writeString(" GB Uni. UTF-8 ");
164
writeln();
165
writeln();
166
}
167
public static void writeFooter() throws IOException
{
168
writeString("</pre>");
169
writeln();
170
}
171
public static boolean validGB(int i,int j)
{
172
for (int l=0; l<b_out.length; l++)
{
173
if (i*100+j>=b_out[l] && i*100+j<=e_out[l]) return false;
174
}
175
return true;
176
}
177
}


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



151

152

153

154



155

156

157

158

159

160

161

162

163

164

165

166

167



168

169

170

171



172



173

174

175

176

177
