imported everything from my branch (which is slightly harmless).
[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 DateTimeFormatEntry DateTimeFormatEntry;
37                 public NumberFormatEntry NumberFormatEntry;
38                 public TextInfoEntry TextInfoEntry;
39                 public int [] CalendarData = new int [5];
40                 public int DateTimeIndex;
41                 public int NumberIndex;
42                 
43                 
44                 public int Row;
45
46                 public CultureInfoEntry ()
47                 {
48                         DateTimeFormatEntry = new DateTimeFormatEntry ();
49                         NumberFormatEntry = new NumberFormatEntry ();
50                 }
51
52                 public string Language {
53                         get {
54                                 return language;
55                         }
56                         set {
57                                 language = (value == "zh") ? "zh-CHS" : value;
58                         }
59                 }
60
61                 public string Name {
62                         get {
63                                 if (Territory == null)
64                                         return Language;
65                                 return (Language.StartsWith ("zh") ? "zh" : Language) + "-" + Territory;
66                         }
67                 }
68
69                 public override string ToString ()
70                 {
71                         StringBuilder builder = new StringBuilder ();
72                         AppendTableRow (builder);
73                         return builder.ToString ();
74                 }
75
76                 public void AppendTableRow (StringBuilder builder)
77                 {
78                         builder.Append ("\t{");
79                         builder.AppendFormat ("{0}, {1}, {2}, " +
80                                         "{3}, {4}, {5}, " +
81                                         "{6}, {7}, {8}, " +
82                                         "{9}, {10}, " +
83                                         "{11}, " +
84                                         "{12}, {13}, {14}",
85                                         Lcid, ParentLcid, SpecificLcid,
86                                         EncodeStringIdx (Name), EncodeStringIdx (IcuName), EncodeStringIdx (EnglishName),
87                                         EncodeStringIdx (DisplayName), EncodeStringIdx (NativeName), EncodeStringIdx (Win3Lang),
88                                         EncodeStringIdx (ISO3Lang), EncodeStringIdx (ISO2Lang),
89                                         ValuesString (CalendarData),
90                                         DateTimeFormatEntry == null ? -1 : DateTimeFormatEntry.Row,
91                                         NumberFormatEntry == null ? -1 : NumberFormatEntry.Row,
92                                         TextInfoEntry.ToString ());
93                         builder.Append ('}');
94                 }
95
96                 private string ValuesString (int [] values)
97                 {
98                         StringBuilder builder = new StringBuilder ();
99                         builder.Append ('{');
100                         for (int i=0; i<values.Length; i++) {
101                                 builder.Append (values [i].ToString ());
102                                 if (i+1 < values.Length)
103                                         builder.Append (", ");
104                         }
105                         builder.Append ("}");
106                         return builder.ToString ();
107                 }
108         }
109         
110 }
111