3 // create-combining-class-source.cs
6 // Atsushi Enomoto <atsushi@ximian.com>
8 // Copyright 2005 Novell, Inc
10 // It creates combining class information table.
14 using System.Globalization;
17 using Util = Mono.Globalization.Unicode.NormalizationTableUtil;
19 namespace Mono.Globalization.Unicode
21 internal class CombiningClassCodeGenerator
23 private int lineCount = 0;
25 TextWriter CSCodeOut = TextWriter.Null;//Console.Out;
26 TextWriter CSTableOut = Console.Out;//TextWriter.Null;
28 public static void Main ()
30 new CombiningClassCodeGenerator ().Run ();
37 } catch (Exception ex) {
38 throw new InvalidOperationException ("Internal error at line " + lineCount + " : " + ex);
42 private void Process ()
44 CSCodeOut.WriteLine ("public static byte GetCombiningClass (int c)");
45 CSCodeOut.WriteLine ("{");
46 CSCodeOut.WriteLine (" switch (c) {");
48 TextReader reader = Console.In;
49 while (reader.Peek () != -1) {
50 string line = reader.ReadLine ();
52 int idx = line.IndexOf ('#');
54 line = line.Substring (0, idx).Trim ();
58 while (Char.IsDigit (line [n]) || Char.IsLetter (line [n]))
60 int cp = int.Parse (line.Substring (0, n), NumberStyles.HexNumber);
63 if (line [n] == '.' && line [n + 1] == '.')
64 cpEnd = int.Parse (line.Substring (n + 2, n), NumberStyles.HexNumber);
65 int nameStart = line.IndexOf (';') + 1;
66 int valueStart = line.IndexOf (';', nameStart) + 1;
67 string val = valueStart == 0 ? line.Substring (nameStart) :
68 line.Substring (nameStart, valueStart - nameStart - 1);
69 SetProp (cp, cpEnd, short.Parse (val));
72 CSCodeOut.WriteLine (" return {0};", prevVal);
73 CSCodeOut.WriteLine (" default:");
74 CSCodeOut.WriteLine (" return 0;");
75 CSCodeOut.WriteLine (" }");
76 CSCodeOut.WriteLine ("}");
80 byte [] ret = CodePointIndexer.CompressArray (
81 values, typeof (byte), Util.Combining) as byte [];
83 CSTableOut.WriteLine ("public static byte [] combiningClass = new byte [] {");
84 for (int i = 0; i < ret.Length; i++) {
87 CSTableOut.Write ("{0},", value);
89 CSTableOut.Write ("0x{0:X02},", value);
91 CSTableOut.WriteLine (" // {0:X04}", Util.Combining.ToCodePoint (i - 15));
93 CSTableOut.WriteLine ("};");
96 private short prevVal;
98 byte [] values = new byte [0x20000];
100 private void SetProp (int cp, int cpEnd, short val)
105 if (prevVal != val && prevVal != 0)
106 CSCodeOut.WriteLine ("\t\treturn {0};", prevVal);
110 CSCodeOut.WriteLine ("\tcase 0x{0:X}:", cp);
111 values [cp] = (byte) val;
114 for (int i = cp; i <= cpEnd; i++) {
115 CSCodeOut.WriteLine ("\tcase 0x{0:X}:", i);
116 values [i] = (byte) val;