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 namespace Mono.Globalization.Unicode
19 internal class CombiningClassCodeGenerator
21 private int lineCount = 0;
23 public static void Main ()
25 new CombiningClassCodeGenerator ().Run ();
32 } catch (Exception ex) {
33 throw new InvalidOperationException ("Internal error at line " + lineCount + " : " + ex);
37 private void Process ()
39 Console.WriteLine ("public static byte GetCombiningClass (int c)");
40 Console.WriteLine ("{");
41 Console.WriteLine (" switch (c) {");
43 TextReader reader = Console.In;
44 while (reader.Peek () != -1) {
45 string line = reader.ReadLine ();
47 int idx = line.IndexOf ('#');
49 line = line.Substring (0, idx).Trim ();
53 while (Char.IsDigit (line [n]) || Char.IsLetter (line [n]))
55 int cp = int.Parse (line.Substring (0, n), NumberStyles.HexNumber);
58 if (line [n] == '.' && line [n + 1] == '.')
59 cpEnd = int.Parse (line.Substring (n + 2, n), NumberStyles.HexNumber);
60 int nameStart = line.IndexOf (';') + 1;
61 int valueStart = line.IndexOf (';', nameStart) + 1;
62 string val = valueStart == 0 ? line.Substring (nameStart) :
63 line.Substring (nameStart, valueStart - nameStart - 1);
64 SetProp (cp, cpEnd, short.Parse (val));
67 Console.WriteLine (" return {0};", prevVal);
68 Console.WriteLine (" default:");
69 Console.WriteLine (" return 0;");
70 Console.WriteLine (" }");
71 Console.WriteLine ("}");
76 private short prevVal;
78 private void SetProp (int cp, int cpEnd, short val)
83 if (prevVal != val && prevVal != 0)
84 Console.WriteLine ("\t\treturn {0};", prevVal);
88 Console.WriteLine ("\tcase 0x{0:X}:", cp);
90 for (int i = cp; i <= cpEnd; i++)
91 Console.WriteLine ("\tcase 0x{0:X}:", i);