Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DecimalFormatter.cs
Go to the documentation of this file.
2using System.Text;
3
5
6internal sealed class DecimalFormatter
7{
9
11
12 private readonly string _posFormat;
13
14 private readonly string _negFormat;
15
16 private readonly char _zeroDigit;
17
19 {
20 if (formatPicture.Length == 0)
21 {
23 }
24 _zeroDigit = decimalFormat.zeroDigit;
27 bool flag = true;
28 bool flag2 = false;
29 bool flag3 = false;
30 bool flag4 = false;
31 bool flag5 = false;
32 bool flag6 = false;
37 int num = 0;
38 int num2 = 0;
39 int num3 = -1;
40 int num4 = -1;
41 for (int i = 0; i < formatPicture.Length; i++)
42 {
43 char c5 = formatPicture[i];
44 if (c5 == decimalFormat.digit)
45 {
46 if (flag3 && flag)
47 {
49 }
50 num4 = stringBuilder.Length;
51 flag4 = (flag6 = true);
52 stringBuilder.Append('#');
53 }
54 else if (c5 == decimalFormat.zeroDigit)
55 {
56 if (flag4 && !flag)
57 {
59 }
60 num4 = stringBuilder.Length;
61 flag3 = (flag6 = true);
62 stringBuilder.Append('0');
63 }
64 else if (c5 == decimalFormat.patternSeparator)
65 {
66 if (!flag6)
67 {
69 }
70 if (flag2)
71 {
73 }
74 flag2 = true;
75 if (num3 < 0)
76 {
77 num3 = num4 + 1;
78 }
80 if (num2 > 9)
81 {
82 num2 = 0;
83 }
85 if (!flag5)
86 {
88 }
89 _posFormat = stringBuilder.ToString();
91 num3 = -1;
92 num4 = -1;
93 num = 0;
94 flag4 = (flag3 = (flag6 = false));
95 flag5 = false;
96 flag = true;
98 _negFormatInfo.NegativeSign = string.Empty;
99 }
100 else if (c5 == c)
101 {
102 if (flag5)
103 {
105 }
106 num3 = stringBuilder.Length;
107 flag5 = true;
108 flag4 = (flag3 = (flag = false));
109 stringBuilder.Append('.');
110 }
111 else if (c5 == c2)
112 {
113 num = stringBuilder.Length;
114 num4 = num;
115 stringBuilder.Append(',');
116 }
117 else if (c5 == c3)
118 {
119 stringBuilder.Append('%');
120 }
121 else if (c5 == c4)
122 {
123 stringBuilder.Append('‰');
124 }
125 else if (c5 == '\'')
126 {
127 int num5 = formatPicture.IndexOf('\'', i + 1);
128 if (num5 < 0)
129 {
131 }
132 stringBuilder.Append(formatPicture, i, num5 - i + 1);
133 i = num5;
134 }
135 else
136 {
137 if ((('0' <= c5 && c5 <= '9') || c5 == '\a') && decimalFormat.zeroDigit != '0')
138 {
139 stringBuilder.Append('\a');
140 }
141 if ("0#.,%‰Ee\\'\";".Contains(c5))
142 {
143 stringBuilder.Append('\\');
144 }
145 stringBuilder.Append(c5);
146 }
147 }
148 if (!flag6)
149 {
151 }
153 if (num3 < 0)
154 {
155 num3 = num4 + 1;
156 }
158 if (num2 > 9)
159 {
160 num2 = 0;
161 }
163 if (!flag5)
164 {
166 }
167 if (flag2)
168 {
169 _negFormat = stringBuilder.ToString();
170 }
171 else
172 {
173 _posFormat = stringBuilder.ToString();
174 }
175 }
176
178 {
179 if (commaIndex > 0 && commaIndex == decimalIndex - 1)
180 {
181 builder.Remove(decimalIndex - 1, 1);
182 }
183 else if (decimalIndex > commaIndex)
184 {
185 return decimalIndex - commaIndex - 1;
186 }
187 return 0;
188 }
189
190 public string Format(double value)
191 {
193 string text;
194 if (value < 0.0 && _negFormatInfo != null)
195 {
198 }
199 else
200 {
203 }
204 string text2 = value.ToString(text, numberFormatInfo);
205 if (_zeroDigit != '0')
206 {
208 int num = _zeroDigit - 48;
209 for (int i = 0; i < text2.Length; i++)
210 {
211 char c = text2[i];
212 switch (c)
213 {
214 case '0':
215 case '1':
216 case '2':
217 case '3':
218 case '4':
219 case '5':
220 case '6':
221 case '7':
222 case '8':
223 case '9':
224 c = (char)(c + (ushort)num);
225 break;
226 case '\a':
227 c = text2[++i];
228 break;
229 }
230 stringBuilder.Append(c);
231 }
232 text2 = stringBuilder.ToString();
233 }
234 return text2;
235 }
236
237 public static string Format(double value, string formatPicture, DecimalFormat decimalFormat)
238 {
240 }
241}
static string Xslt_InvalidFormat8
Definition SR.cs:2114
static string Xslt_InvalidFormat
Definition SR.cs:2104
static string Xslt_InvalidFormat2
Definition SR.cs:2108
static string Xslt_InvalidFormat5
Definition SR.cs:2112
static string Xslt_InvalidFormat3
Definition SR.cs:2110
static string Xslt_InvalidFormat1
Definition SR.cs:2106
Definition SR.cs:7
readonly NumberFormatInfo _negFormatInfo
readonly NumberFormatInfo _posFormatInfo
static string Format(double value, string formatPicture, DecimalFormat decimalFormat)
DecimalFormatter(string formatPicture, DecimalFormat decimalFormat)
static int RemoveTrailingComma(StringBuilder builder, int commaIndex, int decimalIndex)
static XsltException Create(string res, params string[] args)