Merge pull request #309 from i59/patch-1
[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                                 return NegativeSign + InfinitySymbol;
72                         }
73                 }
74
75                 public string PositiveInfinitySymbol
76                 {
77                         get
78                         {
79                                 return InfinitySymbol == "Infinity" ? InfinitySymbol : PositiveSign + InfinitySymbol;
80                         }
81                 }
82
83                 public void AppendTableRow (StringBuilder builder)
84                 {
85                         builder.Append ("\t{");
86
87                         builder.Append (EncodeStringIdx (CurrencyDecimalSeparator) + ", ");
88                         builder.Append (EncodeStringIdx (CurrencyGroupSeparator) + ", ");
89                         builder.Append (EncodeStringIdx (PercentDecimalSeparator) + ", ");
90                         builder.Append (EncodeStringIdx (PercentGroupSeparator) + ", ");
91                         builder.Append (EncodeStringIdx (NumberDecimalSeparator) + ", ");
92                         builder.Append (EncodeStringIdx (NumberGroupSeparator) + ", ");
93
94                         builder.Append (EncodeStringIdx (CurrencySymbol) + ", ");
95                         builder.Append (EncodeStringIdx (PercentSymbol) + ", ");
96                         builder.Append (EncodeStringIdx (NaNSymbol) + ", ");
97                         builder.Append (EncodeStringIdx (PerMilleSymbol) + ", ");
98                         builder.Append (EncodeStringIdx (NegativeInfinitySymbol) + ", ");
99                         builder.Append (EncodeStringIdx (PositiveInfinitySymbol) + ", ");
100
101                         builder.Append (EncodeStringIdx (NegativeSign) + ", ");
102                         builder.Append (EncodeStringIdx (PositiveSign) + ", ");
103
104                         builder.Append (CurrencyNegativePattern + ", ");
105                         builder.Append (CurrencyPositivePattern + ", ");
106                         builder.Append (PercentNegativePattern + ", ");
107                         builder.Append (PercentPositivePattern + ", ");
108                         builder.Append (NumberNegativePattern + ", ");
109
110                         builder.Append (CurrencyDecimalDigits + ", ");
111                         builder.Append (PercentDecimalDigits + ", ");
112                         builder.Append (NumberDecimalDigits + ", ");
113
114                         AppendGroupSizes (builder, CurrencyGroupSizes);
115                         builder.Append (", ");
116                         AppendGroupSizes (builder, PercentGroupSizes);
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