[runtime] Updates comments.
[mono.git] / tools / locale-builder / NumberFormatEntry.cs
1 //
2 // DateTimeFormatEntry.cs
3 //
4 // Authors:
5 //  Jackson Harper (jackson@ximian.com)
6 //      Marek Safar  <marek.safar@gmail.com>
7 //
8 // (C) 2004, Novell, Inc (http://www.novell.com)
9 // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Text;
32 using System.Globalization;
33
34 namespace Mono.Tools.LocaleBuilder
35 {
36         public class NumberFormatEntry : Entry
37         {
38                 public string CurrencyDecimalDigits;
39                 public string CurrencyDecimalSeparator = ",";
40                 public string CurrencyGroupSeparator = ",";
41                 public string[] CurrencyGroupSizes = new string[Constants.GROUP_SIZE];
42                 public string CurrencyNegativePattern;
43                 public string CurrencyPositivePattern;
44                 public string CurrencySymbol;
45                 public string NaNSymbol;
46                 public string NegativeSign = "-";
47                 public int NumberDecimalDigits;
48                 public string NumberDecimalSeparator = ",";
49                 public string NumberGroupSeparator = ",";
50                 public string[] NumberGroupSizes = new string[Constants.GROUP_SIZE];
51                 public string NumberNegativePattern;
52                 public int PercentDecimalDigits;
53                 public string PercentDecimalSeparator = ",";
54                 public string PercentGroupSeparator = ",";
55                 public string[] PercentGroupSizes = new string[Constants.GROUP_SIZE];
56                 public string PercentNegativePattern;
57                 public string PercentPositivePattern;
58                 public string PercentSymbol = "%";
59                 public string PerMilleSymbol = "‰";
60                 public string InfinitySymbol = "Infinity";
61                 public string PositiveSign = "+";
62                 public DigitShapes DigitSubstitution = DigitShapes.None;
63                 public string[] NativeDigits = new string[10] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
64
65                 public int Row;
66
67                 public string NegativeInfinitySymbol
68                 {
69                         get
70                         {
71                                 if (InfinitySymbol.StartsWith (PositiveSign))
72                                         return NegativeSign + InfinitySymbol.Substring (1, InfinitySymbol.Length - 1);
73         
74                                 return NegativeSign + InfinitySymbol;
75                         }
76                 }
77
78                 public string PositiveInfinitySymbol
79                 {
80                         get
81                         {
82                                 return InfinitySymbol;
83                         }
84                 }
85
86                 public void AppendTableRow (StringBuilder builder)
87                 {
88                         builder.Append ("\t{");
89
90                         builder.Append (EncodeStringIdx (CurrencyDecimalSeparator) + ", ");
91                         builder.Append (EncodeStringIdx (CurrencyGroupSeparator) + ", ");
92                         builder.Append (EncodeStringIdx (PercentDecimalSeparator) + ", ");
93                         builder.Append (EncodeStringIdx (PercentGroupSeparator) + ", ");
94                         builder.Append (EncodeStringIdx (NumberDecimalSeparator) + ", ");
95                         builder.Append (EncodeStringIdx (NumberGroupSeparator) + ", ");
96
97                         builder.Append (EncodeStringIdx (CurrencySymbol) + ", ");
98                         builder.Append (EncodeStringIdx (PercentSymbol) + ", ");
99                         builder.Append (EncodeStringIdx (NaNSymbol) + ", ");
100                         builder.Append (EncodeStringIdx (PerMilleSymbol) + ", ");
101                         builder.Append (EncodeStringIdx (NegativeInfinitySymbol) + ", ");
102                         builder.Append (EncodeStringIdx (PositiveInfinitySymbol) + ", ");
103
104                         builder.Append (EncodeStringIdx (NegativeSign) + ", ");
105                         builder.Append (EncodeStringIdx (PositiveSign) + ", ");
106
107                         builder.Append (CurrencyNegativePattern + ", ");
108                         builder.Append (CurrencyPositivePattern + ", ");
109                         builder.Append (PercentNegativePattern + ", ");
110                         builder.Append (PercentPositivePattern + ", ");
111                         builder.Append (NumberNegativePattern + ", ");
112
113                         builder.Append (CurrencyDecimalDigits + ", ");
114                         builder.Append (PercentDecimalDigits + ", ");
115                         builder.Append (NumberDecimalDigits + ", ");
116
117                         AppendGroupSizes (builder, CurrencyGroupSizes);
118                         builder.Append (", ");
119                         AppendGroupSizes (builder, PercentGroupSizes);
120                         builder.Append (", ");
121                         AppendGroupSizes (builder, NumberGroupSizes);
122
123                         builder.Append ('}');
124                 }
125
126                 static void AppendGroupSizes (StringBuilder builder, string[] gs)
127                 {
128                         builder.Append ('{');
129                         for (int i = 0; i < gs.Length; i++) {
130                                 if (i > 0)
131                                         builder.Append (", ");
132
133                                 if (gs[i] == null)
134                                         builder.Append (-1);
135                                 else
136                                         builder.Append (gs[i]);
137                         }
138
139                         builder.Append ('}');
140                 }
141
142                 public override string ToString ()
143                 {
144                         StringBuilder builder = new StringBuilder ();
145                         AppendTableRow (builder);
146                         return builder.ToString ();
147                 }
148         }
149 }
150