2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / tools / misc / DumpCultureInfo.cs
1 using System;
2 using System.Threading;
3 using System.Globalization;
4
5 namespace Mono.Tools {
6
7         public class DumpCultureInfo {
8
9                 internal static string ToUnicode (string input)
10                 {
11                         string output = "";
12                         for (int i = 0; i < input.Length; i++) {
13                                 int chr = input [i];
14                                 output += "\\x" + chr.ToString ("x4");
15                         }
16
17                         return output;
18                 }
19
20                 public static void DumpNumberFormatInfo (CultureInfo culture)
21                 {
22                         NumberFormatInfo nfi = culture.NumberFormat;
23
24                         string currency_group_sizes = "";
25                         {
26                                 int[] group_sizes = nfi.CurrencyGroupSizes;
27
28                                 currency_group_sizes = "new int[" + group_sizes.Length + "] { ";
29                                 for (int i = 0; i < group_sizes.Length; i++) {
30                                         if (i > 0) currency_group_sizes += ", ";
31                                         currency_group_sizes += group_sizes[i] + " ";
32                                 }
33                                 currency_group_sizes += "}";
34                         }
35
36                         string number_group_sizes = "";
37                         {
38                                 int[] group_sizes = nfi.NumberGroupSizes;
39
40                                 number_group_sizes = "new int[" + group_sizes.Length + "] { ";
41                                 for (int i = 0; i < group_sizes.Length; i++) {
42                                         if (i > 0) number_group_sizes += ", ";
43                                         number_group_sizes += group_sizes[i] + " ";
44                                 }
45                                 number_group_sizes += "}";
46                         }
47
48                         string percent_group_sizes = "";
49                         {
50                                 int[] group_sizes = nfi.PercentGroupSizes;
51
52                                 percent_group_sizes = "new int[" + group_sizes.Length + "] { ";
53                                 for (int i = 0; i < group_sizes.Length; i++) {
54                                         if (i > 0) percent_group_sizes += ", ";
55                                         percent_group_sizes += group_sizes[i] + " ";
56                                 }
57                                 percent_group_sizes += "}";
58                         }
59
60
61                         Object[] data = { "\t\t\t\t",
62                                           nfi.CurrencyDecimalDigits,
63                                           ToUnicode (nfi.CurrencyDecimalSeparator),
64                                           ToUnicode (nfi.CurrencyGroupSeparator),
65                                           currency_group_sizes,
66                                           nfi.CurrencyNegativePattern,
67                                           nfi.CurrencyPositivePattern,
68                                           ToUnicode (nfi.CurrencySymbol),
69                                           ToUnicode (nfi.NaNSymbol),
70                                           ToUnicode (nfi.NegativeInfinitySymbol),
71                                           ToUnicode (nfi.NegativeSign),
72                                           nfi.NumberDecimalDigits,
73                                           ToUnicode (nfi.NumberDecimalSeparator),
74                                           ToUnicode (nfi.NumberGroupSeparator),
75                                           number_group_sizes,
76                                           nfi.NumberNegativePattern,
77                                           nfi.PercentDecimalDigits,
78                                           ToUnicode (nfi.PercentDecimalSeparator),
79                                           ToUnicode (nfi.PercentGroupSeparator),
80                                           percent_group_sizes,
81                                           nfi.PercentNegativePattern,
82                                           nfi.PercentPositivePattern,
83                                           ToUnicode (nfi.PercentSymbol),
84                                           ToUnicode (nfi.PerMilleSymbol),
85                                           ToUnicode (nfi.PositiveInfinitySymbol),
86                                           ToUnicode (nfi.PositiveSign)
87                         };
88
89                         string format = "{0}currencyDecimalDigits\t\t= {1};\n"
90                                 + "{0}currencyDecimalSeparator\t= \"{2}\";\n"
91                                 + "{0}currencyGroupSeparator\t\t= \"{3}\";\n"
92                                 + "{0}currencyGroupSizes\t\t= {4};\n"
93                                 + "{0}currencyNegativePattern\t\t= {5};\n"
94                                 + "{0}currencyPositivePattern\t\t= {6};\n"
95                                 + "{0}currencySymbol\t\t\t= \"{7}\";\n\n"
96                                 + "{0}naNSymbol\t\t\t= \"{8}\";\n"
97                                 + "{0}negativeInfinitySymbol\t\t= \"{9}\";\n"
98                                 + "{0}negativeSign\t\t\t= \"{10}\";\n\n"
99                                 + "{0}numberDecimalDigits\t\t= {11};\n"
100                                 + "{0}numberDecimalSeparator\t\t= \"{12}\";\n"
101                                 + "{0}numberGroupSeparator\t\t= \"{13}\";\n"
102                                 + "{0}numberGroupSizes\t\t= {14};\n"
103                                 + "{0}numberNegativePattern\t\t= {15};\n"
104                                 + "{0}percentDecimalDigits\t\t= {16};\n"
105                                 + "{0}percentDecimalSeparator\t\t= \"{17}\";\n"
106                                 + "{0}percentGroupSeparator\t\t= \"{18}\";\n"
107                                 + "{0}percentGroupSizes\t\t= {19};\n"
108                                 + "{0}percentNegativePattern\t\t= {20};\n"
109                                 + "{0}percentPositivePattern\t\t= {21};\n"
110                                 + "{0}percentSymbol\t\t\t= \"{22}\";\n\n"
111                                 + "{0}perMilleSymbol\t\t\t= \"{23}\";\n"
112                                 + "{0}positiveInfinitySymbol\t\t= \"{24}\";\n"
113                                 + "{0}positiveSign\t\t\t= \"{25}\";\n";
114
115                         string output = String.Format (format, data);
116
117                         Object[] data2 = { "\t\t\t\t", "\t\t\t", culture.EnglishName,
118                                            culture.LCID.ToString ("x4"), output };
119
120                         string format2 = "{0}// {2}\n{1}case 0x{3}:\n{0}readOnly = false;\n\n"
121                                 + "{4}\n{0}break;\n\n";
122
123                         Console.WriteLine (String.Format (format2, data2));
124                 }
125
126                 public static int[] AllCultures = {
127                         0x007F, 0x0001, 0x0401, 0x0801, 0x0C01, 0x1001, 0x1401, 0x1801,
128                         0x1C01, 0x2001, 0x2401, 0x2801, 0x2C01, 0x3001, 0x3401, 0x3801,
129                         0x3C01, 0x4001, 0x0002, 0x0402, 0x0003, 0x0403, 0x0004, 0x0404,
130                         0x0804, 0x0C04, 0x1004, 0x1404, 0x7C04, 0x0005, 0x0405, 0x0006,
131                         0x0406, 0x0007, 0x0407, 0x0807, 0x0C07, 0x1007, 0x1407, 0x0008,
132                         0x0408, 0x0009, 0x0409, 0x0809, 0x0C09, 0x1009, 0x1409, 0x1809,
133                         0x1C09, 0x2009, 0x2409, 0x2809, 0x2C09, 0x3009, 0x3409, 0x000A,
134                         0x080A, 0x0C0A, 0x100A, 0x140A, 0x180A, 0x1C0A, 0x200A, 0x240A,
135                         0x280A, 0x2C0A, 0x300A, 0x340A, 0x380A, 0x3C0A, 0x400A, 0x440A,
136                         0x480A, 0x4C0A, 0x500A, 0x000B, 0x040B, 0x000C, 0x040C, 0x080C,
137                         0x0C0C, 0x100C, 0x140C, 0x180C, 0x000D, 0x040D, 0x000E, 0x040E,
138                         0x000F, 0x040F, 0x0010, 0x0410, 0x0810, 0x0011, 0x0411, 0x0012,
139                         0x0412, 0x0013, 0x0413, 0x0813, 0x0014, 0x0414, 0x0814, 0x0015,
140                         0x0415, 0x0016, 0x0416, 0x0816, 0x0018, 0x0418, 0x0019, 0x0419,
141                         0x001A, 0x041A, 0x081A, 0x0C1A, 0x001B, 0x041B, 0x001C, 0x041C,
142                         0x001D, 0x041D, 0x081D, 0x001E, 0x041E, 0x001F, 0x041F, 0x0020,
143                         0x0420, 0x0021, 0x0421, 0x0022, 0x0422, 0x0023, 0x0423, 0x0024,
144                         0x0424, 0x0025, 0x0425, 0x0026, 0x0426, 0x0027, 0x0427, 0x0029,
145                         0x0429, 0x002A, 0x042A, 0x002B, 0x042B, 0x002C, 0x042C, 0x082C,
146                         0x002D, 0x042D, 0x002F, 0x042F, 0x0036, 0x0436, 0x0037, 0x0437,
147                         0x0038, 0x0438, 0x0039, 0x0439, 0x003E, 0x043E, 0x083E, 0x003F,
148                         0x043F, 0x0040, 0x0440, 0x0041, 0x0441, 0x0043, 0x0443, 0x0843,
149                         0x0044, 0x0444, 0x0046, 0x0446, 0x0047, 0x0447, 0x0049, 0x0449,
150                         0x004A, 0x044A, 0x004B, 0x044B, 0x004E, 0x044E, 0x004F, 0x044F,
151                         0x0050, 0x0450, 0x0056, 0x0456, 0x0057, 0x0457, 0x005A, 0x045A,
152                         0x0065, 0x0465
153                 };
154
155                 public static int[] Cultures = {
156                         // Invariant culture
157                         0x007f,
158                         // English
159                         0x0409, 0x0809, 0x0c09, 0x1009,
160                         // German
161                         0x0407, 0x0807, 0x0c07, 0x1007, 0x1407
162                 };
163
164                 public static void Main ()
165                 {
166                         for (int i = 0; i < AllCultures.Length; i++) {
167                                 CultureInfo culture = new CultureInfo (AllCultures [i], false);
168
169                                 if (culture.IsNeutralCulture)
170                                         continue;
171
172                                 DumpNumberFormatInfo (culture);
173                         }
174                 }
175         }
176 }