2 * Create a table from Unicode to CHARSET.
7 using System
; /* String, Console */
8 using System
.Text
; /* Encoding */
10 public class table_to
{
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 public static int Main (String
[] args
) {
26 if (args
.Length
!= 1) {
27 Console
.Error
.WriteLine("Usage: mono table_to charset");
30 String charset
= args
[0];
33 encoding
= Encoding
.GetEncoding(charset
);
34 } catch (NotSupportedException e
) {
35 Console
.Error
.WriteLine("no converter for "+charset
);
38 byte[] qmark
= encoding
.GetBytes(new char[] { (char)0x003f }
);
39 for (int i
= 0; i
< 0x110000; i
++) {
42 ? new char[] { (char)i }
43 : new char[] { (char)(0xd800 + ((i
- 0x10000) >> 10)),
44 (char)(0xdc00 + ((i
- 0x10000) & 0x3ff)) });
45 byte[] outp
= encoding
.GetBytes(inp
);
46 if (!(((outp
.Length
>= qmark
.Length
47 && outp
[0] == qmark
[0]
48 && (qmark
.Length
< 2 || outp
[1] == qmark
[1])
49 && (qmark
.Length
< 3 || outp
[2] == qmark
[2])
50 && (qmark
.Length
< 4 || outp
[3] == qmark
[3]))
51 || (outp
.Length
>= 1 && outp
[0] == 0x3f))
53 Console
.Out
.Write("0x");
54 for (int j
= 0; j
< outp
.Length
; j
++)
55 Console
.Out
.Write(toHexString2(outp
[j
]));
56 Console
.Out
.WriteLine("\t0x" + (i
<0x10000 ? toHexString4(i
) : ((Int32
)i
).ToString("X")));
59 } catch (Exception e
) {
60 Console
.Error
.WriteLine(e
);
61 Console
.Error
.WriteLine(e
.StackTrace
);