Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Driver.cs « locale-builder « tools - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 384b25ff7e49c2e06811c8460ce872abab15048e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
//
// Mono.Tools.LocalBuilder.Driver
//
// Author(s):
//  Jackson Harper (jackson@ximian.com)
//
// (C) 2004 Novell, Inc (http://www.novell.com)
//


using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Collections;
using System.Globalization;
using System.Text.RegularExpressions;

namespace Mono.Tools.LocaleBuilder {

	public class Driver {

		public static void Main (string [] args)
		{
			Driver d = new Driver ();
			ParseArgs (args, d);
			d.Run ();
		}

		private static void ParseArgs (string [] args, Driver d)
		{
			for (int i = 0; i < args.Length; i++) {
				if (args [i] == "--lang" && i+1 < args.Length)
					d.Lang = args [++i];
				else if (args [i] == "--locales" && i+1 < args.Length)
					d.Locales = args [++i];
                                else if (args [i] == "--header" && i + 1 < args.Length)
                                        d.HeaderFileName = args [++i];
			}
		}

		private string lang;
		private string locales;
                private string header_name;
                private ArrayList cultures;
                private Hashtable langs;
                private Hashtable currency_types;
                
		// The lang is the language that display names will be displayed in
		public string Lang {
			get {
				if (lang == null)
					lang = "en";
				return lang;
			}
			set { lang = value; }
		}

		public string Locales {
			get { return locales; }
			set { locales = value; }
		}

                public string HeaderFileName {
                        get {
                                if (header_name == null)
                                        return "culture-info-tables.h";
                                return header_name;
                        }
                        set { header_name = value; }
                }

		public void Run ()
		{
			Regex locales_regex = null;
			if (Locales != null)
				locales_regex = new Regex (Locales);

                        langs = new Hashtable ();
                        cultures = new ArrayList ();

                        LookupCurrencyTypes ();

			foreach (string file in Directory.GetFiles ("locales", "*.xml")) {
				string fn = Path.GetFileNameWithoutExtension (file);
				if (locales_regex == null || locales_regex.IsMatch (fn)) {
					ParseLocale (fn);
                                }
			}

                        /**
                         * Dump each table individually. Using StringBuilders
                         * because it is easier to debug, should switch to just
                         * writing to streams eventually.
                         */
                        using (StreamWriter writer = new StreamWriter (HeaderFileName, false, new UTF8Encoding (false, true))) {

                                writer.WriteLine ();
                                writer.WriteLine ("/* This is a generated file. Do not edit. See tools/locale-builder. */");
                                writer.WriteLine ("#ifndef MONO_METADATA_CULTURE_INFO_TABLES");
                                writer.WriteLine ("#define MONO_METADATA_CULTURE_INFO_TABLES 1");
                                writer.WriteLine ("\n");

                                writer.WriteLine ("#define NUM_CULTURE_ENTRIES " + cultures.Count);
                                writer.WriteLine ("\n");

                                // Sort the cultures by lcid
                                cultures.Sort (new LcidComparer ());

                                StringBuilder builder = new StringBuilder ();
                                int row = 0;
                                int count = cultures.Count;
                                for (int i = 0; i < count; i++) {
                                        CultureInfoEntry ci = (CultureInfoEntry) cultures [i];
                                        if (ci.DateTimeFormatEntry == null)
                                                continue;
                                        ci.DateTimeFormatEntry.AppendTableRow (builder);
                                        ci.DateTimeFormatEntry.Row = row++;
                                        if (i + 1 < count)
                                                builder.Append (',');
                                        builder.Append ('\n');
                                }

                                writer.WriteLine ("static const DateTimeFormatEntry datetime_format_entries [] = {");
                                writer.Write (builder);
                                writer.WriteLine ("};\n\n");
                                
                                builder = new StringBuilder ();
                                row = 0;
                                for (int i=0; i < count; i++) {
                                        CultureInfoEntry ci = (CultureInfoEntry) cultures [i];
                                        if (ci.NumberFormatEntry == null)
                                                continue;
                                        ci.NumberFormatEntry.AppendTableRow (builder);
                                        ci.NumberFormatEntry.Row = row++;
                                        if (i + 1 < count)
                                                builder.Append (',');
                                        builder.Append ('\n');
                                }

                                writer.WriteLine ("static const NumberFormatEntry number_format_entries [] = {");
                                writer.Write (builder);
                                writer.WriteLine ("};\n\n");
                                
                                builder = new StringBuilder ();
                                row = 0;
                                for (int i = 0; i < count; i++) {
                                        CultureInfoEntry ci = (CultureInfoEntry) cultures [i];
                                        ci.AppendTableRow (builder);
                                        ci.Row = row++;
                                        if (i + 1 < count)
                                                builder.Append (',');
                                        builder.Append ('\n');
                                }
                                
                                writer.WriteLine ("static const CultureInfoEntry culture_entries [] = {");
                                writer.Write (builder);
                                writer.WriteLine ("};\n\n");

                                cultures.Sort (new NameComparer ()); // Sort based on name
                                builder = new StringBuilder ();
                                for (int i = 0; i < count; i++) {
                                        CultureInfoEntry ci = (CultureInfoEntry) cultures [i];
                                        builder.Append ("\t{" + Entry.EncodeStringIdx (ci.Name.ToLower ()) + ", ");
                                        builder.Append (ci.Row + "}");
                                        if (i + 1 < count)
                                                builder.Append (',');
                                        builder.Append ('\n');
                                }

                                writer.WriteLine ("static const CultureInfoNameEntry culture_name_entries [] = {");
                                writer.Write (builder);
                                writer.WriteLine ("};\n\n");

                                writer.WriteLine ("static const char locale_strings [] = {");
                                writer.Write (Entry.GetStrings ());
                                writer.WriteLine ("};\n\n");

                                writer.WriteLine ("#endif\n");
                        }
		}

		private XPathDocument GetXPathDocument (string path)
		{
			XmlTextReader xtr = new XmlTextReader (path);
			xtr.XmlResolver = null;
			return new XPathDocument (xtr);
		}

                private bool ParseLang (string lang)
		{
                        XPathDocument doc = GetXPathDocument (Path.Combine ("langs", lang + ".xml"));
			XPathNavigator nav = doc.CreateNavigator ();
                        CultureInfoEntry ci = new CultureInfoEntry ();
                        string lang_type, terr_type;

//                        ci.Name = lang; // TODO: might need to be mapped.

                        lang_type = nav.Evaluate ("string (ldml/identity/language/@type)").ToString ();
			terr_type = nav.Evaluate ("string (ldml/identity/territory/@type)").ToString ();

                        ci.Language = (lang_type == String.Empty ? null : lang_type);
                        ci.Territory = (terr_type == String.Empty ? null : terr_type);

			if (!LookupLcids (ci))
                                return false;

                        doc = GetXPathDocument (Path.Combine ("langs", Lang + ".xml"));
			nav = doc.CreateNavigator ();
			ci.DisplayName = LookupFullName (ci, nav);
                        
			if (Lang == "en") {
				ci.EnglishName = ci.DisplayName;
			} else {
				doc = GetXPathDocument (Path.Combine ("langs", Lang + ".xml"));
				nav = doc.CreateNavigator ();
				ci.EnglishName = LookupFullName (ci, nav);
			}

			if (ci.Language == Lang) {
				ci.NativeName = ci.DisplayName;
			} else {
				doc = GetXPathDocument (Path.Combine ("langs", lang + ".xml"));
				nav = doc.CreateNavigator ();
				ci.NativeName = LookupFullName (ci, nav);
			}

                        // Null these out because langs dont have them
                        ci.DateTimeFormatEntry = null;
                        ci.NumberFormatEntry = null;

                        langs [lang] = ci;
                        cultures.Add (ci);

                        return true;
                }

                private void ParseLocale (string locale)
                {
                        CultureInfoEntry ci;

                        ci = LookupCulture (locale);

                        if (ci == null)
                                return;

                        if (langs [ci.Language] == null) {
                                if (!ParseLang (ci.Language)) // If we can't parse the lang we cant have the locale
                                        return;
                        }

                        cultures.Add (ci);
                }

		private CultureInfoEntry LookupCulture (string locale)
		{
                        XPathDocument doc = GetXPathDocument (Path.Combine ("locales", locale + ".xml"));
                        XPathNavigator nav = doc.CreateNavigator ();
			CultureInfoEntry ci = new CultureInfoEntry ();
			string supp;

//                        ci.Name = locale; // TODO: Some of these need to be mapped.

			// First thing we do is get the lang-territory combo, lcid, and full names
			ci.Language = nav.Evaluate ("string (ldml/identity/language/@type)").ToString ();
			ci.Territory = nav.Evaluate ("string (ldml/identity/territory/@type)").ToString ();

                        if (!LookupLcids (ci))
                                return null;
			LookupNames (ci);

			/**
			 * Locale generation is done in six steps, first we
                         * read the root file which is the base invariant data
                         * then the supplemental root data, 
			 * then the language file, the supplemental languages
			 * file then the locale file, then the supplemental
			 * locale file. Values in each descending file can
			 * overwrite previous values.
			 */
                        doc = GetXPathDocument (Path.Combine ("langs", "root.xml"));
                        nav = doc.CreateNavigator ();
                        Lookup (nav, ci);

                        doc = GetXPathDocument (Path.Combine ("supp", "root.xml"));
                        nav = doc.CreateNavigator ();
                        Lookup (nav, ci);

			doc = GetXPathDocument (Path.Combine ("langs", ci.Language + ".xml"));
			nav = doc.CreateNavigator ();
			Lookup (nav, ci);

			supp = Path.Combine ("supp", ci.Language + ".xml");
			if (File.Exists (supp)) {
				doc = GetXPathDocument (supp);
				nav = doc.CreateNavigator ();
				Lookup (nav, ci);
			}
			
			doc = GetXPathDocument (Path.Combine ("locales", locale + ".xml"));
			nav = doc.CreateNavigator ();
			Lookup (nav, ci);

			supp = Path.Combine ("supp", locale + ".xml");
			if (File.Exists (supp)) {
				doc = GetXPathDocument (supp);
				nav = doc.CreateNavigator ();
				Lookup (nav, ci);
			}

                        return ci;
		}

		private void Lookup (XPathNavigator nav, CultureInfoEntry ci)
		{
			LookupDateTimeInfo (nav, ci);
			LookupNumberInfo (nav, ci);
		}

		private void LookupNames (CultureInfoEntry ci)
		{
			XPathDocument doc = GetXPathDocument (Path.Combine ("langs", Lang + ".xml"));
			XPathNavigator nav = doc.CreateNavigator ();

			ci.DisplayName = LookupFullName (ci, nav);
			
			if (Lang == "en") {
				ci.EnglishName = ci.DisplayName;
			} else {
				doc = GetXPathDocument (Path.Combine ("langs", "en.xml"));
				nav = doc.CreateNavigator ();
				ci.EnglishName = LookupFullName (ci, nav);
			}

			if (ci.Language == Lang) {
				ci.NativeName = ci.DisplayName;
			} else {
				doc = GetXPathDocument (Path.Combine ("langs", ci.Language + ".xml"));
				nav = doc.CreateNavigator ();
				ci.NativeName = LookupFullName (ci, nav);
			}
		}

		private void LookupDateTimeInfo (XPathNavigator nav, CultureInfoEntry ci)
		{
			/**
			 * TODO: Does anyone have multiple calendars?
			 */
			XPathNodeIterator ni =(XPathNodeIterator) nav.Evaluate ("ldml/dates/calendars/calendar");

			while (ni.MoveNext ()) {
				DateTimeFormatEntry df = ci.DateTimeFormatEntry;
				string cal_type = ni.Current.GetAttribute ("type", String.Empty);

				if (cal_type != String.Empty)
					df.CalendarType = cal_type;

				XPathNodeIterator ni2 = (XPathNodeIterator) ni.Current.Evaluate ("optionalCalendars/calendar");
                                int opt_cal_count = 0;
				while (ni2.MoveNext ()) {
                                        int type;
                                        string greg_type_str;
                                        XPathNavigator df_nav = ni2.Current;
                                        switch (df_nav.GetAttribute ("type", String.Empty)) {
                                        case "Gregorian":
                                                type = 0;
                                                break;
                                        case "Hijri":
                                                type = 0x01;
                                                break;
                                        case "ThaiBuddhist":
                                                type = 0x02;
                                                break;
                                        default:
                                                Console.WriteLine ("unknown calendar type:  " +
                                                                df_nav.GetAttribute ("type", String.Empty));
                                                continue;
                                        }
                                        type <<= 24;
                                        greg_type_str = df_nav.GetAttribute ("greg_type", String.Empty);
                                        if (greg_type_str != null && greg_type_str != String.Empty) {
                                                GregorianCalendarTypes greg_type = (GregorianCalendarTypes)
                                                        Enum.Parse (typeof (GregorianCalendarTypes), greg_type_str);
                                                int greg_type_int = (int) greg_type;
                                                type |= greg_type_int;
                                                
                                        }
                                        Console.WriteLine ("Setting cal type: {0:X}  for   {1}", type, ci.Name);
					ci.CalendarData [opt_cal_count++] = type;
				}
                                
				ni2 = (XPathNodeIterator) ni.Current.Evaluate ("monthNames/month");
				while (ni2.MoveNext ()) {
					if (ni2.CurrentPosition == 1)
						df.MonthNames.Clear ();
					df.MonthNames.Add (ni2.Current.Value);
				}

				ni2 = (XPathNodeIterator) ni.Current.Evaluate ("dayNames/day");
				while (ni2.MoveNext ()) {
					if (ni2.CurrentPosition == 1)
						df.DayNames.Clear ();
					df.DayNames.Add (ni2.Current.Value);
				}

				ni2 = (XPathNodeIterator) ni.Current.Evaluate ("dayAbbr/day");
				while (ni2.MoveNext ()) {
					if (ni2.CurrentPosition == 1)
						df.AbbreviatedDayNames.Clear ();
					df.AbbreviatedDayNames.Add (ni2.Current.Value);
				}

				ni2 = (XPathNodeIterator) ni.Current.Evaluate ("monthAbbr/month");
				while (ni2.MoveNext ()) {
					if (ni2.CurrentPosition == 1)
						df.AbbreviatedMonthNames.Clear ();
					df.AbbreviatedMonthNames.Add (ni2.Current.Value);
				}

				ni2 = (XPathNodeIterator) ni.Current.Evaluate ("dateFormats/dateFormatLength");
				while (ni2.MoveNext ()) {
					XPathNavigator df_nav = ni2.Current;
					XPathNodeIterator p = df_nav.Select ("dateFormat/pattern");
					string value = null;
					if (p.MoveNext ())
						value = p.Current.Value;
					XPathNodeIterator ext = null;
					switch (df_nav.GetAttribute ("type", String.Empty)) {
					case "full":
						if (value != null)
							ParseFullDateFormat (df, value);
						break;
					case "long":
						if (value != null)
							df.LongDatePattern = value;
						ext = df_nav.Select ("extraPatterns/pattern");
						if (ext.MoveNext ()) {
							df.LongDatePatterns.Clear ();
							do {
								df.LongDatePatterns.Add (ext.Current.Value);
							} while (ext.MoveNext ());
						}
						break;
					case "short":
						if (value != null)
							df.ShortDatePattern = value;
						ext = df_nav.Select ("extraPatterns/pattern");
						if (ext.MoveNext ()) {
							df.ShortDatePatterns.Clear ();
							do {
								df.ShortDatePatterns.Add (ext.Current.Value);
							} while (ext.MoveNext ());
						}
						break;
					case "year_month":
						if (value != null)
							df.YearMonthPattern = value;
						break;
					case "month_day":
						if (value != null)
							df.MonthDayPattern = value;
						break;
					}
				}

				ni2 = (XPathNodeIterator) ni.Current.Evaluate ("timeFormats/timeFormatLength");
				while (ni2.MoveNext ()) {
					XPathNavigator df_nav = ni2.Current;
					XPathNodeIterator p = df_nav.Select ("timeFormat/pattern");
					string value = null;
					if (p.MoveNext ())
						value = p.Current.Value;
					XPathNodeIterator ext = null;
					switch (df_nav.GetAttribute ("type", String.Empty)) {
					case "long":
						if (value != null)
							df.LongTimePattern = value.Replace ('a', 't');
						ext = df_nav.Select ("extraPatterns/pattern");
						if (ext.MoveNext ()) {
							df.LongTimePatterns.Clear ();
							do {
								df.LongTimePatterns.Add (ext.Current.Value);
							} while (ext.MoveNext ());
						}
						break;
					case "short":
						if (value != null)
							df.ShortTimePattern = value.Replace ('a', 't');
						ext = df_nav.Select ("extraPatterns/pattern");
						if (ext.MoveNext ()) {
							df.ShortTimePatterns.Clear ();
							do {
								df.ShortTimePatterns.Add (ext.Current.Value);
							} while (ext.MoveNext ());
						}
						break;
					}
				}

				ni2 = (XPathNodeIterator) ni.Current.Evaluate ("dateTimeFormats/dateTimeFormatLength/dateTimeFormat/pattern");
				if (ni2.MoveNext ())
					df.FullDateTimePattern = String.Format (ni2.Current.ToString (),
							df.LongTimePattern, df.LongDatePattern);

				XPathNodeIterator am = ni.Current.SelectChildren ("am", "");
				if (am.MoveNext ())
					df.AMDesignator = am.Current.Value;
				XPathNodeIterator pm = ni.Current.SelectChildren ("pm", "");
				if (pm.MoveNext ())
					df.PMDesignator = pm.Current.Value;
/*
                                string am = (string) ni.Current.Evaluate ("string(am)");
                                string pm = (string) ni.Current.Evaluate ("string(pm)");

                                if (am != String.Empty)
                                        df.AMDesignator = am;
                                if (pm != String.Empty)
                                        df.PMDesignator = pm;
*/
			}

                        string date_sep = (string) nav.Evaluate ("string(ldml/dates/symbols/dateSeparator)");
                        string time_sep = (string) nav.Evaluate ("string(ldml/dates/symbols/timeSeparator)");

                        if (date_sep != String.Empty)
                                ci.DateTimeFormatEntry.DateSeparator = date_sep;
                        if (time_sep != String.Empty)
                                ci.DateTimeFormatEntry.TimeSeparator = time_sep;
		}

		private void LookupNumberInfo (XPathNavigator nav, CultureInfoEntry ci)
		{
			XPathNodeIterator ni =(XPathNodeIterator) nav.Evaluate ("ldml/numbers");

			while (ni.MoveNext ()) {
                                LookupNumberSymbols (ni.Current, ci);
				LookupDecimalFormat (ni.Current, ci);
				LookupPercentFormat (ni.Current, ci);
				LookupCurrencyFormat (ni.Current, ci);
                                LookupCurrencySymbol (ni.Current, ci);
			}
		}

		private void LookupDecimalFormat (XPathNavigator nav, CultureInfoEntry ci)
		{
			string format = (string) nav.Evaluate ("string(decimalFormats/" +
					"decimalFormatLength/decimalFormat/pattern)");

			if (format == String.Empty)
				return;

			string [] part_one, part_two;
			string [] pos_neg = format.Split (new char [1] {';'}, 2);

			// Most of the patterns are common in positive and negative
			if (pos_neg.Length == 1)
				pos_neg = new string [] {pos_neg [0], pos_neg [0]};

			if (pos_neg.Length == 2) {
				
				part_one = pos_neg [0].Split (new char [1] {'.'}, 2);
				if (part_one.Length == 1)
					part_one = new string [] {part_one [0], String.Empty};

				if (part_one.Length == 2) {
					// assumed same for both positive and negative
					// decimal digit side
					ci.NumberFormatEntry.NumberDecimalDigits = 0;					
					for (int i = 0; i < part_one [1].Length; i++) {
						if (part_one [1][i] == '#') {
							ci.NumberFormatEntry.NumberDecimalDigits ++;
						} else
							break;								}
					// FIXME: This should be actually done by modifying culture xml files, but too many files to be modified.
					if (ci.NumberFormatEntry.NumberDecimalDigits > 0)
						ci.NumberFormatEntry.NumberDecimalDigits --;

					// decimal grouping side
					part_two = part_one [0].Split (',');
					if (part_two.Length > 1) {
						int len = part_two.Length - 1;
						ci.NumberFormatEntry.NumberGroupSizes = new int [len];
						for (int i = 0; i < len; i++) {
							string pat = part_two [i + 1];
							ci.NumberFormatEntry.NumberGroupSizes [i] = pat.Length;
						}
					} else {
						ci.NumberFormatEntry.NumberGroupSizes = new int [1] { 3 };
					}

					if (pos_neg [1].StartsWith ("(") && pos_neg [1].EndsWith (")")) {
						ci.NumberFormatEntry.NumberNegativePattern = 0;
					} else if (pos_neg [1].StartsWith ("- ")) {
						ci.NumberFormatEntry.NumberNegativePattern = 2;
					} else if (pos_neg [1].StartsWith ("-")) {
						ci.NumberFormatEntry.NumberNegativePattern = 1;
					} else if (pos_neg [1].EndsWith (" -")) {
						ci.NumberFormatEntry.NumberNegativePattern = 4;
					} else if (pos_neg [1].EndsWith ("-")) {
						ci.NumberFormatEntry.NumberNegativePattern = 3;
					} else {
						ci.NumberFormatEntry.NumberNegativePattern = 1;
					}
				}
			}
		}

		private void LookupPercentFormat (XPathNavigator nav, CultureInfoEntry ci)
		{
			string format = (string) nav.Evaluate ("string(percentFormats/" +
					"percentFormatLength/percentFormat/pattern)");

			if (format == String.Empty)
				return;

			string [] part_one, part_two;

			// we don't have percentNegativePattern in CLDR so 
			// the percentNegativePattern are just guesses
			if (format.StartsWith ("%")) {
				ci.NumberFormatEntry.PercentPositivePattern = 2;
				ci.NumberFormatEntry.PercentNegativePattern = 2;
				format = format.Substring (1);
			} else if (format.EndsWith (" %")) {
				ci.NumberFormatEntry.PercentPositivePattern = 0;
				ci.NumberFormatEntry.PercentNegativePattern = 0;
				format = format.Substring (0, format.Length - 2);
			} else if (format.EndsWith ("%")) {
				ci.NumberFormatEntry.PercentPositivePattern = 1;
				ci.NumberFormatEntry.PercentNegativePattern = 1;
				format = format.Substring (0, format.Length - 1);
			} else {
				ci.NumberFormatEntry.PercentPositivePattern = 0;
				ci.NumberFormatEntry.PercentNegativePattern = 0;
			}

			part_one = format.Split (new char [1] {'.'}, 2);
			if (part_one.Length == 2) {
				// assumed same for both positive and negative
				// decimal digit side
				ci.NumberFormatEntry.PercentDecimalDigits = 0;
				for (int i = 0; i < part_one [1].Length; i++) {
					if (part_one [1][i] == '#')
						ci.NumberFormatEntry.PercentDecimalDigits++;
					else
						break;
				}
			}

			if (part_one.Length > 0) {
				// percent grouping side
				part_two = part_one [0].Split (',');
				if (part_two.Length > 1) {
					int len = part_two.Length - 1;
					ci.NumberFormatEntry.PercentGroupSizes = new int [len];
					for (int i = 0; i < len; i++) {
						string pat = part_two [i + 1];
						if (pat [pat.Length -1] == '0')
							ci.NumberFormatEntry.PercentDecimalDigits = pat.Length - 1;
						ci.NumberFormatEntry.PercentGroupSizes [i] = pat.Length;
					}
				} else {
					ci.NumberFormatEntry.PercentGroupSizes = new int [1] { 3 };
					ci.NumberFormatEntry.PercentDecimalDigits = 2;
				}
			}
		}

		private void LookupCurrencyFormat (XPathNavigator nav, CultureInfoEntry ci)
		{
			string format = (string) nav.Evaluate ("string(currencyFormats/" +
					"currencyFormatLength/currencyFormat/pattern)");

			if (format == String.Empty)
				return;

			string [] part_one, part_two;
			string [] pos_neg = format.Split (new char [1] {';'}, 2);
	
			// Most of the patterns are common in positive and negative
			if (pos_neg.Length == 1)
				pos_neg = new string [] {pos_neg [0], pos_neg [0]};

			if (pos_neg.Length == 2) {
				part_one = pos_neg [0].Split (new char [1] {'.'}, 2);
				if (part_one.Length == 1)
					part_one = new string [] {part_one [0], String.Empty};
				if (part_one.Length == 2) {
					// assumed same for both positive and negative
					// decimal digit side
					ci.NumberFormatEntry.CurrencyDecimalDigits = 0;
					for (int i = 0; i < part_one [1].Length; i++) {
						if (part_one [1][i] == '0')
							ci.NumberFormatEntry.CurrencyDecimalDigits++;
						else
							break;
					}

					// decimal grouping side
					part_two = part_one [0].Split (',');
					if (part_two.Length > 1) {
						int len = part_two.Length - 1;
						ci.NumberFormatEntry.CurrencyGroupSizes = new int [len];
						for (int i = 0; i < len; i++) {
							string pat = part_two [i + 1];
							ci.NumberFormatEntry.CurrencyGroupSizes [i] = pat.Length;
						}
					} else {
						ci.NumberFormatEntry.CurrencyGroupSizes = new int [1] { 3 };
					}

					if (pos_neg [1].StartsWith ("(\u00a4 ") && pos_neg [1].EndsWith (")")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 14;
					} else if (pos_neg [1].StartsWith ("(\u00a4") && pos_neg [1].EndsWith (")")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 0;
					} else if (pos_neg [1].StartsWith ("\u00a4 ") && pos_neg [1].EndsWith ("-")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 11;
					} else if (pos_neg [1].StartsWith ("\u00a4") && pos_neg [1].EndsWith ("-")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 3;
					} else if (pos_neg [1].StartsWith ("(") && pos_neg [1].EndsWith (" \u00a4")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 15;
					} else if (pos_neg [1].StartsWith ("(") && pos_neg [1].EndsWith ("\u00a4")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 4;
					} else if (pos_neg [1].StartsWith ("-") && pos_neg [1].EndsWith (" \u00a4")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 8;
					} else if (pos_neg [1].StartsWith ("-") && pos_neg [1].EndsWith ("\u00a4")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 5;
					} else if (pos_neg [1].StartsWith ("-\u00a4 ")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 9;
					} else if (pos_neg [1].StartsWith ("-\u00a4")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 1;
					} else if (pos_neg [1].StartsWith ("\u00a4 -")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 12;
					} else if (pos_neg [1].StartsWith ("\u00a4-")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 2;
					} else if (pos_neg [1].EndsWith (" \u00a4-")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 10;
					} else if (pos_neg [1].EndsWith ("\u00a4-")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 7;
					} else if (pos_neg [1].EndsWith ("- \u00a4")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 13;
					} else if (pos_neg [1].EndsWith ("-\u00a4")) {
						ci.NumberFormatEntry.CurrencyNegativePattern = 6;
					} else {
						ci.NumberFormatEntry.CurrencyNegativePattern = 0;
					}
					
					if (pos_neg [0].StartsWith ("\u00a4 ")) {
						ci.NumberFormatEntry.CurrencyPositivePattern = 2;
					} else if (pos_neg [0].StartsWith ("\u00a4")) {
						ci.NumberFormatEntry.CurrencyPositivePattern = 0;
					} else if (pos_neg [0].EndsWith (" \u00a4")) {
						ci.NumberFormatEntry.CurrencyPositivePattern = 3;
					} else if (pos_neg [0].EndsWith ("\u00a4")) {
						ci.NumberFormatEntry.CurrencyPositivePattern = 1; 
					} else {
						ci.NumberFormatEntry.CurrencyPositivePattern = 0;
					}
				}
			}
		}

                private void LookupNumberSymbols (XPathNavigator nav, CultureInfoEntry ci)
                {
                        string dec = (string) nav.Evaluate ("string(symbols/decimal)");
                        string group = (string) nav.Evaluate ("string(symbols/group)");
                        string percent = (string) nav.Evaluate ("string(symbols/percentSign)");
                        string positive = (string) nav.Evaluate ("string(symbols/plusSign)");
                        string negative = (string) nav.Evaluate ("string(symbols/minusSign)");
                        string per_mille = (string) nav.Evaluate ("string(symbols/perMille)");
                        string infinity = (string) nav.Evaluate ("string(symbols/infinity)");
                        string nan = (string) nav.Evaluate ("string(symbols/nan)");

                        if (dec != String.Empty) {
                                ci.NumberFormatEntry.NumberDecimalSeparator = dec;
                                ci.NumberFormatEntry.PercentDecimalSeparator = dec;
                                ci.NumberFormatEntry.CurrencyDecimalSeparator = dec;
                        }

                        if (group != String.Empty) {
                                ci.NumberFormatEntry.NumberGroupSeparator = group;
                                ci.NumberFormatEntry.PercentGroupSeparator = group;
                                ci.NumberFormatEntry.CurrencyGroupSeparator = group;
                        }

                        if (percent != String.Empty)
                                ci.NumberFormatEntry.PercentSymbol = percent;
                        if (positive != String.Empty)
                                ci.NumberFormatEntry.PositiveSign = positive;
                        if (negative != String.Empty)
                                ci.NumberFormatEntry.NegativeSign = negative;
                        if (per_mille != String.Empty)
                                ci.NumberFormatEntry.PerMilleSymbol = per_mille;
                        if (infinity != String.Empty)
                                ci.NumberFormatEntry.PositiveInfinitySymbol = infinity;
                        if (nan != String.Empty)
                                ci.NumberFormatEntry.NaNSymbol = nan;
                }

                private void LookupCurrencySymbol (XPathNavigator nav, CultureInfoEntry ci)
                {
                        string type = currency_types [ci.Territory] as string;

                        if (type == null) {
                                Console.WriteLine ("no currency type for:  " + ci.Territory);
                                return;
                        }
                        
                        string cur = (string) nav.Evaluate ("string(currencies/currency [@type='" +
                                        type + "']/symbol)");

                        if (cur != String.Empty)
                                ci.NumberFormatEntry.CurrencySymbol = cur;
                }

		private bool LookupLcids (CultureInfoEntry ci)
		{
			XPathDocument doc = GetXPathDocument ("lcids.xml");
			XPathNavigator nav = doc.CreateNavigator ();
			string name = ci.Language;

                        if (ci.Territory != null)
                                name += "-" + ci.Territory;

			XPathNodeIterator ni =(XPathNodeIterator) nav.Evaluate ("lcids/lcid[@name='"
					+ name + "']");
			if (!ni.MoveNext ()) {
                                string file;
                                if (ci.Territory != null) {
                                        file = Path.Combine ("locales", ci.Language + "_" + ci.Territory + ".xml");
                                        File.Delete (file);
                                        Console.WriteLine ("deleting file:  " + file);
                                }
				Console.WriteLine ("no lcid found for:	" + name);
				return false;
			}

			string id = ni.Current.GetAttribute ("id", String.Empty);
			string parent = ni.Current.GetAttribute ("parent", String.Empty);
                        string specific = ni.Current.GetAttribute ("specific", String.Empty);
                        string iso2 = ni.Current.GetAttribute ("iso2", String.Empty);
                        string iso3 = ni.Current.GetAttribute ("iso3", String.Empty);
                        string win = ni.Current.GetAttribute ("win", String.Empty);
                        string icu = ni.Current.GetAttribute ("icu_name", String.Empty);

			// lcids are in 0x<hex> format
			ci.Lcid = id;
			ci.ParentLcid = parent;
                        ci.SpecificLcid = specific;
                        ci.ISO2Lang = iso2;
                        ci.ISO3Lang = iso3;
                        ci.Win3Lang = win;
                        ci.IcuName = icu;

                        return true;
		}
		
		private string LookupFullName (CultureInfoEntry ci, XPathNavigator nav)
		{
			string pre = "ldml/localeDisplayNames/";
			string ret;

			ret = (string) nav.Evaluate ("string("+
					pre + "languages/language[@type='" + ci.Language + "'])");

			if (ci.Territory == null)
				return ret;
			ret += " (" + (string) nav.Evaluate ("string("+
					pre + "territories/territory[@type='" + ci.Territory + "'])") + ")";

			return ret;
		}

                private void LookupCurrencyTypes ()
                {
                        XPathDocument doc = GetXPathDocument ("supplementalData.xml");
			XPathNavigator nav = doc.CreateNavigator ();

                        currency_types = new Hashtable ();

			XPathNodeIterator ni =(XPathNodeIterator) nav.Evaluate ("supplementalData/currencyData/region");
			while (ni.MoveNext ()) {
				string territory = (string) ni.Current.GetAttribute ("iso3166", String.Empty);
                                string currency = (string) ni.Current.Evaluate ("string(currency/@iso4217)");
                                currency_types [territory] = currency;
			}
                }

                static string control_chars = "ghmsftz";

                // HACK: We are trying to build year_month and month_day patterns from the full pattern.
                private void ParseFullDateFormat (DateTimeFormatEntry df, string full)
                {
                        
                        string month_day = String.Empty;
                        string year_month = String.Empty;
                        bool in_month_data = false;
                        bool in_year_data = false;
                        int month_end = 0;
                        int year_end = 0;
			bool inquote = false;
                        
                        for (int i = 0; i < full.Length; i++) {
                                char c = full [i];
				if (!inquote && c == 'M') {
                                        month_day += c;
                                        year_month += c;
                                        in_year_data = true;
                                        in_month_data = true;
                                        month_end = month_day.Length;
                                        year_end = year_month.Length;
                                } else if (!inquote && Char.ToLower (c) == 'd') {
                                        month_day += c;
                                        in_month_data = true;
                                        in_year_data = false;
                                        month_end = month_day.Length;
                                } else if (!inquote && Char.ToLower (c) == 'y') {
                                        year_month += c;
                                        in_year_data = true;
                                        in_month_data = false;
                                        year_end = year_month.Length;
                                } else if (!inquote && control_chars.IndexOf (Char.ToLower (c)) >= 0) {
                                        in_year_data = false;
                                        in_month_data = false;
                                } else if (in_year_data || in_month_data) {
                                        if (in_month_data)
                                                month_day += c;
                                        if (in_year_data)
                                                year_month += c;
                                }

				if (c == '\'') {
					inquote = !inquote;
                                }
                        }

                        if (month_day != String.Empty) {
                                month_day = month_day.Substring (0, month_end);
                                df.MonthDayPattern = month_day;
                        }
                        if (year_month != String.Empty) {
                                year_month = year_month.Substring (0, year_end);
                                df.YearMonthPattern = year_month;
                        }
                }

                private class LcidComparer : IComparer {

                        public int Compare (object a, object b)
                        {
                                CultureInfoEntry aa = (CultureInfoEntry) a;
                                CultureInfoEntry bb = (CultureInfoEntry) b;
                        
                                return aa.Lcid.CompareTo (bb.Lcid);
                        }                
                }

                private class NameComparer : IComparer {

                        public int Compare (object a, object b)
                        {
                                CultureInfoEntry aa = (CultureInfoEntry) a;
                                CultureInfoEntry bb = (CultureInfoEntry) b;

                                return aa.Name.ToLower ().CompareTo (bb.Name.ToLower ());
                        }
                }
        }
}