Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Utf8Parser.cs
Go to the documentation of this file.
3
4namespace System.Buffers.Text;
5
6public static class Utf8Parser
7{
8 [Flags]
9 private enum ParseNumberOptions
10 {
12 }
13
14 private enum ComponentParseResult : byte
15 {
17 Colon,
18 Period,
20 }
21
22 private struct TimeSpanSplitter
23 {
24 public uint V1;
25
26 public uint V2;
27
28 public uint V3;
29
30 public uint V4;
31
32 public uint V5;
33
34 public bool IsNegative;
35
36 public uint Separators;
37
38 public bool TrySplitTimeSpan(ReadOnlySpan<byte> source, bool periodUsedToSeparateDay, out int bytesConsumed)
39 {
40 int i = 0;
41 byte b = 0;
42 for (; i != source.Length; i++)
43 {
44 b = source[i];
45 if (b != 32 && b != 9)
46 {
47 break;
48 }
49 }
50 if (i == source.Length)
51 {
52 bytesConsumed = 0;
53 return false;
54 }
55 if (b == 45)
56 {
57 IsNegative = true;
58 i++;
59 if (i == source.Length)
60 {
61 bytesConsumed = 0;
62 return false;
63 }
64 }
65 if (!TryParseUInt32D(source.Slice(i), out V1, out var bytesConsumed2))
66 {
67 bytesConsumed = 0;
68 return false;
69 }
70 i += bytesConsumed2;
71 ComponentParseResult componentParseResult = ParseComponent(source, periodUsedToSeparateDay, ref i, out V2);
72 switch (componentParseResult)
73 {
74 case ComponentParseResult.ParseFailure:
75 bytesConsumed = 0;
76 return false;
77 case ComponentParseResult.NoMoreData:
78 bytesConsumed = i;
79 return true;
80 default:
81 Separators |= (uint)componentParseResult << 24;
82 componentParseResult = ParseComponent(source, neverParseAsFraction: false, ref i, out V3);
83 switch (componentParseResult)
84 {
85 case ComponentParseResult.ParseFailure:
86 bytesConsumed = 0;
87 return false;
88 case ComponentParseResult.NoMoreData:
89 bytesConsumed = i;
90 return true;
91 default:
92 Separators |= (uint)componentParseResult << 16;
93 componentParseResult = ParseComponent(source, neverParseAsFraction: false, ref i, out V4);
94 switch (componentParseResult)
95 {
96 case ComponentParseResult.ParseFailure:
97 bytesConsumed = 0;
98 return false;
99 case ComponentParseResult.NoMoreData:
100 bytesConsumed = i;
101 return true;
102 default:
103 Separators |= (uint)componentParseResult << 8;
104 componentParseResult = ParseComponent(source, neverParseAsFraction: false, ref i, out V5);
105 switch (componentParseResult)
106 {
107 case ComponentParseResult.ParseFailure:
108 bytesConsumed = 0;
109 return false;
110 case ComponentParseResult.NoMoreData:
111 bytesConsumed = i;
112 return true;
113 default:
114 Separators |= (uint)componentParseResult;
115 if (i != source.Length && (source[i] == 46 || source[i] == 58))
116 {
117 bytesConsumed = 0;
118 return false;
119 }
120 bytesConsumed = i;
121 return true;
122 }
123 }
124 }
125 }
126 }
127
128 private static ComponentParseResult ParseComponent(ReadOnlySpan<byte> source, bool neverParseAsFraction, ref int srcIndex, out uint value)
129 {
130 if (srcIndex == source.Length)
131 {
132 value = 0u;
133 return ComponentParseResult.NoMoreData;
134 }
135 byte b = source[srcIndex];
136 if (b == 58 || (b == 46 && neverParseAsFraction))
137 {
138 srcIndex++;
139 if (!TryParseUInt32D(source.Slice(srcIndex), out value, out var bytesConsumed))
140 {
141 value = 0u;
142 return ComponentParseResult.ParseFailure;
143 }
144 srcIndex += bytesConsumed;
145 if (b != 58)
146 {
147 return ComponentParseResult.Period;
148 }
149 return ComponentParseResult.Colon;
150 }
151 if (b == 46)
152 {
153 srcIndex++;
154 if (!TryParseTimeSpanFraction(source.Slice(srcIndex), out value, out var bytesConsumed2))
155 {
156 value = 0u;
157 return ComponentParseResult.ParseFailure;
158 }
159 srcIndex += bytesConsumed2;
160 return ComponentParseResult.Period;
161 }
162 value = 0u;
163 return ComponentParseResult.NoMoreData;
164 }
165 }
166
167 private static readonly int[] s_daysToMonth365 = new int[13]
168 {
169 0, 31, 59, 90, 120, 151, 181, 212, 243, 273,
170 304, 334, 365
171 };
172
173 private static readonly int[] s_daysToMonth366 = new int[13]
174 {
175 0, 31, 60, 91, 121, 152, 182, 213, 244, 274,
176 305, 335, 366
177 };
178
179 public static bool TryParse(ReadOnlySpan<byte> source, out bool value, out int bytesConsumed, char standardFormat = '\0')
180 {
181 if (standardFormat != 0 && standardFormat != 'G' && standardFormat != 'l')
182 {
184 }
185 if (source.Length >= 4)
186 {
187 int num = BinaryPrimitives.ReadInt32LittleEndian(source) & -538976289;
188 if (num == 1163219540)
189 {
190 bytesConsumed = 4;
191 value = true;
192 return true;
193 }
194 if (source.Length > 4 && num == 1397506374 && (source[4] & -33) == 69)
195 {
196 bytesConsumed = 5;
197 value = false;
198 return true;
199 }
200 }
201 bytesConsumed = 0;
202 value = false;
203 return false;
204 }
205
206 public static bool TryParse(ReadOnlySpan<byte> source, out DateTime value, out int bytesConsumed, char standardFormat = '\0')
207 {
208 switch (standardFormat)
209 {
210 case 'R':
211 {
212 if (!TryParseDateTimeOffsetR(source, 0u, out var dateTimeOffset, out bytesConsumed))
213 {
214 value = default(DateTime);
215 return false;
216 }
217 value = dateTimeOffset.DateTime;
218 return true;
219 }
220 case 'l':
221 {
222 if (!TryParseDateTimeOffsetR(source, 32u, out var dateTimeOffset2, out bytesConsumed))
223 {
224 value = default(DateTime);
225 return false;
226 }
227 value = dateTimeOffset2.DateTime;
228 return true;
229 }
230 case 'O':
231 {
232 if (!TryParseDateTimeOffsetO(source, out var value2, out bytesConsumed, out var kind))
233 {
234 value = default(DateTime);
235 bytesConsumed = 0;
236 return false;
237 }
238 switch (kind)
239 {
240 case DateTimeKind.Local:
241 value = value2.LocalDateTime;
242 break;
243 case DateTimeKind.Utc:
244 value = value2.UtcDateTime;
245 break;
246 default:
247 value = value2.DateTime;
248 break;
249 }
250 return true;
251 }
252 case '\0':
253 case 'G':
254 {
255 DateTimeOffset valueAsOffset;
256 return TryParseDateTimeG(source, out value, out valueAsOffset, out bytesConsumed);
257 }
258 default:
259 return ParserHelpers.TryParseThrowFormatException<DateTime>(out value, out bytesConsumed);
260 }
261 }
262
263 public static bool TryParse(ReadOnlySpan<byte> source, out DateTimeOffset value, out int bytesConsumed, char standardFormat = '\0')
264 {
265 DateTimeKind kind;
266 DateTime value2;
267 return standardFormat switch
268 {
269 'R' => TryParseDateTimeOffsetR(source, 0u, out value, out bytesConsumed),
270 'l' => TryParseDateTimeOffsetR(source, 32u, out value, out bytesConsumed),
271 'O' => TryParseDateTimeOffsetO(source, out value, out bytesConsumed, out kind),
272 '\0' => TryParseDateTimeOffsetDefault(source, out value, out bytesConsumed),
273 'G' => TryParseDateTimeG(source, out value2, out value, out bytesConsumed),
274 _ => ParserHelpers.TryParseThrowFormatException<DateTimeOffset>(out value, out bytesConsumed),
275 };
276 }
277
278 private static bool TryParseDateTimeOffsetDefault(ReadOnlySpan<byte> source, out DateTimeOffset value, out int bytesConsumed)
279 {
280 if (source.Length < 26)
281 {
282 bytesConsumed = 0;
283 value = default(DateTimeOffset);
284 return false;
285 }
286 if (!TryParseDateTimeG(source, out var value2, out var _, out var _))
287 {
288 bytesConsumed = 0;
289 value = default(DateTimeOffset);
290 return false;
291 }
292 if (source[19] != 32)
293 {
294 bytesConsumed = 0;
295 value = default(DateTimeOffset);
296 return false;
297 }
298 byte b = source[20];
299 if (b != 43 && b != 45)
300 {
301 bytesConsumed = 0;
302 value = default(DateTimeOffset);
303 return false;
304 }
305 uint num = (uint)(source[21] - 48);
306 uint num2 = (uint)(source[22] - 48);
307 if (num > 9 || num2 > 9)
308 {
309 bytesConsumed = 0;
310 value = default(DateTimeOffset);
311 return false;
312 }
313 int offsetHours = (int)(num * 10 + num2);
314 if (source[23] != 58)
315 {
316 bytesConsumed = 0;
317 value = default(DateTimeOffset);
318 return false;
319 }
320 uint num3 = (uint)(source[24] - 48);
321 uint num4 = (uint)(source[25] - 48);
322 if (num3 > 9 || num4 > 9)
323 {
324 bytesConsumed = 0;
325 value = default(DateTimeOffset);
326 return false;
327 }
328 int offsetMinutes = (int)(num3 * 10 + num4);
329 if (!TryCreateDateTimeOffset(value2, b == 45, offsetHours, offsetMinutes, out value))
330 {
331 bytesConsumed = 0;
332 value = default(DateTimeOffset);
333 return false;
334 }
335 bytesConsumed = 26;
336 return true;
337 }
338
339 private static bool TryParseDateTimeG(ReadOnlySpan<byte> source, out DateTime value, out DateTimeOffset valueAsOffset, out int bytesConsumed)
340 {
341 if (source.Length < 19)
342 {
343 bytesConsumed = 0;
344 value = default(DateTime);
345 valueAsOffset = default(DateTimeOffset);
346 return false;
347 }
348 uint num = (uint)(source[0] - 48);
349 uint num2 = (uint)(source[1] - 48);
350 if (num > 9 || num2 > 9)
351 {
352 bytesConsumed = 0;
353 value = default(DateTime);
354 valueAsOffset = default(DateTimeOffset);
355 return false;
356 }
357 int month = (int)(num * 10 + num2);
358 if (source[2] != 47)
359 {
360 bytesConsumed = 0;
361 value = default(DateTime);
362 valueAsOffset = default(DateTimeOffset);
363 return false;
364 }
365 uint num3 = (uint)(source[3] - 48);
366 uint num4 = (uint)(source[4] - 48);
367 if (num3 > 9 || num4 > 9)
368 {
369 bytesConsumed = 0;
370 value = default(DateTime);
371 valueAsOffset = default(DateTimeOffset);
372 return false;
373 }
374 int day = (int)(num3 * 10 + num4);
375 if (source[5] != 47)
376 {
377 bytesConsumed = 0;
378 value = default(DateTime);
379 valueAsOffset = default(DateTimeOffset);
380 return false;
381 }
382 uint num5 = (uint)(source[6] - 48);
383 uint num6 = (uint)(source[7] - 48);
384 uint num7 = (uint)(source[8] - 48);
385 uint num8 = (uint)(source[9] - 48);
386 if (num5 > 9 || num6 > 9 || num7 > 9 || num8 > 9)
387 {
388 bytesConsumed = 0;
389 value = default(DateTime);
390 valueAsOffset = default(DateTimeOffset);
391 return false;
392 }
393 int year = (int)(num5 * 1000 + num6 * 100 + num7 * 10 + num8);
394 if (source[10] != 32)
395 {
396 bytesConsumed = 0;
397 value = default(DateTime);
398 valueAsOffset = default(DateTimeOffset);
399 return false;
400 }
401 uint num9 = (uint)(source[11] - 48);
402 uint num10 = (uint)(source[12] - 48);
403 if (num9 > 9 || num10 > 9)
404 {
405 bytesConsumed = 0;
406 value = default(DateTime);
407 valueAsOffset = default(DateTimeOffset);
408 return false;
409 }
410 int hour = (int)(num9 * 10 + num10);
411 if (source[13] != 58)
412 {
413 bytesConsumed = 0;
414 value = default(DateTime);
415 valueAsOffset = default(DateTimeOffset);
416 return false;
417 }
418 uint num11 = (uint)(source[14] - 48);
419 uint num12 = (uint)(source[15] - 48);
420 if (num11 > 9 || num12 > 9)
421 {
422 bytesConsumed = 0;
423 value = default(DateTime);
424 valueAsOffset = default(DateTimeOffset);
425 return false;
426 }
427 int minute = (int)(num11 * 10 + num12);
428 if (source[16] != 58)
429 {
430 bytesConsumed = 0;
431 value = default(DateTime);
432 valueAsOffset = default(DateTimeOffset);
433 return false;
434 }
435 uint num13 = (uint)(source[17] - 48);
436 uint num14 = (uint)(source[18] - 48);
437 if (num13 > 9 || num14 > 9)
438 {
439 bytesConsumed = 0;
440 value = default(DateTime);
441 valueAsOffset = default(DateTimeOffset);
442 return false;
443 }
444 int second = (int)(num13 * 10 + num14);
445 if (!TryCreateDateTimeOffsetInterpretingDataAsLocalTime(year, month, day, hour, minute, second, 0, out valueAsOffset))
446 {
447 bytesConsumed = 0;
448 value = default(DateTime);
449 valueAsOffset = default(DateTimeOffset);
450 return false;
451 }
452 bytesConsumed = 19;
453 value = valueAsOffset.DateTime;
454 return true;
455 }
456
457 private static bool TryCreateDateTimeOffset(DateTime dateTime, bool offsetNegative, int offsetHours, int offsetMinutes, out DateTimeOffset value)
458 {
459 if ((uint)offsetHours > 14u)
460 {
461 value = default(DateTimeOffset);
462 return false;
463 }
464 if ((uint)offsetMinutes > 59u)
465 {
466 value = default(DateTimeOffset);
467 return false;
468 }
469 if (offsetHours == 14 && offsetMinutes != 0)
470 {
471 value = default(DateTimeOffset);
472 return false;
473 }
474 long num = ((long)offsetHours * 3600L + (long)offsetMinutes * 60L) * 10000000;
475 if (offsetNegative)
476 {
477 num = -num;
478 }
479 try
480 {
481 value = new DateTimeOffset(dateTime.Ticks, new TimeSpan(num));
482 }
484 {
485 value = default(DateTimeOffset);
486 return false;
487 }
488 return true;
489 }
490
491 private static bool TryCreateDateTimeOffset(int year, int month, int day, int hour, int minute, int second, int fraction, bool offsetNegative, int offsetHours, int offsetMinutes, out DateTimeOffset value)
492 {
493 if (!TryCreateDateTime(year, month, day, hour, minute, second, fraction, DateTimeKind.Unspecified, out var value2))
494 {
495 value = default(DateTimeOffset);
496 return false;
497 }
498 if (!TryCreateDateTimeOffset(value2, offsetNegative, offsetHours, offsetMinutes, out value))
499 {
500 value = default(DateTimeOffset);
501 return false;
502 }
503 return true;
504 }
505
506 private static bool TryCreateDateTimeOffsetInterpretingDataAsLocalTime(int year, int month, int day, int hour, int minute, int second, int fraction, out DateTimeOffset value)
507 {
508 if (!TryCreateDateTime(year, month, day, hour, minute, second, fraction, DateTimeKind.Local, out var value2))
509 {
510 value = default(DateTimeOffset);
511 return false;
512 }
513 try
514 {
515 value = new DateTimeOffset(value2);
516 }
518 {
519 value = default(DateTimeOffset);
520 return false;
521 }
522 return true;
523 }
524
525 private static bool TryCreateDateTime(int year, int month, int day, int hour, int minute, int second, int fraction, DateTimeKind kind, out DateTime value)
526 {
527 if (year == 0)
528 {
529 value = default(DateTime);
530 return false;
531 }
532 if ((uint)(month - 1) >= 12u)
533 {
534 value = default(DateTime);
535 return false;
536 }
537 uint num = (uint)(day - 1);
538 if (num >= 28 && num >= DateTime.DaysInMonth(year, month))
539 {
540 value = default(DateTime);
541 return false;
542 }
543 if ((uint)hour > 23u)
544 {
545 value = default(DateTime);
546 return false;
547 }
548 if ((uint)minute > 59u)
549 {
550 value = default(DateTime);
551 return false;
552 }
553 if ((uint)second > 59u)
554 {
555 value = default(DateTime);
556 return false;
557 }
559 int num2 = year - 1;
560 int num3 = num2 * 365 + num2 / 4 - num2 / 100 + num2 / 400 + array[month - 1] + day - 1;
561 long num4 = num3 * 864000000000L;
562 int num5 = hour * 3600 + minute * 60 + second;
563 num4 += (long)num5 * 10000000L;
564 num4 += fraction;
565 value = new DateTime(num4, kind);
566 return true;
567 }
568
569 private static bool TryParseDateTimeOffsetO(ReadOnlySpan<byte> source, out DateTimeOffset value, out int bytesConsumed, out DateTimeKind kind)
570 {
571 if (source.Length < 27)
572 {
573 value = default(DateTimeOffset);
574 bytesConsumed = 0;
575 kind = DateTimeKind.Unspecified;
576 return false;
577 }
578 uint num = (uint)(source[0] - 48);
579 uint num2 = (uint)(source[1] - 48);
580 uint num3 = (uint)(source[2] - 48);
581 uint num4 = (uint)(source[3] - 48);
582 if (num > 9 || num2 > 9 || num3 > 9 || num4 > 9)
583 {
584 value = default(DateTimeOffset);
585 bytesConsumed = 0;
586 kind = DateTimeKind.Unspecified;
587 return false;
588 }
589 int year = (int)(num * 1000 + num2 * 100 + num3 * 10 + num4);
590 if (source[4] != 45)
591 {
592 value = default(DateTimeOffset);
593 bytesConsumed = 0;
594 kind = DateTimeKind.Unspecified;
595 return false;
596 }
597 uint num5 = (uint)(source[5] - 48);
598 uint num6 = (uint)(source[6] - 48);
599 if (num5 > 9 || num6 > 9)
600 {
601 value = default(DateTimeOffset);
602 bytesConsumed = 0;
603 kind = DateTimeKind.Unspecified;
604 return false;
605 }
606 int month = (int)(num5 * 10 + num6);
607 if (source[7] != 45)
608 {
609 value = default(DateTimeOffset);
610 bytesConsumed = 0;
611 kind = DateTimeKind.Unspecified;
612 return false;
613 }
614 uint num7 = (uint)(source[8] - 48);
615 uint num8 = (uint)(source[9] - 48);
616 if (num7 > 9 || num8 > 9)
617 {
618 value = default(DateTimeOffset);
619 bytesConsumed = 0;
620 kind = DateTimeKind.Unspecified;
621 return false;
622 }
623 int day = (int)(num7 * 10 + num8);
624 if (source[10] != 84)
625 {
626 value = default(DateTimeOffset);
627 bytesConsumed = 0;
628 kind = DateTimeKind.Unspecified;
629 return false;
630 }
631 uint num9 = (uint)(source[11] - 48);
632 uint num10 = (uint)(source[12] - 48);
633 if (num9 > 9 || num10 > 9)
634 {
635 value = default(DateTimeOffset);
636 bytesConsumed = 0;
637 kind = DateTimeKind.Unspecified;
638 return false;
639 }
640 int hour = (int)(num9 * 10 + num10);
641 if (source[13] != 58)
642 {
643 value = default(DateTimeOffset);
644 bytesConsumed = 0;
645 kind = DateTimeKind.Unspecified;
646 return false;
647 }
648 uint num11 = (uint)(source[14] - 48);
649 uint num12 = (uint)(source[15] - 48);
650 if (num11 > 9 || num12 > 9)
651 {
652 value = default(DateTimeOffset);
653 bytesConsumed = 0;
654 kind = DateTimeKind.Unspecified;
655 return false;
656 }
657 int minute = (int)(num11 * 10 + num12);
658 if (source[16] != 58)
659 {
660 value = default(DateTimeOffset);
661 bytesConsumed = 0;
662 kind = DateTimeKind.Unspecified;
663 return false;
664 }
665 uint num13 = (uint)(source[17] - 48);
666 uint num14 = (uint)(source[18] - 48);
667 if (num13 > 9 || num14 > 9)
668 {
669 value = default(DateTimeOffset);
670 bytesConsumed = 0;
671 kind = DateTimeKind.Unspecified;
672 return false;
673 }
674 int second = (int)(num13 * 10 + num14);
675 if (source[19] != 46)
676 {
677 value = default(DateTimeOffset);
678 bytesConsumed = 0;
679 kind = DateTimeKind.Unspecified;
680 return false;
681 }
682 uint num15 = (uint)(source[20] - 48);
683 uint num16 = (uint)(source[21] - 48);
684 uint num17 = (uint)(source[22] - 48);
685 uint num18 = (uint)(source[23] - 48);
686 uint num19 = (uint)(source[24] - 48);
687 uint num20 = (uint)(source[25] - 48);
688 uint num21 = (uint)(source[26] - 48);
689 if (num15 > 9 || num16 > 9 || num17 > 9 || num18 > 9 || num19 > 9 || num20 > 9 || num21 > 9)
690 {
691 value = default(DateTimeOffset);
692 bytesConsumed = 0;
693 kind = DateTimeKind.Unspecified;
694 return false;
695 }
696 int fraction = (int)(num15 * 1000000 + num16 * 100000 + num17 * 10000 + num18 * 1000 + num19 * 100 + num20 * 10 + num21);
697 byte b = (byte)((source.Length > 27) ? source[27] : 0);
698 if (b != 90 && b != 43 && b != 45)
699 {
700 if (!TryCreateDateTimeOffsetInterpretingDataAsLocalTime(year, month, day, hour, minute, second, fraction, out value))
701 {
702 value = default(DateTimeOffset);
703 bytesConsumed = 0;
704 kind = DateTimeKind.Unspecified;
705 return false;
706 }
707 bytesConsumed = 27;
708 kind = DateTimeKind.Unspecified;
709 return true;
710 }
711 if (b == 90)
712 {
713 if (!TryCreateDateTimeOffset(year, month, day, hour, minute, second, fraction, offsetNegative: false, 0, 0, out value))
714 {
715 value = default(DateTimeOffset);
716 bytesConsumed = 0;
717 kind = DateTimeKind.Unspecified;
718 return false;
719 }
720 bytesConsumed = 28;
721 kind = DateTimeKind.Utc;
722 return true;
723 }
724 if (source.Length < 33)
725 {
726 value = default(DateTimeOffset);
727 bytesConsumed = 0;
728 kind = DateTimeKind.Unspecified;
729 return false;
730 }
731 uint num22 = (uint)(source[28] - 48);
732 uint num23 = (uint)(source[29] - 48);
733 if (num22 > 9 || num23 > 9)
734 {
735 value = default(DateTimeOffset);
736 bytesConsumed = 0;
737 kind = DateTimeKind.Unspecified;
738 return false;
739 }
740 int offsetHours = (int)(num22 * 10 + num23);
741 if (source[30] != 58)
742 {
743 value = default(DateTimeOffset);
744 bytesConsumed = 0;
745 kind = DateTimeKind.Unspecified;
746 return false;
747 }
748 uint num24 = (uint)(source[31] - 48);
749 uint num25 = (uint)(source[32] - 48);
750 if (num24 > 9 || num25 > 9)
751 {
752 value = default(DateTimeOffset);
753 bytesConsumed = 0;
754 kind = DateTimeKind.Unspecified;
755 return false;
756 }
757 int offsetMinutes = (int)(num24 * 10 + num25);
758 if (!TryCreateDateTimeOffset(year, month, day, hour, minute, second, fraction, b == 45, offsetHours, offsetMinutes, out value))
759 {
760 value = default(DateTimeOffset);
761 bytesConsumed = 0;
762 kind = DateTimeKind.Unspecified;
763 return false;
764 }
765 bytesConsumed = 33;
766 kind = DateTimeKind.Local;
767 return true;
768 }
769
770 private static bool TryParseDateTimeOffsetR(ReadOnlySpan<byte> source, uint caseFlipXorMask, out DateTimeOffset dateTimeOffset, out int bytesConsumed)
771 {
772 if (source.Length < 29)
773 {
774 bytesConsumed = 0;
775 dateTimeOffset = default(DateTimeOffset);
776 return false;
777 }
778 uint num = source[0] ^ caseFlipXorMask;
779 uint num2 = source[1];
780 uint num3 = source[2];
781 uint num4 = source[3];
782 DayOfWeek dayOfWeek;
783 switch ((num << 24) | (num2 << 16) | (num3 << 8) | num4)
784 {
785 case 1400204844u:
786 dayOfWeek = DayOfWeek.Sunday;
787 break;
788 case 1299148332u:
789 dayOfWeek = DayOfWeek.Monday;
790 break;
791 case 1416979756u:
792 dayOfWeek = DayOfWeek.Tuesday;
793 break;
794 case 1466262572u:
795 dayOfWeek = DayOfWeek.Wednesday;
796 break;
797 case 1416131884u:
798 dayOfWeek = DayOfWeek.Thursday;
799 break;
800 case 1181903148u:
801 dayOfWeek = DayOfWeek.Friday;
802 break;
803 case 1398895660u:
804 dayOfWeek = DayOfWeek.Saturday;
805 break;
806 default:
807 bytesConsumed = 0;
808 dateTimeOffset = default(DateTimeOffset);
809 return false;
810 }
811 if (source[4] != 32)
812 {
813 bytesConsumed = 0;
814 dateTimeOffset = default(DateTimeOffset);
815 return false;
816 }
817 uint num5 = (uint)(source[5] - 48);
818 uint num6 = (uint)(source[6] - 48);
819 if (num5 > 9 || num6 > 9)
820 {
821 bytesConsumed = 0;
822 dateTimeOffset = default(DateTimeOffset);
823 return false;
824 }
825 int day = (int)(num5 * 10 + num6);
826 if (source[7] != 32)
827 {
828 bytesConsumed = 0;
829 dateTimeOffset = default(DateTimeOffset);
830 return false;
831 }
832 uint num7 = source[8] ^ caseFlipXorMask;
833 uint num8 = source[9];
834 uint num9 = source[10];
835 uint num10 = source[11];
836 int month;
837 switch ((num7 << 24) | (num8 << 16) | (num9 << 8) | num10)
838 {
839 case 1247899168u:
840 month = 1;
841 break;
842 case 1181049376u:
843 month = 2;
844 break;
845 case 1298231840u:
846 month = 3;
847 break;
848 case 1097888288u:
849 month = 4;
850 break;
851 case 1298233632u:
852 month = 5;
853 break;
854 case 1249209888u:
855 month = 6;
856 break;
857 case 1249209376u:
858 month = 7;
859 break;
860 case 1098213152u:
861 month = 8;
862 break;
863 case 1399156768u:
864 month = 9;
865 break;
866 case 1331917856u:
867 month = 10;
868 break;
869 case 1315927584u:
870 month = 11;
871 break;
872 case 1147495200u:
873 month = 12;
874 break;
875 default:
876 bytesConsumed = 0;
877 dateTimeOffset = default(DateTimeOffset);
878 return false;
879 }
880 uint num11 = (uint)(source[12] - 48);
881 uint num12 = (uint)(source[13] - 48);
882 uint num13 = (uint)(source[14] - 48);
883 uint num14 = (uint)(source[15] - 48);
884 if (num11 > 9 || num12 > 9 || num13 > 9 || num14 > 9)
885 {
886 bytesConsumed = 0;
887 dateTimeOffset = default(DateTimeOffset);
888 return false;
889 }
890 int year = (int)(num11 * 1000 + num12 * 100 + num13 * 10 + num14);
891 if (source[16] != 32)
892 {
893 bytesConsumed = 0;
894 dateTimeOffset = default(DateTimeOffset);
895 return false;
896 }
897 uint num15 = (uint)(source[17] - 48);
898 uint num16 = (uint)(source[18] - 48);
899 if (num15 > 9 || num16 > 9)
900 {
901 bytesConsumed = 0;
902 dateTimeOffset = default(DateTimeOffset);
903 return false;
904 }
905 int hour = (int)(num15 * 10 + num16);
906 if (source[19] != 58)
907 {
908 bytesConsumed = 0;
909 dateTimeOffset = default(DateTimeOffset);
910 return false;
911 }
912 uint num17 = (uint)(source[20] - 48);
913 uint num18 = (uint)(source[21] - 48);
914 if (num17 > 9 || num18 > 9)
915 {
916 bytesConsumed = 0;
917 dateTimeOffset = default(DateTimeOffset);
918 return false;
919 }
920 int minute = (int)(num17 * 10 + num18);
921 if (source[22] != 58)
922 {
923 bytesConsumed = 0;
924 dateTimeOffset = default(DateTimeOffset);
925 return false;
926 }
927 uint num19 = (uint)(source[23] - 48);
928 uint num20 = (uint)(source[24] - 48);
929 if (num19 > 9 || num20 > 9)
930 {
931 bytesConsumed = 0;
932 dateTimeOffset = default(DateTimeOffset);
933 return false;
934 }
935 int second = (int)(num19 * 10 + num20);
936 uint num21 = source[25];
937 uint num22 = source[26] ^ caseFlipXorMask;
938 uint num23 = source[27] ^ caseFlipXorMask;
939 uint num24 = source[28] ^ caseFlipXorMask;
940 uint num25 = (num21 << 24) | (num22 << 16) | (num23 << 8) | num24;
941 if (num25 != 541543764)
942 {
943 bytesConsumed = 0;
944 dateTimeOffset = default(DateTimeOffset);
945 return false;
946 }
947 if (!TryCreateDateTimeOffset(year, month, day, hour, minute, second, 0, offsetNegative: false, 0, 0, out dateTimeOffset))
948 {
949 bytesConsumed = 0;
950 dateTimeOffset = default(DateTimeOffset);
951 return false;
952 }
953 if (dayOfWeek != dateTimeOffset.DayOfWeek)
954 {
955 bytesConsumed = 0;
956 dateTimeOffset = default(DateTimeOffset);
957 return false;
958 }
959 bytesConsumed = 29;
960 return true;
961 }
962
963 public unsafe static bool TryParse(ReadOnlySpan<byte> source, out decimal value, out int bytesConsumed, char standardFormat = '\0')
964 {
966 switch (standardFormat)
967 {
968 case '\0':
969 case 'E':
970 case 'G':
971 case 'e':
972 case 'g':
973 options = ParseNumberOptions.AllowExponent;
974 break;
975 case 'F':
976 case 'f':
978 break;
979 default:
980 return ParserHelpers.TryParseThrowFormatException<decimal>(out value, out bytesConsumed);
981 }
982 byte* digits = stackalloc byte[31];
983 Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.Decimal, digits, 31);
984 if (!TryParseNumber(source, ref number, out bytesConsumed, options, out var textUsedExponentNotation))
985 {
986 value = default(decimal);
987 return false;
988 }
989 if (!textUsedExponentNotation && (standardFormat == 'E' || standardFormat == 'e'))
990 {
991 value = default(decimal);
992 bytesConsumed = 0;
993 return false;
994 }
995 value = default(decimal);
996 if (!Number.TryNumberToDecimal(ref number, ref value))
997 {
998 value = default(decimal);
999 bytesConsumed = 0;
1000 return false;
1001 }
1002 return true;
1003 }
1004
1005 public unsafe static bool TryParse(ReadOnlySpan<byte> source, out float value, out int bytesConsumed, char standardFormat = '\0')
1006 {
1007 byte* digits = stackalloc byte[114];
1008 Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.FloatingPoint, digits, 114);
1009 if (TryParseNormalAsFloatingPoint(source, ref number, out bytesConsumed, standardFormat))
1010 {
1011 value = Number.NumberToSingle(ref number);
1012 return true;
1013 }
1014 return TryParseAsSpecialFloatingPoint(source, float.PositiveInfinity, float.NegativeInfinity, float.NaN, out value, out bytesConsumed);
1015 }
1016
1017 public unsafe static bool TryParse(ReadOnlySpan<byte> source, out double value, out int bytesConsumed, char standardFormat = '\0')
1018 {
1019 byte* digits = stackalloc byte[769];
1020 Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.FloatingPoint, digits, 769);
1021 if (TryParseNormalAsFloatingPoint(source, ref number, out bytesConsumed, standardFormat))
1022 {
1023 value = Number.NumberToDouble(ref number);
1024 return true;
1025 }
1026 return TryParseAsSpecialFloatingPoint(source, double.PositiveInfinity, double.NegativeInfinity, double.NaN, out value, out bytesConsumed);
1027 }
1028
1029 private static bool TryParseNormalAsFloatingPoint(ReadOnlySpan<byte> source, ref Number.NumberBuffer number, out int bytesConsumed, char standardFormat)
1030 {
1032 switch (standardFormat)
1033 {
1034 case '\0':
1035 case 'E':
1036 case 'G':
1037 case 'e':
1038 case 'g':
1039 options = ParseNumberOptions.AllowExponent;
1040 break;
1041 case 'F':
1042 case 'f':
1044 break;
1045 default:
1046 return ParserHelpers.TryParseThrowFormatException(out bytesConsumed);
1047 }
1048 if (!TryParseNumber(source, ref number, out bytesConsumed, options, out var textUsedExponentNotation))
1049 {
1050 return false;
1051 }
1052 if (!textUsedExponentNotation && (standardFormat == 'E' || standardFormat == 'e'))
1053 {
1054 bytesConsumed = 0;
1055 return false;
1056 }
1057 return true;
1058 }
1059
1060 private static bool TryParseAsSpecialFloatingPoint<T>(ReadOnlySpan<byte> source, T positiveInfinity, T negativeInfinity, T nan, out T value, out int bytesConsumed) where T : struct
1061 {
1062 int num = 0;
1063 int num2 = source.Length;
1064 bool flag = false;
1065 if (num2 >= 4)
1066 {
1067 byte b = source[num];
1068 if (b != 43)
1069 {
1070 if (b != 45)
1071 {
1072 goto IL_002e;
1073 }
1074 flag = true;
1075 }
1076 num++;
1077 num2--;
1078 }
1079 goto IL_002e;
1080 IL_002e:
1081 if (num2 >= 3)
1082 {
1083 if (((source[num] ^ 0x6E) & -33) == 0 && ((source[num + 1] ^ 0x61) & -33) == 0 && ((source[num + 2] ^ 0x6E) & -33) == 0)
1084 {
1085 value = nan;
1086 bytesConsumed = 3 + num;
1087 return true;
1088 }
1089 if (num2 >= 8)
1090 {
1091 int num3 = BinaryPrimitives.ReadInt32LittleEndian(source.Slice(num)) ^ 0x69666E69;
1092 if ((num3 & -538976289) == 0)
1093 {
1094 num3 = BinaryPrimitives.ReadInt32LittleEndian(source.Slice(num + 4)) ^ 0x7974696E;
1095 if ((num3 & -538976289) == 0)
1096 {
1097 value = (flag ? negativeInfinity : positiveInfinity);
1098 bytesConsumed = 8 + num;
1099 return true;
1100 }
1101 }
1102 }
1103 }
1104 value = default(T);
1105 bytesConsumed = 0;
1106 return false;
1107 }
1108
1109 public static bool TryParse(ReadOnlySpan<byte> source, out Guid value, out int bytesConsumed, char standardFormat = '\0')
1110 {
1111 while (true)
1112 {
1113 switch (standardFormat)
1114 {
1115 case '\0':
1116 return TryParseGuidCore(source, out value, out bytesConsumed, 0);
1117 case 'D':
1118 break;
1119 case 'B':
1120 return TryParseGuidCore(source, out value, out bytesConsumed, 32123);
1121 case 'P':
1122 return TryParseGuidCore(source, out value, out bytesConsumed, 10536);
1123 case 'N':
1124 return TryParseGuidN(source, out value, out bytesConsumed);
1125 default:
1126 return ParserHelpers.TryParseThrowFormatException<Guid>(source, out value, out bytesConsumed);
1127 }
1128 standardFormat = '\0';
1129 }
1130 }
1131
1132 private static bool TryParseGuidN(ReadOnlySpan<byte> text, out Guid value, out int bytesConsumed)
1133 {
1134 if (text.Length < 32)
1135 {
1136 value = default(Guid);
1137 bytesConsumed = 0;
1138 return false;
1139 }
1140 if (!TryParseUInt32X(text.Slice(0, 8), out var value2, out var bytesConsumed2) || bytesConsumed2 != 8)
1141 {
1142 value = default(Guid);
1143 bytesConsumed = 0;
1144 return false;
1145 }
1146 if (!TryParseUInt16X(text.Slice(8, 4), out var value3, out bytesConsumed2) || bytesConsumed2 != 4)
1147 {
1148 value = default(Guid);
1149 bytesConsumed = 0;
1150 return false;
1151 }
1152 if (!TryParseUInt16X(text.Slice(12, 4), out var value4, out bytesConsumed2) || bytesConsumed2 != 4)
1153 {
1154 value = default(Guid);
1155 bytesConsumed = 0;
1156 return false;
1157 }
1158 if (!TryParseUInt16X(text.Slice(16, 4), out var value5, out bytesConsumed2) || bytesConsumed2 != 4)
1159 {
1160 value = default(Guid);
1161 bytesConsumed = 0;
1162 return false;
1163 }
1164 if (!TryParseUInt64X(text.Slice(20), out var value6, out bytesConsumed2) || bytesConsumed2 != 12)
1165 {
1166 value = default(Guid);
1167 bytesConsumed = 0;
1168 return false;
1169 }
1170 bytesConsumed = 32;
1171 value = new Guid((int)value2, (short)value3, (short)value4, (byte)(value5 >> 8), (byte)value5, (byte)(value6 >> 40), (byte)(value6 >> 32), (byte)(value6 >> 24), (byte)(value6 >> 16), (byte)(value6 >> 8), (byte)value6);
1172 return true;
1173 }
1174
1175 private static bool TryParseGuidCore(ReadOnlySpan<byte> source, out Guid value, out int bytesConsumed, int ends)
1176 {
1177 int num = 36 + ((ends != 0) ? 2 : 0);
1178 if (source.Length < num)
1179 {
1180 value = default(Guid);
1181 bytesConsumed = 0;
1182 return false;
1183 }
1184 if (ends != 0)
1185 {
1186 if (source[0] != (byte)ends)
1187 {
1188 value = default(Guid);
1189 bytesConsumed = 0;
1190 return false;
1191 }
1192 source = source.Slice(1);
1193 ends >>= 8;
1194 }
1195 if (!TryParseUInt32X(source, out var value2, out var bytesConsumed2))
1196 {
1197 value = default(Guid);
1198 bytesConsumed = 0;
1199 return false;
1200 }
1201 if (bytesConsumed2 != 8)
1202 {
1203 value = default(Guid);
1204 bytesConsumed = 0;
1205 return false;
1206 }
1207 if (source[bytesConsumed2] != 45)
1208 {
1209 value = default(Guid);
1210 bytesConsumed = 0;
1211 return false;
1212 }
1213 source = source.Slice(9);
1214 if (!TryParseUInt16X(source, out var value3, out bytesConsumed2))
1215 {
1216 value = default(Guid);
1217 bytesConsumed = 0;
1218 return false;
1219 }
1220 if (bytesConsumed2 != 4)
1221 {
1222 value = default(Guid);
1223 bytesConsumed = 0;
1224 return false;
1225 }
1226 if (source[bytesConsumed2] != 45)
1227 {
1228 value = default(Guid);
1229 bytesConsumed = 0;
1230 return false;
1231 }
1232 source = source.Slice(5);
1233 if (!TryParseUInt16X(source, out var value4, out bytesConsumed2))
1234 {
1235 value = default(Guid);
1236 bytesConsumed = 0;
1237 return false;
1238 }
1239 if (bytesConsumed2 != 4)
1240 {
1241 value = default(Guid);
1242 bytesConsumed = 0;
1243 return false;
1244 }
1245 if (source[bytesConsumed2] != 45)
1246 {
1247 value = default(Guid);
1248 bytesConsumed = 0;
1249 return false;
1250 }
1251 source = source.Slice(5);
1252 if (!TryParseUInt16X(source, out var value5, out bytesConsumed2))
1253 {
1254 value = default(Guid);
1255 bytesConsumed = 0;
1256 return false;
1257 }
1258 if (bytesConsumed2 != 4)
1259 {
1260 value = default(Guid);
1261 bytesConsumed = 0;
1262 return false;
1263 }
1264 if (source[bytesConsumed2] != 45)
1265 {
1266 value = default(Guid);
1267 bytesConsumed = 0;
1268 return false;
1269 }
1270 source = source.Slice(5);
1271 if (!TryParseUInt64X(source, out var value6, out bytesConsumed2))
1272 {
1273 value = default(Guid);
1274 bytesConsumed = 0;
1275 return false;
1276 }
1277 if (bytesConsumed2 != 12)
1278 {
1279 value = default(Guid);
1280 bytesConsumed = 0;
1281 return false;
1282 }
1283 if (ends != 0 && source[bytesConsumed2] != (byte)ends)
1284 {
1285 value = default(Guid);
1286 bytesConsumed = 0;
1287 return false;
1288 }
1289 bytesConsumed = num;
1290 value = new Guid((int)value2, (short)value3, (short)value4, (byte)(value5 >> 8), (byte)value5, (byte)(value6 >> 40), (byte)(value6 >> 32), (byte)(value6 >> 24), (byte)(value6 >> 16), (byte)(value6 >> 8), (byte)value6);
1291 return true;
1292 }
1293
1294 [CLSCompliant(false)]
1295 public static bool TryParse(ReadOnlySpan<byte> source, out sbyte value, out int bytesConsumed, char standardFormat = '\0')
1296 {
1297 while (standardFormat != 0)
1298 {
1299 switch (standardFormat | 0x20)
1300 {
1301 case 100:
1302 case 103:
1303 break;
1304 case 110:
1305 return TryParseSByteN(source, out value, out bytesConsumed);
1306 case 120:
1307 Unsafe.SkipInit<sbyte>(out value);
1308 return TryParseByteX(source, out Unsafe.As<sbyte, byte>(ref value), out bytesConsumed);
1309 default:
1310 return ParserHelpers.TryParseThrowFormatException<sbyte>(source, out value, out bytesConsumed);
1311 }
1312 standardFormat = '\0';
1313 }
1314 return TryParseSByteD(source, out value, out bytesConsumed);
1315 }
1316
1317 public static bool TryParse(ReadOnlySpan<byte> source, out short value, out int bytesConsumed, char standardFormat = '\0')
1318 {
1319 while (standardFormat != 0)
1320 {
1321 switch (standardFormat | 0x20)
1322 {
1323 case 100:
1324 case 103:
1325 break;
1326 case 110:
1327 return TryParseInt16N(source, out value, out bytesConsumed);
1328 case 120:
1329 Unsafe.SkipInit<short>(out value);
1330 return TryParseUInt16X(source, out Unsafe.As<short, ushort>(ref value), out bytesConsumed);
1331 default:
1332 return ParserHelpers.TryParseThrowFormatException<short>(source, out value, out bytesConsumed);
1333 }
1334 standardFormat = '\0';
1335 }
1336 return TryParseInt16D(source, out value, out bytesConsumed);
1337 }
1338
1339 public static bool TryParse(ReadOnlySpan<byte> source, out int value, out int bytesConsumed, char standardFormat = '\0')
1340 {
1341 while (standardFormat != 0)
1342 {
1343 switch (standardFormat | 0x20)
1344 {
1345 case 100:
1346 case 103:
1347 break;
1348 case 110:
1349 return TryParseInt32N(source, out value, out bytesConsumed);
1350 case 120:
1351 Unsafe.SkipInit<int>(out value);
1352 return TryParseUInt32X(source, out Unsafe.As<int, uint>(ref value), out bytesConsumed);
1353 default:
1354 return ParserHelpers.TryParseThrowFormatException<int>(source, out value, out bytesConsumed);
1355 }
1356 standardFormat = '\0';
1357 }
1358 return TryParseInt32D(source, out value, out bytesConsumed);
1359 }
1360
1361 public static bool TryParse(ReadOnlySpan<byte> source, out long value, out int bytesConsumed, char standardFormat = '\0')
1362 {
1363 while (standardFormat != 0)
1364 {
1365 switch (standardFormat | 0x20)
1366 {
1367 case 100:
1368 case 103:
1369 break;
1370 case 110:
1371 return TryParseInt64N(source, out value, out bytesConsumed);
1372 case 120:
1373 Unsafe.SkipInit<long>(out value);
1374 return TryParseUInt64X(source, out Unsafe.As<long, ulong>(ref value), out bytesConsumed);
1375 default:
1376 return ParserHelpers.TryParseThrowFormatException<long>(source, out value, out bytesConsumed);
1377 }
1378 standardFormat = '\0';
1379 }
1380 return TryParseInt64D(source, out value, out bytesConsumed);
1381 }
1382
1383 private static bool TryParseSByteD(ReadOnlySpan<byte> source, out sbyte value, out int bytesConsumed)
1384 {
1385 int num;
1386 int num2;
1387 int num4;
1388 int num3;
1389 if (source.Length >= 1)
1390 {
1391 num = 1;
1392 num2 = 0;
1393 num3 = source[num2];
1394 if (num3 == 45)
1395 {
1396 num = -1;
1397 num2++;
1398 if ((uint)num2 >= (uint)source.Length)
1399 {
1400 goto IL_0123;
1401 }
1402 num3 = source[num2];
1403 }
1404 else if (num3 == 43)
1405 {
1406 num2++;
1407 if ((uint)num2 >= (uint)source.Length)
1408 {
1409 goto IL_0123;
1410 }
1411 num3 = source[num2];
1412 }
1413 num4 = 0;
1414 if (ParserHelpers.IsDigit(num3))
1415 {
1416 if (num3 != 48)
1417 {
1418 goto IL_009c;
1419 }
1420 while (true)
1421 {
1422 num2++;
1423 if ((uint)num2 >= (uint)source.Length)
1424 {
1425 break;
1426 }
1427 num3 = source[num2];
1428 if (num3 == 48)
1429 {
1430 continue;
1431 }
1432 goto IL_0091;
1433 }
1434 goto IL_012b;
1435 }
1436 }
1437 goto IL_0123;
1438 IL_012b:
1439 bytesConsumed = num2;
1440 value = (sbyte)(num4 * num);
1441 return true;
1442 IL_009c:
1443 num4 = num3 - 48;
1444 num2++;
1445 if ((uint)num2 < (uint)source.Length)
1446 {
1447 num3 = source[num2];
1448 if (ParserHelpers.IsDigit(num3))
1449 {
1450 num2++;
1451 num4 = 10 * num4 + num3 - 48;
1452 if ((uint)num2 < (uint)source.Length)
1453 {
1454 num3 = source[num2];
1455 if (ParserHelpers.IsDigit(num3))
1456 {
1457 num2++;
1458 num4 = num4 * 10 + num3 - 48;
1459 if ((uint)num4 > 127L + (long)((-1 * num + 1) / 2) || ((uint)num2 < (uint)source.Length && ParserHelpers.IsDigit(source[num2])))
1460 {
1461 goto IL_0123;
1462 }
1463 }
1464 }
1465 }
1466 }
1467 goto IL_012b;
1468 IL_0123:
1469 bytesConsumed = 0;
1470 value = 0;
1471 return false;
1472 IL_0091:
1473 if (ParserHelpers.IsDigit(num3))
1474 {
1475 goto IL_009c;
1476 }
1477 goto IL_012b;
1478 }
1479
1480 private static bool TryParseInt16D(ReadOnlySpan<byte> source, out short value, out int bytesConsumed)
1481 {
1482 int num;
1483 int num2;
1484 int num4;
1485 int num3;
1486 if (source.Length >= 1)
1487 {
1488 num = 1;
1489 num2 = 0;
1490 num3 = source[num2];
1491 if (num3 == 45)
1492 {
1493 num = -1;
1494 num2++;
1495 if ((uint)num2 >= (uint)source.Length)
1496 {
1497 goto IL_0186;
1498 }
1499 num3 = source[num2];
1500 }
1501 else if (num3 == 43)
1502 {
1503 num2++;
1504 if ((uint)num2 >= (uint)source.Length)
1505 {
1506 goto IL_0186;
1507 }
1508 num3 = source[num2];
1509 }
1510 num4 = 0;
1511 if (ParserHelpers.IsDigit(num3))
1512 {
1513 if (num3 != 48)
1514 {
1515 goto IL_009c;
1516 }
1517 while (true)
1518 {
1519 num2++;
1520 if ((uint)num2 >= (uint)source.Length)
1521 {
1522 break;
1523 }
1524 num3 = source[num2];
1525 if (num3 == 48)
1526 {
1527 continue;
1528 }
1529 goto IL_0091;
1530 }
1531 goto IL_018e;
1532 }
1533 }
1534 goto IL_0186;
1535 IL_018e:
1536 bytesConsumed = num2;
1537 value = (short)(num4 * num);
1538 return true;
1539 IL_009c:
1540 num4 = num3 - 48;
1541 num2++;
1542 if ((uint)num2 < (uint)source.Length)
1543 {
1544 num3 = source[num2];
1545 if (ParserHelpers.IsDigit(num3))
1546 {
1547 num2++;
1548 num4 = 10 * num4 + num3 - 48;
1549 if ((uint)num2 < (uint)source.Length)
1550 {
1551 num3 = source[num2];
1552 if (ParserHelpers.IsDigit(num3))
1553 {
1554 num2++;
1555 num4 = 10 * num4 + num3 - 48;
1556 if ((uint)num2 < (uint)source.Length)
1557 {
1558 num3 = source[num2];
1559 if (ParserHelpers.IsDigit(num3))
1560 {
1561 num2++;
1562 num4 = 10 * num4 + num3 - 48;
1563 if ((uint)num2 < (uint)source.Length)
1564 {
1565 num3 = source[num2];
1566 if (ParserHelpers.IsDigit(num3))
1567 {
1568 num2++;
1569 num4 = num4 * 10 + num3 - 48;
1570 if ((uint)num4 > 32767L + (long)((-1 * num + 1) / 2) || ((uint)num2 < (uint)source.Length && ParserHelpers.IsDigit(source[num2])))
1571 {
1572 goto IL_0186;
1573 }
1574 }
1575 }
1576 }
1577 }
1578 }
1579 }
1580 }
1581 }
1582 goto IL_018e;
1583 IL_0186:
1584 bytesConsumed = 0;
1585 value = 0;
1586 return false;
1587 IL_0091:
1588 if (ParserHelpers.IsDigit(num3))
1589 {
1590 goto IL_009c;
1591 }
1592 goto IL_018e;
1593 }
1594
1595 private static bool TryParseInt32D(ReadOnlySpan<byte> source, out int value, out int bytesConsumed)
1596 {
1597 int num;
1598 int num2;
1599 int num4;
1600 int num3;
1601 if (source.Length >= 1)
1602 {
1603 num = 1;
1604 num2 = 0;
1605 num3 = source[num2];
1606 if (num3 == 45)
1607 {
1608 num = -1;
1609 num2++;
1610 if ((uint)num2 >= (uint)source.Length)
1611 {
1612 goto IL_0281;
1613 }
1614 num3 = source[num2];
1615 }
1616 else if (num3 == 43)
1617 {
1618 num2++;
1619 if ((uint)num2 >= (uint)source.Length)
1620 {
1621 goto IL_0281;
1622 }
1623 num3 = source[num2];
1624 }
1625 num4 = 0;
1626 if (ParserHelpers.IsDigit(num3))
1627 {
1628 if (num3 != 48)
1629 {
1630 goto IL_009c;
1631 }
1632 while (true)
1633 {
1634 num2++;
1635 if ((uint)num2 >= (uint)source.Length)
1636 {
1637 break;
1638 }
1639 num3 = source[num2];
1640 if (num3 == 48)
1641 {
1642 continue;
1643 }
1644 goto IL_0091;
1645 }
1646 goto IL_0289;
1647 }
1648 }
1649 goto IL_0281;
1650 IL_0289:
1651 bytesConsumed = num2;
1652 value = num4 * num;
1653 return true;
1654 IL_009c:
1655 num4 = num3 - 48;
1656 num2++;
1657 if ((uint)num2 < (uint)source.Length)
1658 {
1659 num3 = source[num2];
1660 if (ParserHelpers.IsDigit(num3))
1661 {
1662 num2++;
1663 num4 = 10 * num4 + num3 - 48;
1664 if ((uint)num2 < (uint)source.Length)
1665 {
1666 num3 = source[num2];
1667 if (ParserHelpers.IsDigit(num3))
1668 {
1669 num2++;
1670 num4 = 10 * num4 + num3 - 48;
1671 if ((uint)num2 < (uint)source.Length)
1672 {
1673 num3 = source[num2];
1674 if (ParserHelpers.IsDigit(num3))
1675 {
1676 num2++;
1677 num4 = 10 * num4 + num3 - 48;
1678 if ((uint)num2 < (uint)source.Length)
1679 {
1680 num3 = source[num2];
1681 if (ParserHelpers.IsDigit(num3))
1682 {
1683 num2++;
1684 num4 = 10 * num4 + num3 - 48;
1685 if ((uint)num2 < (uint)source.Length)
1686 {
1687 num3 = source[num2];
1688 if (ParserHelpers.IsDigit(num3))
1689 {
1690 num2++;
1691 num4 = 10 * num4 + num3 - 48;
1692 if ((uint)num2 < (uint)source.Length)
1693 {
1694 num3 = source[num2];
1695 if (ParserHelpers.IsDigit(num3))
1696 {
1697 num2++;
1698 num4 = 10 * num4 + num3 - 48;
1699 if ((uint)num2 < (uint)source.Length)
1700 {
1701 num3 = source[num2];
1702 if (ParserHelpers.IsDigit(num3))
1703 {
1704 num2++;
1705 num4 = 10 * num4 + num3 - 48;
1706 if ((uint)num2 < (uint)source.Length)
1707 {
1708 num3 = source[num2];
1709 if (ParserHelpers.IsDigit(num3))
1710 {
1711 num2++;
1712 num4 = 10 * num4 + num3 - 48;
1713 if ((uint)num2 < (uint)source.Length)
1714 {
1715 num3 = source[num2];
1716 if (ParserHelpers.IsDigit(num3))
1717 {
1718 num2++;
1719 if (num4 <= 214748364)
1720 {
1721 num4 = num4 * 10 + num3 - 48;
1722 if ((uint)num4 <= 2147483647L + (long)((-1 * num + 1) / 2) && ((uint)num2 >= (uint)source.Length || !ParserHelpers.IsDigit(source[num2])))
1723 {
1724 goto IL_0289;
1725 }
1726 }
1727 goto IL_0281;
1728 }
1729 }
1730 }
1731 }
1732 }
1733 }
1734 }
1735 }
1736 }
1737 }
1738 }
1739 }
1740 }
1741 }
1742 }
1743 }
1744 }
1745 }
1746 goto IL_0289;
1747 IL_0281:
1748 bytesConsumed = 0;
1749 value = 0;
1750 return false;
1751 IL_0091:
1752 if (ParserHelpers.IsDigit(num3))
1753 {
1754 goto IL_009c;
1755 }
1756 goto IL_0289;
1757 }
1758
1759 private static bool TryParseInt64D(ReadOnlySpan<byte> source, out long value, out int bytesConsumed)
1760 {
1761 long num = 0L;
1762 int num2 = 0;
1763 while ((uint)num2 < (uint)source.Length)
1764 {
1765 nuint num3 = (uint)(source[num2] - 48);
1766 if ((uint)num3 > 9)
1767 {
1768 if (num2 != 0)
1769 {
1770 break;
1771 }
1772 num2++;
1773 if ((int)num3 == -3)
1774 {
1775 num--;
1776 }
1777 else if ((int)num3 != -5)
1778 {
1779 break;
1780 }
1781 continue;
1782 }
1783 ulong num4 = num3;
1784 int num5 = 19 + num2;
1785 num2++;
1786 if (source.Length < num5)
1787 {
1788 for (; (uint)num2 < (uint)source.Length; num2++)
1789 {
1790 nuint num6 = (uint)(source[num2] - 48);
1791 if ((uint)num6 > 9)
1792 {
1793 break;
1794 }
1795 num4 = num4 * 10 + num6;
1796 }
1797 }
1798 else
1799 {
1800 while ((uint)num2 < (uint)source.Length)
1801 {
1802 nuint num7 = (uint)(source[num2] - 48);
1803 if ((uint)num7 > 9)
1804 {
1805 break;
1806 }
1807 num2++;
1808 if (num4 < 922337203685477580L)
1809 {
1810 num4 = num4 * 10 + num7;
1811 continue;
1812 }
1813 if (num4 != 922337203685477580L || (int)num7 + (int)num > 7)
1814 {
1815 goto end_IL_0005;
1816 }
1817 num4 = 9223372036854775800uL + (ulong)num7;
1818 }
1819 }
1820 bytesConsumed = num2;
1821 value = (long)(num4 ^ (ulong)num) - num;
1822 return true;
1823 continue;
1824 end_IL_0005:
1825 break;
1826 }
1827 bytesConsumed = 0;
1828 value = 0L;
1829 return false;
1830 }
1831
1832 private static bool TryParseSByteN(ReadOnlySpan<byte> source, out sbyte value, out int bytesConsumed)
1833 {
1834 int num;
1835 int num2;
1836 int num4;
1837 int num3;
1838 if (source.Length >= 1)
1839 {
1840 num = 1;
1841 num2 = 0;
1842 num3 = source[num2];
1843 if (num3 == 45)
1844 {
1845 num = -1;
1846 num2++;
1847 if ((uint)num2 >= (uint)source.Length)
1848 {
1849 goto IL_00f9;
1850 }
1851 num3 = source[num2];
1852 }
1853 else if (num3 == 43)
1854 {
1855 num2++;
1856 if ((uint)num2 >= (uint)source.Length)
1857 {
1858 goto IL_00f9;
1859 }
1860 num3 = source[num2];
1861 }
1862 if (num3 != 46)
1863 {
1864 if (ParserHelpers.IsDigit(num3))
1865 {
1866 num4 = num3 - 48;
1867 while (true)
1868 {
1869 num2++;
1870 if ((uint)num2 >= (uint)source.Length)
1871 {
1872 break;
1873 }
1874 num3 = source[num2];
1875 if (num3 == 44)
1876 {
1877 continue;
1878 }
1879 if (num3 == 46)
1880 {
1881 goto IL_00d4;
1882 }
1883 if (!ParserHelpers.IsDigit(num3))
1884 {
1885 break;
1886 }
1887 num4 = num4 * 10 + num3 - 48;
1888 if (num4 <= 127 + (-1 * num + 1) / 2)
1889 {
1890 continue;
1891 }
1892 goto IL_00f9;
1893 }
1894 goto IL_0101;
1895 }
1896 }
1897 else
1898 {
1899 num4 = 0;
1900 num2++;
1901 if ((uint)num2 < (uint)source.Length && source[num2] == 48)
1902 {
1903 goto IL_00d4;
1904 }
1905 }
1906 }
1907 goto IL_00f9;
1908 IL_00f9:
1909 bytesConsumed = 0;
1910 value = 0;
1911 return false;
1912 IL_00f1:
1913 if (ParserHelpers.IsDigit(num3))
1914 {
1915 goto IL_00f9;
1916 }
1917 goto IL_0101;
1918 IL_00d4:
1919 while (true)
1920 {
1921 num2++;
1922 if ((uint)num2 >= (uint)source.Length)
1923 {
1924 break;
1925 }
1926 num3 = source[num2];
1927 if (num3 == 48)
1928 {
1929 continue;
1930 }
1931 goto IL_00f1;
1932 }
1933 goto IL_0101;
1934 IL_0101:
1935 bytesConsumed = num2;
1936 value = (sbyte)(num4 * num);
1937 return true;
1938 }
1939
1940 private static bool TryParseInt16N(ReadOnlySpan<byte> source, out short value, out int bytesConsumed)
1941 {
1942 int num;
1943 int num2;
1944 int num4;
1945 int num3;
1946 if (source.Length >= 1)
1947 {
1948 num = 1;
1949 num2 = 0;
1950 num3 = source[num2];
1951 if (num3 == 45)
1952 {
1953 num = -1;
1954 num2++;
1955 if ((uint)num2 >= (uint)source.Length)
1956 {
1957 goto IL_00ff;
1958 }
1959 num3 = source[num2];
1960 }
1961 else if (num3 == 43)
1962 {
1963 num2++;
1964 if ((uint)num2 >= (uint)source.Length)
1965 {
1966 goto IL_00ff;
1967 }
1968 num3 = source[num2];
1969 }
1970 if (num3 != 46)
1971 {
1972 if (ParserHelpers.IsDigit(num3))
1973 {
1974 num4 = num3 - 48;
1975 while (true)
1976 {
1977 num2++;
1978 if ((uint)num2 >= (uint)source.Length)
1979 {
1980 break;
1981 }
1982 num3 = source[num2];
1983 if (num3 == 44)
1984 {
1985 continue;
1986 }
1987 if (num3 == 46)
1988 {
1989 goto IL_00da;
1990 }
1991 if (!ParserHelpers.IsDigit(num3))
1992 {
1993 break;
1994 }
1995 num4 = num4 * 10 + num3 - 48;
1996 if (num4 <= 32767 + (-1 * num + 1) / 2)
1997 {
1998 continue;
1999 }
2000 goto IL_00ff;
2001 }
2002 goto IL_0107;
2003 }
2004 }
2005 else
2006 {
2007 num4 = 0;
2008 num2++;
2009 if ((uint)num2 < (uint)source.Length && source[num2] == 48)
2010 {
2011 goto IL_00da;
2012 }
2013 }
2014 }
2015 goto IL_00ff;
2016 IL_00ff:
2017 bytesConsumed = 0;
2018 value = 0;
2019 return false;
2020 IL_00f7:
2021 if (ParserHelpers.IsDigit(num3))
2022 {
2023 goto IL_00ff;
2024 }
2025 goto IL_0107;
2026 IL_00da:
2027 while (true)
2028 {
2029 num2++;
2030 if ((uint)num2 >= (uint)source.Length)
2031 {
2032 break;
2033 }
2034 num3 = source[num2];
2035 if (num3 == 48)
2036 {
2037 continue;
2038 }
2039 goto IL_00f7;
2040 }
2041 goto IL_0107;
2042 IL_0107:
2043 bytesConsumed = num2;
2044 value = (short)(num4 * num);
2045 return true;
2046 }
2047
2048 private static bool TryParseInt32N(ReadOnlySpan<byte> source, out int value, out int bytesConsumed)
2049 {
2050 int num;
2051 int num2;
2052 int num4;
2053 int num3;
2054 if (source.Length >= 1)
2055 {
2056 num = 1;
2057 num2 = 0;
2058 num3 = source[num2];
2059 if (num3 == 45)
2060 {
2061 num = -1;
2062 num2++;
2063 if ((uint)num2 >= (uint)source.Length)
2064 {
2065 goto IL_010a;
2066 }
2067 num3 = source[num2];
2068 }
2069 else if (num3 == 43)
2070 {
2071 num2++;
2072 if ((uint)num2 >= (uint)source.Length)
2073 {
2074 goto IL_010a;
2075 }
2076 num3 = source[num2];
2077 }
2078 if (num3 != 46)
2079 {
2080 if (ParserHelpers.IsDigit(num3))
2081 {
2082 num4 = num3 - 48;
2083 while (true)
2084 {
2085 num2++;
2086 if ((uint)num2 >= (uint)source.Length)
2087 {
2088 break;
2089 }
2090 num3 = source[num2];
2091 if (num3 == 44)
2092 {
2093 continue;
2094 }
2095 if (num3 == 46)
2096 {
2097 goto IL_00e5;
2098 }
2099 if (!ParserHelpers.IsDigit(num3))
2100 {
2101 break;
2102 }
2103 if ((uint)num4 <= 214748364u)
2104 {
2105 num4 = num4 * 10 + num3 - 48;
2106 if ((uint)num4 <= 2147483647L + (long)((-1 * num + 1) / 2))
2107 {
2108 continue;
2109 }
2110 }
2111 goto IL_010a;
2112 }
2113 goto IL_0112;
2114 }
2115 }
2116 else
2117 {
2118 num4 = 0;
2119 num2++;
2120 if ((uint)num2 < (uint)source.Length && source[num2] == 48)
2121 {
2122 goto IL_00e5;
2123 }
2124 }
2125 }
2126 goto IL_010a;
2127 IL_010a:
2128 bytesConsumed = 0;
2129 value = 0;
2130 return false;
2131 IL_0102:
2132 if (ParserHelpers.IsDigit(num3))
2133 {
2134 goto IL_010a;
2135 }
2136 goto IL_0112;
2137 IL_00e5:
2138 while (true)
2139 {
2140 num2++;
2141 if ((uint)num2 >= (uint)source.Length)
2142 {
2143 break;
2144 }
2145 num3 = source[num2];
2146 if (num3 == 48)
2147 {
2148 continue;
2149 }
2150 goto IL_0102;
2151 }
2152 goto IL_0112;
2153 IL_0112:
2154 bytesConsumed = num2;
2155 value = num4 * num;
2156 return true;
2157 }
2158
2159 private static bool TryParseInt64N(ReadOnlySpan<byte> source, out long value, out int bytesConsumed)
2160 {
2161 int num;
2162 int num2;
2163 long num4;
2164 int num3;
2165 if (source.Length >= 1)
2166 {
2167 num = 1;
2168 num2 = 0;
2169 num3 = source[num2];
2170 if (num3 == 45)
2171 {
2172 num = -1;
2173 num2++;
2174 if ((uint)num2 >= (uint)source.Length)
2175 {
2176 goto IL_0115;
2177 }
2178 num3 = source[num2];
2179 }
2180 else if (num3 == 43)
2181 {
2182 num2++;
2183 if ((uint)num2 >= (uint)source.Length)
2184 {
2185 goto IL_0115;
2186 }
2187 num3 = source[num2];
2188 }
2189 if (num3 != 46)
2190 {
2191 if (ParserHelpers.IsDigit(num3))
2192 {
2193 num4 = num3 - 48;
2194 while (true)
2195 {
2196 num2++;
2197 if ((uint)num2 >= (uint)source.Length)
2198 {
2199 break;
2200 }
2201 num3 = source[num2];
2202 if (num3 == 44)
2203 {
2204 continue;
2205 }
2206 if (num3 == 46)
2207 {
2208 goto IL_00f0;
2209 }
2210 if (!ParserHelpers.IsDigit(num3))
2211 {
2212 break;
2213 }
2214 if ((ulong)num4 <= 922337203685477580uL)
2215 {
2216 num4 = num4 * 10 + num3 - 48;
2217 if ((ulong)num4 <= (ulong)(long.MaxValue + (-1 * num + 1) / 2))
2218 {
2219 continue;
2220 }
2221 }
2222 goto IL_0115;
2223 }
2224 goto IL_011e;
2225 }
2226 }
2227 else
2228 {
2229 num4 = 0L;
2230 num2++;
2231 if ((uint)num2 < (uint)source.Length && source[num2] == 48)
2232 {
2233 goto IL_00f0;
2234 }
2235 }
2236 }
2237 goto IL_0115;
2238 IL_0115:
2239 bytesConsumed = 0;
2240 value = 0L;
2241 return false;
2242 IL_010d:
2243 if (ParserHelpers.IsDigit(num3))
2244 {
2245 goto IL_0115;
2246 }
2247 goto IL_011e;
2248 IL_00f0:
2249 while (true)
2250 {
2251 num2++;
2252 if ((uint)num2 >= (uint)source.Length)
2253 {
2254 break;
2255 }
2256 num3 = source[num2];
2257 if (num3 == 48)
2258 {
2259 continue;
2260 }
2261 goto IL_010d;
2262 }
2263 goto IL_011e;
2264 IL_011e:
2265 bytesConsumed = num2;
2266 value = num4 * num;
2267 return true;
2268 }
2269
2270 public static bool TryParse(ReadOnlySpan<byte> source, out byte value, out int bytesConsumed, char standardFormat = '\0')
2271 {
2272 while (standardFormat != 0)
2273 {
2274 switch (standardFormat | 0x20)
2275 {
2276 case 100:
2277 case 103:
2278 break;
2279 case 110:
2280 return TryParseByteN(source, out value, out bytesConsumed);
2281 case 120:
2282 return TryParseByteX(source, out value, out bytesConsumed);
2283 default:
2284 return ParserHelpers.TryParseThrowFormatException<byte>(source, out value, out bytesConsumed);
2285 }
2286 standardFormat = '\0';
2287 }
2288 return TryParseByteD(source, out value, out bytesConsumed);
2289 }
2290
2291 [CLSCompliant(false)]
2292 public static bool TryParse(ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed, char standardFormat = '\0')
2293 {
2294 while (standardFormat != 0)
2295 {
2296 switch (standardFormat | 0x20)
2297 {
2298 case 100:
2299 case 103:
2300 break;
2301 case 110:
2302 return TryParseUInt16N(source, out value, out bytesConsumed);
2303 case 120:
2304 return TryParseUInt16X(source, out value, out bytesConsumed);
2305 default:
2306 return ParserHelpers.TryParseThrowFormatException<ushort>(source, out value, out bytesConsumed);
2307 }
2308 standardFormat = '\0';
2309 }
2310 return TryParseUInt16D(source, out value, out bytesConsumed);
2311 }
2312
2313 [CLSCompliant(false)]
2314 public static bool TryParse(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed, char standardFormat = '\0')
2315 {
2316 while (standardFormat != 0)
2317 {
2318 switch (standardFormat | 0x20)
2319 {
2320 case 100:
2321 case 103:
2322 break;
2323 case 110:
2324 return TryParseUInt32N(source, out value, out bytesConsumed);
2325 case 120:
2326 return TryParseUInt32X(source, out value, out bytesConsumed);
2327 default:
2328 return ParserHelpers.TryParseThrowFormatException<uint>(source, out value, out bytesConsumed);
2329 }
2330 standardFormat = '\0';
2331 }
2332 return TryParseUInt32D(source, out value, out bytesConsumed);
2333 }
2334
2335 [CLSCompliant(false)]
2336 public static bool TryParse(ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed, char standardFormat = '\0')
2337 {
2338 while (standardFormat != 0)
2339 {
2340 switch (standardFormat | 0x20)
2341 {
2342 case 100:
2343 case 103:
2344 break;
2345 case 110:
2346 return TryParseUInt64N(source, out value, out bytesConsumed);
2347 case 120:
2348 return TryParseUInt64X(source, out value, out bytesConsumed);
2349 default:
2350 return ParserHelpers.TryParseThrowFormatException<ulong>(source, out value, out bytesConsumed);
2351 }
2352 standardFormat = '\0';
2353 }
2354 return TryParseUInt64D(source, out value, out bytesConsumed);
2355 }
2356
2357 private static bool TryParseByteD(ReadOnlySpan<byte> source, out byte value, out int bytesConsumed)
2358 {
2359 int num;
2360 int num3;
2361 int num2;
2362 if (source.Length >= 1)
2363 {
2364 num = 0;
2365 num2 = source[num];
2366 num3 = 0;
2367 if (ParserHelpers.IsDigit(num2))
2368 {
2369 if (num2 != 48)
2370 {
2371 goto IL_0056;
2372 }
2373 while (true)
2374 {
2375 num++;
2376 if ((uint)num >= (uint)source.Length)
2377 {
2378 break;
2379 }
2380 num2 = source[num];
2381 if (num2 == 48)
2382 {
2383 continue;
2384 }
2385 goto IL_004b;
2386 }
2387 goto IL_00dd;
2388 }
2389 }
2390 goto IL_00d5;
2391 IL_004b:
2392 if (ParserHelpers.IsDigit(num2))
2393 {
2394 goto IL_0056;
2395 }
2396 goto IL_00dd;
2397 IL_0056:
2398 num3 = num2 - 48;
2399 num++;
2400 if ((uint)num < (uint)source.Length)
2401 {
2402 num2 = source[num];
2403 if (ParserHelpers.IsDigit(num2))
2404 {
2405 num++;
2406 num3 = 10 * num3 + num2 - 48;
2407 if ((uint)num < (uint)source.Length)
2408 {
2409 num2 = source[num];
2410 if (ParserHelpers.IsDigit(num2))
2411 {
2412 num++;
2413 num3 = num3 * 10 + num2 - 48;
2414 if ((uint)num3 > 255u || ((uint)num < (uint)source.Length && ParserHelpers.IsDigit(source[num])))
2415 {
2416 goto IL_00d5;
2417 }
2418 }
2419 }
2420 }
2421 }
2422 goto IL_00dd;
2423 IL_00dd:
2424 bytesConsumed = num;
2425 value = (byte)num3;
2426 return true;
2427 IL_00d5:
2428 bytesConsumed = 0;
2429 value = 0;
2430 return false;
2431 }
2432
2433 private static bool TryParseUInt16D(ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed)
2434 {
2435 int num;
2436 int num3;
2437 int num2;
2438 if (source.Length >= 1)
2439 {
2440 num = 0;
2441 num2 = source[num];
2442 num3 = 0;
2443 if (ParserHelpers.IsDigit(num2))
2444 {
2445 if (num2 != 48)
2446 {
2447 goto IL_0056;
2448 }
2449 while (true)
2450 {
2451 num++;
2452 if ((uint)num >= (uint)source.Length)
2453 {
2454 break;
2455 }
2456 num2 = source[num];
2457 if (num2 == 48)
2458 {
2459 continue;
2460 }
2461 goto IL_004b;
2462 }
2463 goto IL_013d;
2464 }
2465 }
2466 goto IL_0135;
2467 IL_004b:
2468 if (ParserHelpers.IsDigit(num2))
2469 {
2470 goto IL_0056;
2471 }
2472 goto IL_013d;
2473 IL_0056:
2474 num3 = num2 - 48;
2475 num++;
2476 if ((uint)num < (uint)source.Length)
2477 {
2478 num2 = source[num];
2479 if (ParserHelpers.IsDigit(num2))
2480 {
2481 num++;
2482 num3 = 10 * num3 + num2 - 48;
2483 if ((uint)num < (uint)source.Length)
2484 {
2485 num2 = source[num];
2486 if (ParserHelpers.IsDigit(num2))
2487 {
2488 num++;
2489 num3 = 10 * num3 + num2 - 48;
2490 if ((uint)num < (uint)source.Length)
2491 {
2492 num2 = source[num];
2493 if (ParserHelpers.IsDigit(num2))
2494 {
2495 num++;
2496 num3 = 10 * num3 + num2 - 48;
2497 if ((uint)num < (uint)source.Length)
2498 {
2499 num2 = source[num];
2500 if (ParserHelpers.IsDigit(num2))
2501 {
2502 num++;
2503 num3 = num3 * 10 + num2 - 48;
2504 if ((uint)num3 > 65535u || ((uint)num < (uint)source.Length && ParserHelpers.IsDigit(source[num])))
2505 {
2506 goto IL_0135;
2507 }
2508 }
2509 }
2510 }
2511 }
2512 }
2513 }
2514 }
2515 }
2516 goto IL_013d;
2517 IL_013d:
2518 bytesConsumed = num;
2519 value = (ushort)num3;
2520 return true;
2521 IL_0135:
2522 bytesConsumed = 0;
2523 value = 0;
2524 return false;
2525 }
2526
2527 private static bool TryParseUInt32D(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed)
2528 {
2529 int num;
2530 int num3;
2531 int num2;
2532 if (source.Length >= 1)
2533 {
2534 num = 0;
2535 num2 = source[num];
2536 num3 = 0;
2537 if (ParserHelpers.IsDigit(num2))
2538 {
2539 if (num2 != 48)
2540 {
2541 goto IL_0056;
2542 }
2543 while (true)
2544 {
2545 num++;
2546 if ((uint)num >= (uint)source.Length)
2547 {
2548 break;
2549 }
2550 num2 = source[num];
2551 if (num2 == 48)
2552 {
2553 continue;
2554 }
2555 goto IL_004b;
2556 }
2557 goto IL_023d;
2558 }
2559 }
2560 goto IL_0235;
2561 IL_004b:
2562 if (ParserHelpers.IsDigit(num2))
2563 {
2564 goto IL_0056;
2565 }
2566 goto IL_023d;
2567 IL_0056:
2568 num3 = num2 - 48;
2569 num++;
2570 if ((uint)num < (uint)source.Length)
2571 {
2572 num2 = source[num];
2573 if (ParserHelpers.IsDigit(num2))
2574 {
2575 num++;
2576 num3 = 10 * num3 + num2 - 48;
2577 if ((uint)num < (uint)source.Length)
2578 {
2579 num2 = source[num];
2580 if (ParserHelpers.IsDigit(num2))
2581 {
2582 num++;
2583 num3 = 10 * num3 + num2 - 48;
2584 if ((uint)num < (uint)source.Length)
2585 {
2586 num2 = source[num];
2587 if (ParserHelpers.IsDigit(num2))
2588 {
2589 num++;
2590 num3 = 10 * num3 + num2 - 48;
2591 if ((uint)num < (uint)source.Length)
2592 {
2593 num2 = source[num];
2594 if (ParserHelpers.IsDigit(num2))
2595 {
2596 num++;
2597 num3 = 10 * num3 + num2 - 48;
2598 if ((uint)num < (uint)source.Length)
2599 {
2600 num2 = source[num];
2601 if (ParserHelpers.IsDigit(num2))
2602 {
2603 num++;
2604 num3 = 10 * num3 + num2 - 48;
2605 if ((uint)num < (uint)source.Length)
2606 {
2607 num2 = source[num];
2608 if (ParserHelpers.IsDigit(num2))
2609 {
2610 num++;
2611 num3 = 10 * num3 + num2 - 48;
2612 if ((uint)num < (uint)source.Length)
2613 {
2614 num2 = source[num];
2615 if (ParserHelpers.IsDigit(num2))
2616 {
2617 num++;
2618 num3 = 10 * num3 + num2 - 48;
2619 if ((uint)num < (uint)source.Length)
2620 {
2621 num2 = source[num];
2622 if (ParserHelpers.IsDigit(num2))
2623 {
2624 num++;
2625 num3 = 10 * num3 + num2 - 48;
2626 if ((uint)num < (uint)source.Length)
2627 {
2628 num2 = source[num];
2629 if (ParserHelpers.IsDigit(num2))
2630 {
2631 num++;
2632 if ((uint)num3 <= 429496729u && (num3 != 429496729 || num2 <= 53))
2633 {
2634 num3 = num3 * 10 + num2 - 48;
2635 if ((uint)num >= (uint)source.Length || !ParserHelpers.IsDigit(source[num]))
2636 {
2637 goto IL_023d;
2638 }
2639 }
2640 goto IL_0235;
2641 }
2642 }
2643 }
2644 }
2645 }
2646 }
2647 }
2648 }
2649 }
2650 }
2651 }
2652 }
2653 }
2654 }
2655 }
2656 }
2657 }
2658 }
2659 goto IL_023d;
2660 IL_023d:
2661 bytesConsumed = num;
2662 value = (uint)num3;
2663 return true;
2664 IL_0235:
2665 bytesConsumed = 0;
2666 value = 0u;
2667 return false;
2668 }
2669
2670 private static bool TryParseUInt64D(ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed)
2671 {
2672 if (!source.IsEmpty)
2673 {
2674 nuint num = (uint)(source[0] - 48);
2675 if ((uint)num <= 9)
2676 {
2677 ulong num2 = num;
2678 int i = 1;
2679 if (source.Length < 20)
2680 {
2681 for (; (uint)i < (uint)source.Length; i++)
2682 {
2683 nuint num3 = (uint)(source[i] - 48);
2684 if ((uint)num3 > 9)
2685 {
2686 break;
2687 }
2688 num2 = num2 * 10 + num3;
2689 }
2690 }
2691 else
2692 {
2693 while ((uint)i < (uint)source.Length)
2694 {
2695 nuint num4 = (uint)(source[i] - 48);
2696 if ((uint)num4 > 9)
2697 {
2698 break;
2699 }
2700 i++;
2701 if (num2 < 1844674407370955161L)
2702 {
2703 num2 = num2 * 10 + num4;
2704 continue;
2705 }
2706 if (num2 == 1844674407370955161L && (uint)num4 <= 5)
2707 {
2708 num2 = 18446744073709551610uL + (ulong)num4;
2709 continue;
2710 }
2711 goto IL_00c0;
2712 }
2713 }
2714 bytesConsumed = i;
2715 value = num2;
2716 return true;
2717 }
2718 }
2719 goto IL_00c0;
2720 IL_00c0:
2721 bytesConsumed = 0;
2722 value = 0uL;
2723 return false;
2724 }
2725
2726 private static bool TryParseByteN(ReadOnlySpan<byte> source, out byte value, out int bytesConsumed)
2727 {
2728 int num;
2729 int num3;
2730 int num2;
2731 if (source.Length >= 1)
2732 {
2733 num = 0;
2734 num2 = source[num];
2735 if (num2 == 43)
2736 {
2737 num++;
2738 if ((uint)num >= (uint)source.Length)
2739 {
2740 goto IL_00ce;
2741 }
2742 num2 = source[num];
2743 }
2744 if (num2 != 46)
2745 {
2746 if (ParserHelpers.IsDigit(num2))
2747 {
2748 num3 = num2 - 48;
2749 while (true)
2750 {
2751 num++;
2752 if ((uint)num >= (uint)source.Length)
2753 {
2754 break;
2755 }
2756 num2 = source[num];
2757 if (num2 == 44)
2758 {
2759 continue;
2760 }
2761 if (num2 == 46)
2762 {
2763 goto IL_00a9;
2764 }
2765 if (!ParserHelpers.IsDigit(num2))
2766 {
2767 break;
2768 }
2769 num3 = num3 * 10 + num2 - 48;
2770 if (num3 <= 255)
2771 {
2772 continue;
2773 }
2774 goto IL_00ce;
2775 }
2776 goto IL_00d6;
2777 }
2778 }
2779 else
2780 {
2781 num3 = 0;
2782 num++;
2783 if ((uint)num < (uint)source.Length && source[num] == 48)
2784 {
2785 goto IL_00a9;
2786 }
2787 }
2788 }
2789 goto IL_00ce;
2790 IL_00c6:
2791 if (ParserHelpers.IsDigit(num2))
2792 {
2793 goto IL_00ce;
2794 }
2795 goto IL_00d6;
2796 IL_00a9:
2797 while (true)
2798 {
2799 num++;
2800 if ((uint)num >= (uint)source.Length)
2801 {
2802 break;
2803 }
2804 num2 = source[num];
2805 if (num2 == 48)
2806 {
2807 continue;
2808 }
2809 goto IL_00c6;
2810 }
2811 goto IL_00d6;
2812 IL_00d6:
2813 bytesConsumed = num;
2814 value = (byte)num3;
2815 return true;
2816 IL_00ce:
2817 bytesConsumed = 0;
2818 value = 0;
2819 return false;
2820 }
2821
2822 private static bool TryParseUInt16N(ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed)
2823 {
2824 int num;
2825 int num3;
2826 int num2;
2827 if (source.Length >= 1)
2828 {
2829 num = 0;
2830 num2 = source[num];
2831 if (num2 == 43)
2832 {
2833 num++;
2834 if ((uint)num >= (uint)source.Length)
2835 {
2836 goto IL_00ce;
2837 }
2838 num2 = source[num];
2839 }
2840 if (num2 != 46)
2841 {
2842 if (ParserHelpers.IsDigit(num2))
2843 {
2844 num3 = num2 - 48;
2845 while (true)
2846 {
2847 num++;
2848 if ((uint)num >= (uint)source.Length)
2849 {
2850 break;
2851 }
2852 num2 = source[num];
2853 if (num2 == 44)
2854 {
2855 continue;
2856 }
2857 if (num2 == 46)
2858 {
2859 goto IL_00a9;
2860 }
2861 if (!ParserHelpers.IsDigit(num2))
2862 {
2863 break;
2864 }
2865 num3 = num3 * 10 + num2 - 48;
2866 if (num3 <= 65535)
2867 {
2868 continue;
2869 }
2870 goto IL_00ce;
2871 }
2872 goto IL_00d6;
2873 }
2874 }
2875 else
2876 {
2877 num3 = 0;
2878 num++;
2879 if ((uint)num < (uint)source.Length && source[num] == 48)
2880 {
2881 goto IL_00a9;
2882 }
2883 }
2884 }
2885 goto IL_00ce;
2886 IL_00c6:
2887 if (ParserHelpers.IsDigit(num2))
2888 {
2889 goto IL_00ce;
2890 }
2891 goto IL_00d6;
2892 IL_00a9:
2893 while (true)
2894 {
2895 num++;
2896 if ((uint)num >= (uint)source.Length)
2897 {
2898 break;
2899 }
2900 num2 = source[num];
2901 if (num2 == 48)
2902 {
2903 continue;
2904 }
2905 goto IL_00c6;
2906 }
2907 goto IL_00d6;
2908 IL_00d6:
2909 bytesConsumed = num;
2910 value = (ushort)num3;
2911 return true;
2912 IL_00ce:
2913 bytesConsumed = 0;
2914 value = 0;
2915 return false;
2916 }
2917
2918 private static bool TryParseUInt32N(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed)
2919 {
2920 int num;
2921 int num3;
2922 int num2;
2923 if (source.Length >= 1)
2924 {
2925 num = 0;
2926 num2 = source[num];
2927 if (num2 == 43)
2928 {
2929 num++;
2930 if ((uint)num >= (uint)source.Length)
2931 {
2932 goto IL_00de;
2933 }
2934 num2 = source[num];
2935 }
2936 if (num2 != 46)
2937 {
2938 if (ParserHelpers.IsDigit(num2))
2939 {
2940 num3 = num2 - 48;
2941 while (true)
2942 {
2943 num++;
2944 if ((uint)num >= (uint)source.Length)
2945 {
2946 break;
2947 }
2948 num2 = source[num];
2949 if (num2 == 44)
2950 {
2951 continue;
2952 }
2953 if (num2 == 46)
2954 {
2955 goto IL_00b9;
2956 }
2957 if (!ParserHelpers.IsDigit(num2))
2958 {
2959 break;
2960 }
2961 if ((uint)num3 <= 429496729u && (num3 != 429496729 || num2 <= 53))
2962 {
2963 num3 = num3 * 10 + num2 - 48;
2964 continue;
2965 }
2966 goto IL_00de;
2967 }
2968 goto IL_00e6;
2969 }
2970 }
2971 else
2972 {
2973 num3 = 0;
2974 num++;
2975 if ((uint)num < (uint)source.Length && source[num] == 48)
2976 {
2977 goto IL_00b9;
2978 }
2979 }
2980 }
2981 goto IL_00de;
2982 IL_00de:
2983 bytesConsumed = 0;
2984 value = 0u;
2985 return false;
2986 IL_00b9:
2987 while (true)
2988 {
2989 num++;
2990 if ((uint)num >= (uint)source.Length)
2991 {
2992 break;
2993 }
2994 num2 = source[num];
2995 if (num2 == 48)
2996 {
2997 continue;
2998 }
2999 goto IL_00d6;
3000 }
3001 goto IL_00e6;
3002 IL_00e6:
3003 bytesConsumed = num;
3004 value = (uint)num3;
3005 return true;
3006 IL_00d6:
3007 if (ParserHelpers.IsDigit(num2))
3008 {
3009 goto IL_00de;
3010 }
3011 goto IL_00e6;
3012 }
3013
3014 private static bool TryParseUInt64N(ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed)
3015 {
3016 int num;
3017 long num3;
3018 int num2;
3019 if (source.Length >= 1)
3020 {
3021 num = 0;
3022 num2 = source[num];
3023 if (num2 == 43)
3024 {
3025 num++;
3026 if ((uint)num >= (uint)source.Length)
3027 {
3028 goto IL_00eb;
3029 }
3030 num2 = source[num];
3031 }
3032 if (num2 != 46)
3033 {
3034 if (ParserHelpers.IsDigit(num2))
3035 {
3036 num3 = num2 - 48;
3037 while (true)
3038 {
3039 num++;
3040 if ((uint)num >= (uint)source.Length)
3041 {
3042 break;
3043 }
3044 num2 = source[num];
3045 if (num2 == 44)
3046 {
3047 continue;
3048 }
3049 if (num2 == 46)
3050 {
3051 goto IL_00c6;
3052 }
3053 if (!ParserHelpers.IsDigit(num2))
3054 {
3055 break;
3056 }
3057 if ((ulong)num3 <= 1844674407370955161uL && (num3 != 1844674407370955161L || num2 <= 53))
3058 {
3059 num3 = num3 * 10 + num2 - 48;
3060 continue;
3061 }
3062 goto IL_00eb;
3063 }
3064 goto IL_00f4;
3065 }
3066 }
3067 else
3068 {
3069 num3 = 0L;
3070 num++;
3071 if ((uint)num < (uint)source.Length && source[num] == 48)
3072 {
3073 goto IL_00c6;
3074 }
3075 }
3076 }
3077 goto IL_00eb;
3078 IL_00eb:
3079 bytesConsumed = 0;
3080 value = 0uL;
3081 return false;
3082 IL_00c6:
3083 while (true)
3084 {
3085 num++;
3086 if ((uint)num >= (uint)source.Length)
3087 {
3088 break;
3089 }
3090 num2 = source[num];
3091 if (num2 == 48)
3092 {
3093 continue;
3094 }
3095 goto IL_00e3;
3096 }
3097 goto IL_00f4;
3098 IL_00f4:
3099 bytesConsumed = num;
3100 value = (ulong)num3;
3101 return true;
3102 IL_00e3:
3103 if (ParserHelpers.IsDigit(num2))
3104 {
3105 goto IL_00eb;
3106 }
3107 goto IL_00f4;
3108 }
3109
3110 private static bool TryParseByteX(ReadOnlySpan<byte> source, out byte value, out int bytesConsumed)
3111 {
3112 if (source.Length < 1)
3113 {
3114 bytesConsumed = 0;
3115 value = 0;
3116 return false;
3117 }
3119 byte index = source[0];
3120 byte b = charToHexLookup[index];
3121 if (b == byte.MaxValue)
3122 {
3123 bytesConsumed = 0;
3124 value = 0;
3125 return false;
3126 }
3127 uint num = b;
3128 if (source.Length <= 2)
3129 {
3130 for (int i = 1; i < source.Length; i++)
3131 {
3132 index = source[i];
3133 b = charToHexLookup[index];
3134 if (b == byte.MaxValue)
3135 {
3136 bytesConsumed = i;
3137 value = (byte)num;
3138 return true;
3139 }
3140 num = (num << 4) + b;
3141 }
3142 }
3143 else
3144 {
3145 for (int j = 1; j < 2; j++)
3146 {
3147 index = source[j];
3148 b = charToHexLookup[index];
3149 if (b == byte.MaxValue)
3150 {
3151 bytesConsumed = j;
3152 value = (byte)num;
3153 return true;
3154 }
3155 num = (num << 4) + b;
3156 }
3157 for (int k = 2; k < source.Length; k++)
3158 {
3159 index = source[k];
3160 b = charToHexLookup[index];
3161 if (b == byte.MaxValue)
3162 {
3163 bytesConsumed = k;
3164 value = (byte)num;
3165 return true;
3166 }
3167 if (num > 15)
3168 {
3169 bytesConsumed = 0;
3170 value = 0;
3171 return false;
3172 }
3173 num = (num << 4) + b;
3174 }
3175 }
3176 bytesConsumed = source.Length;
3177 value = (byte)num;
3178 return true;
3179 }
3180
3181 private static bool TryParseUInt16X(ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed)
3182 {
3183 if (source.Length < 1)
3184 {
3185 bytesConsumed = 0;
3186 value = 0;
3187 return false;
3188 }
3190 byte index = source[0];
3191 byte b = charToHexLookup[index];
3192 if (b == byte.MaxValue)
3193 {
3194 bytesConsumed = 0;
3195 value = 0;
3196 return false;
3197 }
3198 uint num = b;
3199 if (source.Length <= 4)
3200 {
3201 for (int i = 1; i < source.Length; i++)
3202 {
3203 index = source[i];
3204 b = charToHexLookup[index];
3205 if (b == byte.MaxValue)
3206 {
3207 bytesConsumed = i;
3208 value = (ushort)num;
3209 return true;
3210 }
3211 num = (num << 4) + b;
3212 }
3213 }
3214 else
3215 {
3216 for (int j = 1; j < 4; j++)
3217 {
3218 index = source[j];
3219 b = charToHexLookup[index];
3220 if (b == byte.MaxValue)
3221 {
3222 bytesConsumed = j;
3223 value = (ushort)num;
3224 return true;
3225 }
3226 num = (num << 4) + b;
3227 }
3228 for (int k = 4; k < source.Length; k++)
3229 {
3230 index = source[k];
3231 b = charToHexLookup[index];
3232 if (b == byte.MaxValue)
3233 {
3234 bytesConsumed = k;
3235 value = (ushort)num;
3236 return true;
3237 }
3238 if (num > 4095)
3239 {
3240 bytesConsumed = 0;
3241 value = 0;
3242 return false;
3243 }
3244 num = (num << 4) + b;
3245 }
3246 }
3247 bytesConsumed = source.Length;
3248 value = (ushort)num;
3249 return true;
3250 }
3251
3252 private static bool TryParseUInt32X(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed)
3253 {
3254 if (source.Length < 1)
3255 {
3256 bytesConsumed = 0;
3257 value = 0u;
3258 return false;
3259 }
3261 byte index = source[0];
3262 byte b = charToHexLookup[index];
3263 if (b == byte.MaxValue)
3264 {
3265 bytesConsumed = 0;
3266 value = 0u;
3267 return false;
3268 }
3269 uint num = b;
3270 if (source.Length <= 8)
3271 {
3272 for (int i = 1; i < source.Length; i++)
3273 {
3274 index = source[i];
3275 b = charToHexLookup[index];
3276 if (b == byte.MaxValue)
3277 {
3278 bytesConsumed = i;
3279 value = num;
3280 return true;
3281 }
3282 num = (num << 4) + b;
3283 }
3284 }
3285 else
3286 {
3287 for (int j = 1; j < 8; j++)
3288 {
3289 index = source[j];
3290 b = charToHexLookup[index];
3291 if (b == byte.MaxValue)
3292 {
3293 bytesConsumed = j;
3294 value = num;
3295 return true;
3296 }
3297 num = (num << 4) + b;
3298 }
3299 for (int k = 8; k < source.Length; k++)
3300 {
3301 index = source[k];
3302 b = charToHexLookup[index];
3303 if (b == byte.MaxValue)
3304 {
3305 bytesConsumed = k;
3306 value = num;
3307 return true;
3308 }
3309 if (num > 268435455)
3310 {
3311 bytesConsumed = 0;
3312 value = 0u;
3313 return false;
3314 }
3315 num = (num << 4) + b;
3316 }
3317 }
3318 bytesConsumed = source.Length;
3319 value = num;
3320 return true;
3321 }
3322
3323 private static bool TryParseUInt64X(ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed)
3324 {
3325 if (source.Length < 1)
3326 {
3327 bytesConsumed = 0;
3328 value = 0uL;
3329 return false;
3330 }
3332 byte index = source[0];
3333 byte b = charToHexLookup[index];
3334 if (b == byte.MaxValue)
3335 {
3336 bytesConsumed = 0;
3337 value = 0uL;
3338 return false;
3339 }
3340 ulong num = b;
3341 if (source.Length <= 16)
3342 {
3343 for (int i = 1; i < source.Length; i++)
3344 {
3345 index = source[i];
3346 b = charToHexLookup[index];
3347 if (b == byte.MaxValue)
3348 {
3349 bytesConsumed = i;
3350 value = num;
3351 return true;
3352 }
3353 num = (num << 4) + b;
3354 }
3355 }
3356 else
3357 {
3358 for (int j = 1; j < 16; j++)
3359 {
3360 index = source[j];
3361 b = charToHexLookup[index];
3362 if (b == byte.MaxValue)
3363 {
3364 bytesConsumed = j;
3365 value = num;
3366 return true;
3367 }
3368 num = (num << 4) + b;
3369 }
3370 for (int k = 16; k < source.Length; k++)
3371 {
3372 index = source[k];
3373 b = charToHexLookup[index];
3374 if (b == byte.MaxValue)
3375 {
3376 bytesConsumed = k;
3377 value = num;
3378 return true;
3379 }
3380 if (num > 1152921504606846975L)
3381 {
3382 bytesConsumed = 0;
3383 value = 0uL;
3384 return false;
3385 }
3386 num = (num << 4) + b;
3387 }
3388 }
3389 bytesConsumed = source.Length;
3390 value = num;
3391 return true;
3392 }
3393
3394 private static bool TryParseNumber(ReadOnlySpan<byte> source, ref Number.NumberBuffer number, out int bytesConsumed, ParseNumberOptions options, out bool textUsedExponentNotation)
3395 {
3396 textUsedExponentNotation = false;
3397 if (source.Length == 0)
3398 {
3399 bytesConsumed = 0;
3400 return false;
3401 }
3402 Span<byte> digits = number.Digits;
3403 int i = 0;
3404 int num = 0;
3405 byte b = source[i];
3406 if (b != 43)
3407 {
3408 if (b != 45)
3409 {
3410 goto IL_0055;
3411 }
3412 number.IsNegative = true;
3413 }
3414 i++;
3415 if (i == source.Length)
3416 {
3417 bytesConsumed = 0;
3418 return false;
3419 }
3420 b = source[i];
3421 goto IL_0055;
3422 IL_02a0:
3423 if ((byte)(b - 48) > 9)
3424 {
3425 bytesConsumed = 0;
3426 return false;
3427 }
3428 if (!TryParseUInt32D(source.Slice(i), out var value, out var bytesConsumed2))
3429 {
3430 value = uint.MaxValue;
3431 for (i += 10; i != source.Length; i++)
3432 {
3433 b = source[i];
3434 int num2 = (byte)(b - 48);
3435 if (num2 > 9)
3436 {
3437 break;
3438 }
3439 }
3440 }
3441 i += bytesConsumed2;
3442 bool flag;
3443 if (flag)
3444 {
3445 if (number.Scale < int.MinValue + value)
3446 {
3447 number.Scale = int.MinValue;
3448 }
3449 else
3450 {
3451 number.Scale -= (int)value;
3452 }
3453 }
3454 else if (number.Scale > 2147483647L - (long)value)
3455 {
3456 number.Scale = int.MaxValue;
3457 }
3458 else
3459 {
3460 number.Scale += (int)value;
3461 }
3462 digits[num] = 0;
3463 number.DigitsCount = num;
3464 bytesConsumed = i;
3465 return true;
3466 IL_0055:
3467 int num3 = i;
3468 int num4 = 0;
3469 int num5 = digits.Length - 1;
3470 for (; i != source.Length; i++)
3471 {
3472 b = source[i];
3473 if (b != 48)
3474 {
3475 break;
3476 }
3477 }
3478 if (i == source.Length)
3479 {
3480 bytesConsumed = i;
3481 return true;
3482 }
3483 int num6 = i;
3484 int num7 = 0;
3485 while (i != source.Length)
3486 {
3487 b = source[i];
3488 int num8 = (byte)(b - 48);
3489 if (num8 > 9)
3490 {
3491 break;
3492 }
3493 i++;
3494 num4++;
3495 if (num4 >= num5)
3496 {
3497 num7 |= num8;
3498 }
3499 }
3500 number.HasNonZeroTail = num7 != 0;
3501 int num9 = i - num3;
3502 int num10 = i - num6;
3503 int num11 = Math.Min(num10, num5);
3504 source.Slice(num6, num11).CopyTo(digits);
3505 num = num11;
3506 number.Scale = num10;
3507 if (i == source.Length)
3508 {
3509 digits[num] = 0;
3510 number.DigitsCount = num;
3511 bytesConsumed = i;
3512 return true;
3513 }
3514 int num12 = 0;
3515 if (b == 46)
3516 {
3517 i++;
3518 int num13 = i;
3519 while (i != source.Length)
3520 {
3521 b = source[i];
3522 int num14 = (byte)(b - 48);
3523 if (num14 > 9)
3524 {
3525 break;
3526 }
3527 i++;
3528 num4++;
3529 if (num4 >= num5)
3530 {
3531 num7 |= num14;
3532 }
3533 }
3534 number.HasNonZeroTail = num7 != 0;
3535 num12 = i - num13;
3536 int j = num13;
3537 if (num == 0)
3538 {
3539 for (; j < i && source[j] == 48; j++)
3540 {
3541 number.Scale--;
3542 }
3543 }
3544 int num15 = Math.Min(i - j, num5 - num);
3545 source.Slice(j, num15).CopyTo(digits.Slice(num));
3546 num += num15;
3547 if (i == source.Length)
3548 {
3549 if (num9 == 0 && num12 == 0)
3550 {
3551 bytesConsumed = 0;
3552 return false;
3553 }
3554 digits[num] = 0;
3555 number.DigitsCount = num;
3556 bytesConsumed = i;
3557 return true;
3558 }
3559 }
3560 if (num9 == 0 && num12 == 0)
3561 {
3562 bytesConsumed = 0;
3563 return false;
3564 }
3565 if ((b & -33) != 69)
3566 {
3567 digits[num] = 0;
3568 number.DigitsCount = num;
3569 bytesConsumed = i;
3570 return true;
3571 }
3572 textUsedExponentNotation = true;
3573 i++;
3574 if ((options & ParseNumberOptions.AllowExponent) == 0)
3575 {
3576 bytesConsumed = 0;
3577 return false;
3578 }
3579 if (i == source.Length)
3580 {
3581 bytesConsumed = 0;
3582 return false;
3583 }
3584 flag = false;
3585 b = source[i];
3586 if (b != 43)
3587 {
3588 if (b != 45)
3589 {
3590 goto IL_02a0;
3591 }
3592 flag = true;
3593 }
3594 i++;
3595 if (i == source.Length)
3596 {
3597 bytesConsumed = 0;
3598 return false;
3599 }
3600 b = source[i];
3601 goto IL_02a0;
3602 }
3603
3604 private static bool TryParseTimeSpanBigG(ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed)
3605 {
3606 int i = 0;
3607 byte b = 0;
3608 for (; i != source.Length; i++)
3609 {
3610 b = source[i];
3611 if (b != 32 && b != 9)
3612 {
3613 break;
3614 }
3615 }
3616 if (i == source.Length)
3617 {
3618 value = default(TimeSpan);
3619 bytesConsumed = 0;
3620 return false;
3621 }
3622 bool isNegative = false;
3623 if (b == 45)
3624 {
3625 isNegative = true;
3626 i++;
3627 if (i == source.Length)
3628 {
3629 value = default(TimeSpan);
3630 bytesConsumed = 0;
3631 return false;
3632 }
3633 }
3634 if (!TryParseUInt32D(source.Slice(i), out var value2, out var bytesConsumed2))
3635 {
3636 value = default(TimeSpan);
3637 bytesConsumed = 0;
3638 return false;
3639 }
3640 i += bytesConsumed2;
3641 if (i == source.Length || source[i++] != 58)
3642 {
3643 value = default(TimeSpan);
3644 bytesConsumed = 0;
3645 return false;
3646 }
3647 if (!TryParseUInt32D(source.Slice(i), out var value3, out bytesConsumed2))
3648 {
3649 value = default(TimeSpan);
3650 bytesConsumed = 0;
3651 return false;
3652 }
3653 i += bytesConsumed2;
3654 if (i == source.Length || source[i++] != 58)
3655 {
3656 value = default(TimeSpan);
3657 bytesConsumed = 0;
3658 return false;
3659 }
3660 if (!TryParseUInt32D(source.Slice(i), out var value4, out bytesConsumed2))
3661 {
3662 value = default(TimeSpan);
3663 bytesConsumed = 0;
3664 return false;
3665 }
3666 i += bytesConsumed2;
3667 if (i == source.Length || source[i++] != 58)
3668 {
3669 value = default(TimeSpan);
3670 bytesConsumed = 0;
3671 return false;
3672 }
3673 if (!TryParseUInt32D(source.Slice(i), out var value5, out bytesConsumed2))
3674 {
3675 value = default(TimeSpan);
3676 bytesConsumed = 0;
3677 return false;
3678 }
3679 i += bytesConsumed2;
3680 if (i == source.Length || source[i++] != 46)
3681 {
3682 value = default(TimeSpan);
3683 bytesConsumed = 0;
3684 return false;
3685 }
3686 if (!TryParseTimeSpanFraction(source.Slice(i), out var value6, out bytesConsumed2))
3687 {
3688 value = default(TimeSpan);
3689 bytesConsumed = 0;
3690 return false;
3691 }
3692 i += bytesConsumed2;
3693 if (!TryCreateTimeSpan(isNegative, value2, value3, value4, value5, value6, out value))
3694 {
3695 value = default(TimeSpan);
3696 bytesConsumed = 0;
3697 return false;
3698 }
3699 if (i != source.Length && (source[i] == 46 || source[i] == 58))
3700 {
3701 value = default(TimeSpan);
3702 bytesConsumed = 0;
3703 return false;
3704 }
3705 bytesConsumed = i;
3706 return true;
3707 }
3708
3709 private static bool TryParseTimeSpanC(ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed)
3710 {
3711 TimeSpanSplitter timeSpanSplitter = default(TimeSpanSplitter);
3712 if (!timeSpanSplitter.TrySplitTimeSpan(source, periodUsedToSeparateDay: true, out bytesConsumed))
3713 {
3714 value = default(TimeSpan);
3715 return false;
3716 }
3717 bool isNegative = timeSpanSplitter.IsNegative;
3718 bool flag;
3719 switch (timeSpanSplitter.Separators)
3720 {
3721 case 0u:
3722 flag = TryCreateTimeSpan(isNegative, timeSpanSplitter.V1, 0u, 0u, 0u, 0u, out value);
3723 break;
3724 case 16777216u:
3725 flag = TryCreateTimeSpan(isNegative, 0u, timeSpanSplitter.V1, timeSpanSplitter.V2, 0u, 0u, out value);
3726 break;
3727 case 33619968u:
3728 flag = TryCreateTimeSpan(isNegative, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, 0u, 0u, out value);
3729 break;
3730 case 16842752u:
3731 flag = TryCreateTimeSpan(isNegative, 0u, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, 0u, out value);
3732 break;
3733 case 33620224u:
3734 flag = TryCreateTimeSpan(isNegative, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, timeSpanSplitter.V4, 0u, out value);
3735 break;
3736 case 16843264u:
3737 flag = TryCreateTimeSpan(isNegative, 0u, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, timeSpanSplitter.V4, out value);
3738 break;
3739 case 33620226u:
3740 flag = TryCreateTimeSpan(isNegative, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, timeSpanSplitter.V4, timeSpanSplitter.V5, out value);
3741 break;
3742 default:
3743 value = default(TimeSpan);
3744 flag = false;
3745 break;
3746 }
3747 if (!flag)
3748 {
3749 bytesConsumed = 0;
3750 return false;
3751 }
3752 return true;
3753 }
3754
3755 public static bool TryParse(ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed, char standardFormat = '\0')
3756 {
3757 switch (standardFormat)
3758 {
3759 case '\0':
3760 case 'T':
3761 case 'c':
3762 case 't':
3763 return TryParseTimeSpanC(source, out value, out bytesConsumed);
3764 case 'G':
3765 return TryParseTimeSpanBigG(source, out value, out bytesConsumed);
3766 case 'g':
3767 return TryParseTimeSpanLittleG(source, out value, out bytesConsumed);
3768 default:
3769 return ParserHelpers.TryParseThrowFormatException<TimeSpan>(out value, out bytesConsumed);
3770 }
3771 }
3772
3773 private static bool TryParseTimeSpanFraction(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed)
3774 {
3775 int num = 0;
3776 if (num == source.Length)
3777 {
3778 value = 0u;
3779 bytesConsumed = 0;
3780 return false;
3781 }
3782 uint num2 = (uint)(source[num] - 48);
3783 if (num2 > 9)
3784 {
3785 value = 0u;
3786 bytesConsumed = 0;
3787 return false;
3788 }
3789 num++;
3790 uint num3 = num2;
3791 int num4 = 1;
3792 while (num != source.Length)
3793 {
3794 num2 = (uint)(source[num] - 48);
3795 if (num2 > 9)
3796 {
3797 break;
3798 }
3799 num++;
3800 num4++;
3801 if (num4 > 7)
3802 {
3803 value = 0u;
3804 bytesConsumed = 0;
3805 return false;
3806 }
3807 num3 = 10 * num3 + num2;
3808 }
3809 switch (num4)
3810 {
3811 case 6:
3812 num3 *= 10;
3813 break;
3814 case 5:
3815 num3 *= 100;
3816 break;
3817 case 4:
3818 num3 *= 1000;
3819 break;
3820 case 3:
3821 num3 *= 10000;
3822 break;
3823 case 2:
3824 num3 *= 100000;
3825 break;
3826 default:
3827 num3 *= 1000000;
3828 break;
3829 case 7:
3830 break;
3831 }
3832 value = num3;
3833 bytesConsumed = num;
3834 return true;
3835 }
3836
3837 private static bool TryCreateTimeSpan(bool isNegative, uint days, uint hours, uint minutes, uint seconds, uint fraction, out TimeSpan timeSpan)
3838 {
3839 if (hours > 23 || minutes > 59 || seconds > 59)
3840 {
3841 timeSpan = default(TimeSpan);
3842 return false;
3843 }
3844 long num = ((long)days * 3600L * 24 + (long)hours * 3600L + (long)minutes * 60L + seconds) * 1000;
3845 long ticks;
3846 if (isNegative)
3847 {
3848 num = -num;
3849 if (num < -922337203685477L)
3850 {
3851 timeSpan = default(TimeSpan);
3852 return false;
3853 }
3854 long num2 = num * 10000;
3855 if (num2 < long.MinValue + fraction)
3856 {
3857 timeSpan = default(TimeSpan);
3858 return false;
3859 }
3860 ticks = num2 - fraction;
3861 }
3862 else
3863 {
3864 if (num > 922337203685477L)
3865 {
3866 timeSpan = default(TimeSpan);
3867 return false;
3868 }
3869 long num3 = num * 10000;
3870 if (num3 > long.MaxValue - (long)fraction)
3871 {
3872 timeSpan = default(TimeSpan);
3873 return false;
3874 }
3875 ticks = num3 + fraction;
3876 }
3877 timeSpan = new TimeSpan(ticks);
3878 return true;
3879 }
3880
3881 private static bool TryParseTimeSpanLittleG(ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed)
3882 {
3883 TimeSpanSplitter timeSpanSplitter = default(TimeSpanSplitter);
3884 if (!timeSpanSplitter.TrySplitTimeSpan(source, periodUsedToSeparateDay: false, out bytesConsumed))
3885 {
3886 value = default(TimeSpan);
3887 return false;
3888 }
3889 bool isNegative = timeSpanSplitter.IsNegative;
3890 bool flag;
3891 switch (timeSpanSplitter.Separators)
3892 {
3893 case 0u:
3894 flag = TryCreateTimeSpan(isNegative, timeSpanSplitter.V1, 0u, 0u, 0u, 0u, out value);
3895 break;
3896 case 16777216u:
3897 flag = TryCreateTimeSpan(isNegative, 0u, timeSpanSplitter.V1, timeSpanSplitter.V2, 0u, 0u, out value);
3898 break;
3899 case 16842752u:
3900 flag = TryCreateTimeSpan(isNegative, 0u, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, 0u, out value);
3901 break;
3902 case 16843008u:
3903 flag = TryCreateTimeSpan(isNegative, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, timeSpanSplitter.V4, 0u, out value);
3904 break;
3905 case 16843264u:
3906 flag = TryCreateTimeSpan(isNegative, 0u, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, timeSpanSplitter.V4, out value);
3907 break;
3908 case 16843010u:
3909 flag = TryCreateTimeSpan(isNegative, timeSpanSplitter.V1, timeSpanSplitter.V2, timeSpanSplitter.V3, timeSpanSplitter.V4, timeSpanSplitter.V5, out value);
3910 break;
3911 default:
3912 value = default(TimeSpan);
3913 flag = false;
3914 break;
3915 }
3916 if (!flag)
3917 {
3918 bytesConsumed = 0;
3919 return false;
3920 }
3921 return true;
3922 }
3923}
static int ReadInt32LittleEndian(ReadOnlySpan< byte > source)
static bool TryParseThrowFormatException(out int bytesConsumed)
static bool TryParse(ReadOnlySpan< byte > source, out ulong value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseSByteN(ReadOnlySpan< byte > source, out sbyte value, out int bytesConsumed)
static unsafe bool TryParse(ReadOnlySpan< byte > source, out double value, out int bytesConsumed, char standardFormat='\0')
static bool TryCreateTimeSpan(bool isNegative, uint days, uint hours, uint minutes, uint seconds, uint fraction, out TimeSpan timeSpan)
static bool TryParseInt32D(ReadOnlySpan< byte > source, out int value, out int bytesConsumed)
static readonly int[] s_daysToMonth366
static unsafe bool TryParse(ReadOnlySpan< byte > source, out decimal value, out int bytesConsumed, char standardFormat='\0')
static bool TryParse(ReadOnlySpan< byte > source, out bool value, out int bytesConsumed, char standardFormat='\0')
static bool TryCreateDateTimeOffset(DateTime dateTime, bool offsetNegative, int offsetHours, int offsetMinutes, out DateTimeOffset value)
static bool TryParseUInt32N(ReadOnlySpan< byte > source, out uint value, out int bytesConsumed)
static bool TryParseDateTimeOffsetR(ReadOnlySpan< byte > source, uint caseFlipXorMask, out DateTimeOffset dateTimeOffset, out int bytesConsumed)
static bool TryParse(ReadOnlySpan< byte > source, out uint value, out int bytesConsumed, char standardFormat='\0')
static bool TryParse(ReadOnlySpan< byte > source, out byte value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseInt64N(ReadOnlySpan< byte > source, out long value, out int bytesConsumed)
static bool TryParse(ReadOnlySpan< byte > source, out int value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseByteX(ReadOnlySpan< byte > source, out byte value, out int bytesConsumed)
static bool TryParseDateTimeOffsetO(ReadOnlySpan< byte > source, out DateTimeOffset value, out int bytesConsumed, out DateTimeKind kind)
static bool TryParseInt16N(ReadOnlySpan< byte > source, out short value, out int bytesConsumed)
static bool TryParseNumber(ReadOnlySpan< byte > source, ref Number.NumberBuffer number, out int bytesConsumed, ParseNumberOptions options, out bool textUsedExponentNotation)
static bool TryParseInt32N(ReadOnlySpan< byte > source, out int value, out int bytesConsumed)
static bool TryParseUInt16D(ReadOnlySpan< byte > source, out ushort value, out int bytesConsumed)
static bool TryParse(ReadOnlySpan< byte > source, out DateTimeOffset value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseUInt16X(ReadOnlySpan< byte > source, out ushort value, out int bytesConsumed)
static bool TryParseTimeSpanC(ReadOnlySpan< byte > source, out TimeSpan value, out int bytesConsumed)
static bool TryParse(ReadOnlySpan< byte > source, out sbyte value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseInt64D(ReadOnlySpan< byte > source, out long value, out int bytesConsumed)
static bool TryParseUInt64N(ReadOnlySpan< byte > source, out ulong value, out int bytesConsumed)
static readonly int[] s_daysToMonth365
static bool TryParse(ReadOnlySpan< byte > source, out long value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseSByteD(ReadOnlySpan< byte > source, out sbyte value, out int bytesConsumed)
static bool TryParse(ReadOnlySpan< byte > source, out ushort value, out int bytesConsumed, char standardFormat='\0')
static bool TryParse(ReadOnlySpan< byte > source, out DateTime value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseInt16D(ReadOnlySpan< byte > source, out short value, out int bytesConsumed)
static bool TryParseTimeSpanFraction(ReadOnlySpan< byte > source, out uint value, out int bytesConsumed)
static bool TryCreateDateTimeOffsetInterpretingDataAsLocalTime(int year, int month, int day, int hour, int minute, int second, int fraction, out DateTimeOffset value)
static bool TryCreateDateTime(int year, int month, int day, int hour, int minute, int second, int fraction, DateTimeKind kind, out DateTime value)
static unsafe bool TryParse(ReadOnlySpan< byte > source, out float value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseDateTimeOffsetDefault(ReadOnlySpan< byte > source, out DateTimeOffset value, out int bytesConsumed)
static bool TryParseUInt32D(ReadOnlySpan< byte > source, out uint value, out int bytesConsumed)
static bool TryParseAsSpecialFloatingPoint< T >(ReadOnlySpan< byte > source, T positiveInfinity, T negativeInfinity, T nan, out T value, out int bytesConsumed)
static bool TryParseGuidN(ReadOnlySpan< byte > text, out Guid value, out int bytesConsumed)
static bool TryParseUInt16N(ReadOnlySpan< byte > source, out ushort value, out int bytesConsumed)
static bool TryParseByteN(ReadOnlySpan< byte > source, out byte value, out int bytesConsumed)
static bool TryParseTimeSpanBigG(ReadOnlySpan< byte > source, out TimeSpan value, out int bytesConsumed)
static bool TryParseByteD(ReadOnlySpan< byte > source, out byte value, out int bytesConsumed)
static bool TryParseUInt32X(ReadOnlySpan< byte > source, out uint value, out int bytesConsumed)
static bool TryParseNormalAsFloatingPoint(ReadOnlySpan< byte > source, ref Number.NumberBuffer number, out int bytesConsumed, char standardFormat)
static bool TryParseTimeSpanLittleG(ReadOnlySpan< byte > source, out TimeSpan value, out int bytesConsumed)
static bool TryParseUInt64D(ReadOnlySpan< byte > source, out ulong value, out int bytesConsumed)
static bool TryCreateDateTimeOffset(int year, int month, int day, int hour, int minute, int second, int fraction, bool offsetNegative, int offsetHours, int offsetMinutes, out DateTimeOffset value)
static bool TryParse(ReadOnlySpan< byte > source, out TimeSpan value, out int bytesConsumed, char standardFormat='\0')
static bool TryParseGuidCore(ReadOnlySpan< byte > source, out Guid value, out int bytesConsumed, int ends)
static bool TryParseUInt64X(ReadOnlySpan< byte > source, out ulong value, out int bytesConsumed)
static bool TryParseDateTimeG(ReadOnlySpan< byte > source, out DateTime value, out DateTimeOffset valueAsOffset, out int bytesConsumed)
static bool TryParse(ReadOnlySpan< byte > source, out short value, out int bytesConsumed, char standardFormat='\0')
static bool TryParse(ReadOnlySpan< byte > source, out Guid value, out int bytesConsumed, char standardFormat='\0')
static ReadOnlySpan< byte > CharToHexLookup
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static unsafe bool TryNumberToDecimal(ref NumberBuffer number, ref decimal value)
Definition Number.cs:5513
static double NumberToDouble(ref NumberBuffer number)
Definition Number.cs:5949
static float NumberToSingle(ref NumberBuffer number)
Definition Number.cs:5995
static void ThrowFormatException_BadFormatSpecifier()
DayOfWeek
Definition DayOfWeek.cs:4
bool TrySplitTimeSpan(ReadOnlySpan< byte > source, bool periodUsedToSeparateDay, out int bytesConsumed)
Definition Utf8Parser.cs:38
static ComponentParseResult ParseComponent(ReadOnlySpan< byte > source, bool neverParseAsFraction, ref int srcIndex, out uint value)
static int DaysInMonth(int year, int month)
Definition DateTime.cs:624
static bool IsLeapYear(int year)
Definition DateTime.cs:898
Span< T > Slice(int start)
Definition Span.cs:271