Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ParseNumber()

static unsafe bool System.Globalization.FormatProvider.Number.ParseNumber ( ref char * str,
char * strEnd,
NumberStyles options,
ref NumberBuffer number,
StringBuilder sb,
NumberFormatInfo numfmt,
bool parseDecimal )
inlinestaticprivate

Definition at line 126 of file FormatProvider.cs.

127 {
128 number.scale = 0;
129 number.sign = false;
130 string text = null;
131 bool allowHyphenDuringParsing = AllowHyphenDuringParsing(numfmt);
132 bool flag = false;
133 string str2;
134 string str3;
135 if ((options & NumberStyles.AllowCurrencySymbol) != 0)
136 {
137 text = numfmt.CurrencySymbol;
138 str2 = numfmt.CurrencyDecimalSeparator;
139 str3 = numfmt.CurrencyGroupSeparator;
140 flag = true;
141 }
142 else
143 {
144 str2 = numfmt.NumberDecimalSeparator;
145 str3 = numfmt.NumberGroupSeparator;
146 }
147 int num = 0;
148 bool flag2 = sb != null;
149 int num2 = (flag2 ? int.MaxValue : 32);
150 char* ptr = str;
151 char c = ((ptr < strEnd) ? (*ptr) : '\0');
152 char* digits = number.digits;
153 while (true)
154 {
155 if (!IsWhite(c) || (options & NumberStyles.AllowLeadingWhite) == 0 || (((uint)num & (true ? 1u : 0u)) != 0 && (num & 0x20) == 0 && numfmt.NumberNegativePattern != 2))
156 {
157 char* ptr2;
158 if ((options & NumberStyles.AllowLeadingSign) != 0 && (num & 1) == 0 && ((ptr2 = MatchChars(ptr, strEnd, numfmt.PositiveSign)) != null || ((ptr2 = MatchNegativeSignChars(ptr, strEnd, numfmt.NegativeSign, allowHyphenDuringParsing)) != null && (number.sign = true))))
159 {
160 num |= 1;
161 ptr = ptr2 - 1;
162 }
163 else if (c == '(' && (options & NumberStyles.AllowParentheses) != 0 && (num & 1) == 0)
164 {
165 num |= 3;
166 number.sign = true;
167 }
168 else
169 {
170 if (text == null || (ptr2 = MatchChars(ptr, strEnd, text)) == null)
171 {
172 break;
173 }
174 num |= 0x20;
175 text = null;
176 ptr = ptr2 - 1;
177 }
178 }
179 c = ((++ptr < strEnd) ? (*ptr) : '\0');
180 }
181 int num3 = 0;
182 int num4 = 0;
183 while (true)
184 {
185 char* ptr2;
186 if ((c >= '0' && c <= '9') || ((options & NumberStyles.AllowHexSpecifier) != 0 && ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))))
187 {
188 num |= 4;
189 if (c != '0' || ((uint)num & 8u) != 0 || (flag2 && (options & NumberStyles.AllowHexSpecifier) != 0))
190 {
191 if (num3 < num2)
192 {
193 if (flag2)
194 {
195 sb.Append(c);
196 }
197 else
198 {
199 digits[num3++] = c;
200 }
201 if (c != '0' || parseDecimal)
202 {
203 num4 = num3;
204 }
205 }
206 if ((num & 0x10) == 0)
207 {
208 number.scale++;
209 }
210 num |= 8;
211 }
212 else if (((uint)num & 0x10u) != 0)
213 {
214 number.scale--;
215 }
216 }
217 else if ((options & NumberStyles.AllowDecimalPoint) != 0 && (num & 0x10) == 0 && ((ptr2 = MatchChars(ptr, strEnd, str2)) != null || (flag && (num & 0x20) == 0 && (ptr2 = MatchChars(ptr, strEnd, numfmt.NumberDecimalSeparator)) != null)))
218 {
219 num |= 0x10;
220 ptr = ptr2 - 1;
221 }
222 else
223 {
224 if ((options & NumberStyles.AllowThousands) == 0 || (num & 4) == 0 || ((uint)num & 0x10u) != 0 || ((ptr2 = MatchChars(ptr, strEnd, str3)) == null && (!flag || ((uint)num & 0x20u) != 0 || (ptr2 = MatchChars(ptr, strEnd, numfmt.NumberGroupSeparator)) == null)))
225 {
226 break;
227 }
228 ptr = ptr2 - 1;
229 }
230 c = ((++ptr < strEnd) ? (*ptr) : '\0');
231 }
232 bool flag3 = false;
233 number.precision = num4;
234 if (flag2)
235 {
236 sb.Append('\0');
237 }
238 else
239 {
240 digits[num4] = '\0';
241 }
242 if (((uint)num & 4u) != 0)
243 {
244 if ((c == 'E' || c == 'e') && (options & NumberStyles.AllowExponent) != 0)
245 {
246 char* ptr3 = ptr;
247 c = ((++ptr < strEnd) ? (*ptr) : '\0');
248 char* ptr2;
249 if ((ptr2 = MatchChars(ptr, strEnd, numfmt.PositiveSign)) != null)
250 {
251 c = (((ptr = ptr2) < strEnd) ? (*ptr) : '\0');
252 }
253 else if ((ptr2 = MatchNegativeSignChars(ptr, strEnd, numfmt.NegativeSign, allowHyphenDuringParsing)) != null)
254 {
255 c = (((ptr = ptr2) < strEnd) ? (*ptr) : '\0');
256 flag3 = true;
257 }
258 if (c >= '0' && c <= '9')
259 {
260 int num5 = 0;
261 do
262 {
263 num5 = num5 * 10 + (c - 48);
264 c = ((++ptr < strEnd) ? (*ptr) : '\0');
265 if (num5 > 1000)
266 {
267 num5 = 9999;
268 while (c >= '0' && c <= '9')
269 {
270 c = ((++ptr < strEnd) ? (*ptr) : '\0');
271 }
272 }
273 }
274 while (c >= '0' && c <= '9');
275 if (flag3)
276 {
277 num5 = -num5;
278 }
279 number.scale += num5;
280 }
281 else
282 {
283 ptr = ptr3;
284 c = ((ptr < strEnd) ? (*ptr) : '\0');
285 }
286 }
287 while (true)
288 {
289 if (!IsWhite(c) || (options & NumberStyles.AllowTrailingWhite) == 0)
290 {
291 char* ptr2;
292 if ((options & NumberStyles.AllowTrailingSign) != 0 && (num & 1) == 0 && ((ptr2 = MatchChars(ptr, strEnd, numfmt.PositiveSign)) != null || ((ptr2 = MatchNegativeSignChars(ptr, strEnd, numfmt.NegativeSign, allowHyphenDuringParsing)) != null && (number.sign = true))))
293 {
294 num |= 1;
295 ptr = ptr2 - 1;
296 }
297 else if (c == ')' && ((uint)num & 2u) != 0)
298 {
299 num &= -3;
300 }
301 else
302 {
303 if (text == null || (ptr2 = MatchChars(ptr, strEnd, text)) == null)
304 {
305 break;
306 }
307 text = null;
308 ptr = ptr2 - 1;
309 }
310 }
311 c = ((++ptr < strEnd) ? (*ptr) : '\0');
312 }
313 if ((num & 2) == 0)
314 {
315 if ((num & 8) == 0)
316 {
317 if (!parseDecimal)
318 {
319 number.scale = 0;
320 }
321 if ((num & 0x10) == 0)
322 {
323 number.sign = false;
324 }
325 }
326 str = ptr;
327 return true;
328 }
329 }
330 str = ptr;
331 return false;
332 }
static unsafe char * MatchNegativeSignChars(char *p, char *pEnd, string negativeSign, bool allowHyphenDuringParsing)
static unsafe char * MatchChars(char *p, char *pEnd, string str)
static bool AllowHyphenDuringParsing(NumberFormatInfo info)
StringBuilder Append(char value, int repeatCount)

References System.Globalization.FormatProvider.Number.AllowHyphenDuringParsing(), System.Text.StringBuilder.Append(), System.Globalization.NumberFormatInfo.CurrencyDecimalSeparator, System.Globalization.NumberFormatInfo.CurrencyGroupSeparator, System.Globalization.NumberFormatInfo.CurrencySymbol, System.Globalization.FormatProvider.Number.IsWhite(), System.Globalization.FormatProvider.Number.MatchChars(), System.Globalization.FormatProvider.Number.MatchNegativeSignChars(), System.Globalization.NumberFormatInfo.NegativeSign, System.Globalization.NumberFormatInfo.NumberDecimalSeparator, System.Globalization.NumberFormatInfo.NumberGroupSeparator, System.Globalization.NumberFormatInfo.NumberNegativePattern, System.options, System.Globalization.NumberFormatInfo.PositiveSign, System.str, and System.text.

Referenced by System.Globalization.FormatProvider.Number.TryStringToNumber().