2 * Create a table from CHARSET to Unicode.
7 using System
; /* String, Console */
8 using System
.Text
; /* Encoding */
10 public class table_from
{
11 static String
toHexString1 (int i
) {
12 return new String(new char[] { "0123456789ABCDEF" [i] }
);
14 static String
toHexString2 (int i
) {
15 return toHexString1((i
>>4)&0x0f)
16 +toHexString1(i
&0x0f);
18 static String
toHexString4 (int i
) {
19 return toHexString1((i
>>12)&0x0f)
20 +toHexString1((i
>>8)&0x0f)
21 +toHexString1((i
>>4)&0x0f)
22 +toHexString1(i
&0x0f);
24 static void printOutput(char[] outp
) {
25 Console
.Out
.Write("0x");
26 for (int j
= 0; j
< outp
.Length
; j
++) {
28 Console
.Out
.Write(" 0x");
30 && outp
[j
] >= 0xd800 && outp
[j
] < 0xdc00
31 && outp
[j
+1] >= 0xdc00 && outp
[j
+1] < 0xe000) {
32 int c
= 0x10000 + ((outp
[j
] - 0xd800) << 10) + (outp
[j
+1] - 0xdc00);
33 Console
.Out
.Write(((Int32
)c
).ToString("X"));
36 Console
.Out
.Write(toHexString4(outp
[j
]));
39 public static int Main (String
[] args
) {
41 if (args
.Length
!= 1) {
42 Console
.Error
.WriteLine("Usage: mono table_from charset");
45 String charset
= args
[0];
48 encoding
= Encoding
.GetEncoding(charset
);
49 } catch (NotSupportedException e
) {
50 Console
.Error
.WriteLine("no converter for "+charset
);
53 byte[] qmark
= encoding
.GetBytes(new char[] { (char)0x003f }
);
54 for (int i0
= 0; i0
< 0x100; i0
++) {
55 char[] outp
= encoding
.GetChars(new byte[] { (byte)i0 }
);
57 && !(outp
.Length
>= 1 && outp
[0] == 0x003f
58 && !(qmark
.Length
== 1 && i0
== qmark
[0]))) {
59 Console
.Out
.Write("0x"+toHexString2(i0
)+"\t");
61 Console
.Out
.WriteLine();
62 } else if (outp
.Length
<= 1) {
63 for (int i1
= 0; i1
< 0x100; i1
++) {
64 outp
= encoding
.GetChars(new byte[] { (byte)i0, (byte)i1 }
);
66 && !(outp
.Length
>= 1 && outp
[0] == 0x003f
67 && !(qmark
.Length
== 2 && i0
== qmark
[0] && i1
== qmark
[1]))) {
68 Console
.Out
.Write("0x"+toHexString2(i0
)+toHexString2(i1
)+"\t");
70 Console
.Out
.WriteLine();
71 } else if (outp
.Length
<= 1) {
72 for (int i2
= 0; i2
< 0x100; i2
++) {
73 outp
= encoding
.GetChars(new byte[] { (byte)i0, (byte)i1, (byte)i2 }
);
75 && !(outp
.Length
>= 1 && outp
[0] == 0x003f
76 && !(qmark
.Length
== 3
77 && i0
== qmark
[0] && i1
== qmark
[1] && i2
== qmark
[2]))) {
78 Console
.Out
.Write("0x"+toHexString2(i0
)+toHexString2(i1
)+toHexString2(i2
)+"\t");
80 Console
.Out
.WriteLine();
81 } else if (outp
.Length
<= 1) {
82 for (int i3
= 0; i3
< 0x100; i3
++) {
83 outp
= encoding
.GetChars(new byte[] { (byte)i0, (byte)i1, (byte)i2, (byte)i3 }
);
85 && !(outp
.Length
>= 1 && outp
[0] == 0x003f
86 && !(qmark
.Length
== 4
87 && i0
== qmark
[0] && i1
== qmark
[1] && i2
== qmark
[2] && i3
== qmark
[3]))) {
88 Console
.Out
.Write("0x"+toHexString2(i0
)+toHexString2(i1
)+toHexString2(i2
)+toHexString2(i3
)+"\t");
90 Console
.Out
.WriteLine();
99 } catch (Exception e
) {
100 Console
.Error
.WriteLine(e
);
101 Console
.Error
.WriteLine(e
.StackTrace
);