Merge pull request #5714 from alexischr/update_bockbuild
[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                 /*
53                 public int PercentDecimalDigits;
54                 public string PercentDecimalSeparator = ",";
55                 public string PercentGroupSeparator = ",";
56                 public string[] PercentGroupSizes = new string[Constants.GROUP_SIZE];
57                 */
58                 public string PercentNegativePattern;
59                 public string PercentPositivePattern;
60                 public string PercentSymbol = "%";
61                 public string PerMilleSymbol = "‰";
62                 public string InfinitySymbol = "Infinity";
63                 public string PositiveSign = "+";
64                 public DigitShapes DigitSubstitution = DigitShapes.None;
65                 public string[] NativeDigits = new string[10] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
66
67                 public int Row;
68
69                 public string NegativeInfinitySymbol
70                 {
71                         get
72                         {
73                                 if (InfinitySymbol.StartsWith (PositiveSign))
74                                         return NegativeSign + InfinitySymbol.Substring (1, InfinitySymbol.Length - 1);
75         
76                                 return NegativeSign + InfinitySymbol;
77                         }
78                 }
79
80                 public string PositiveInfinitySymbol
81                 {
82                         get
83                         {
84                                 return InfinitySymbol;
85                         }
86                 }
87
88                 public void AppendTableRow (StringBuilder builder)
89                 {
90                         builder.Append ("\t{");
91
92                         builder.Append (EncodeStringIdx (CurrencyDecimalSeparator) + ", ");
93                         builder.Append (EncodeStringIdx (CurrencyGroupSeparator) + ", ");
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 (NumberDecimalDigits + ", ");
115
116                         AppendGroupSizes (builder, CurrencyGroupSizes);
117                         builder.Append (", ");
118                         AppendGroupSizes (builder, NumberGroupSizes);
119
120                         builder.Append ('}');
121                 }
122
123                 static void AppendGroupSizes (StringBuilder builder, string[] gs)
124                 {
125                         builder.Append ('{');
126                         for (int i = 0; i < gs.Length; i++) {
127                                 if (i > 0)
128                                         builder.Append (", ");
129
130                                 if (gs[i] == null)
131                                         builder.Append (-1);
132                                 else
133                                         builder.Append (gs[i]);
134                         }
135
136                         builder.Append ('}');
137                 }
138
139                 public override string ToString ()
140                 {
141                         StringBuilder builder = new StringBuilder ();
142                         AppendTableRow (builder);
143                         return builder.ToString ();
144                 }
145         }
146 }
147