New test.
[mono.git] / tools / locale-builder / CultureInfoEntry.cs
1 //
2 // Mono.Tools.LocaleBuilder.CultureInfoEntry
3 //
4 // Author(s):
5 //  Jackson Harper (jackson@ximian.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9
10
11 using System;
12 using System.Text;
13
14 namespace Mono.Tools.LocaleBuilder {
15
16         public class CultureInfoEntry : Entry {
17
18                 public static CultureInfoEntry ShallowCopy (CultureInfoEntry e)
19                 {
20                         return (CultureInfoEntry) e.MemberwiseClone ();
21                 }
22
23                 string language;
24
25                 public string Territory;
26                 public string EnglishName;
27                 public string DisplayName;
28                 public string NativeName;
29                 public string IcuName;
30                 public string Win3Lang;
31                 public string ISO2Lang;
32                 public string ISO3Lang;
33                 public string Lcid;
34                 public string ParentLcid;
35                 public string SpecificLcid;
36                 public int RegionId = -1;
37                 public DateTimeFormatEntry DateTimeFormatEntry;
38                 public NumberFormatEntry NumberFormatEntry;
39                 public TextInfoEntry TextInfoEntry;
40                 public int [] CalendarData = new int [5];
41                 public int DateTimeIndex;
42                 public int NumberIndex;
43                 
44                 
45                 public int Row;
46
47                 public CultureInfoEntry ()
48                 {
49                         DateTimeFormatEntry = new DateTimeFormatEntry ();
50                         NumberFormatEntry = new NumberFormatEntry ();
51                 }
52
53                 public string Language {
54                         get {
55                                 return language;
56                         }
57                         set {
58                                 language = (value == "zh") ? "zh-CHS" : value;
59                         }
60                 }
61
62                 public string Name {
63                         get {
64                                 if (Territory == null)
65                                         return Language;
66                                 return (Language.StartsWith ("zh") ? "zh" : Language) + "-" + Territory;
67                         }
68                 }
69
70                 public override string ToString ()
71                 {
72                         StringBuilder builder = new StringBuilder ();
73                         AppendTableRow (builder);
74                         return builder.ToString ();
75                 }
76
77                 public void AppendTableRow (StringBuilder builder)
78                 {
79                         builder.Append ("\t{");
80                         builder.AppendFormat ("{0}, {1}, {2}, {3}," +
81                                         "{4}, {5}, {6}, " +
82                                         "{7}, {8}, {9}, " +
83                                         "{10}, {11}, " +
84                                         "{12}, " +
85                                         "{13}, {14}, {15}",
86                                         Lcid, ParentLcid, SpecificLcid, RegionId,
87                                         EncodeStringIdx (Name), EncodeStringIdx (IcuName), EncodeStringIdx (EnglishName),
88                                         EncodeStringIdx (DisplayName), EncodeStringIdx (NativeName), EncodeStringIdx (Win3Lang),
89                                         EncodeStringIdx (ISO3Lang), EncodeStringIdx (ISO2Lang),
90                                         ValuesString (CalendarData),
91                                         DateTimeFormatEntry == null ? -1 : DateTimeFormatEntry.Row,
92                                         NumberFormatEntry == null ? -1 : NumberFormatEntry.Row,
93                                         TextInfoEntry.ToString ());
94                         builder.Append ('}');
95                 }
96
97                 private string ValuesString (int [] values)
98                 {
99                         StringBuilder builder = new StringBuilder ();
100                         builder.Append ('{');
101                         for (int i=0; i<values.Length; i++) {
102                                 builder.Append (values [i].ToString ());
103                                 if (i+1 < values.Length)
104                                         builder.Append (", ");
105                         }
106                         builder.Append ("}");
107                         return builder.ToString ();
108                 }
109         }
110         
111 }
112