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

◆ StringToLong() [2/2]

static long System.ParseNumbers.StringToLong ( ReadOnlySpan< char > s,
int radix,
int flags,
ref int currPos )
inlinestatic

Definition at line 13 of file ParseNumbers.cs.

14 {
15 int i = currPos;
16 int num = ((-1 == radix) ? 10 : radix);
17 if (num != 2 && num != 10 && num != 8 && num != 16)
18 {
19 throw new ArgumentException(SR.Arg_InvalidBase, "radix");
20 }
21 int length = s.Length;
22 if (i < 0 || i >= length)
23 {
24 throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Index);
25 }
26 if ((flags & 0x1000) == 0 && (flags & 0x2000) == 0)
27 {
28 EatWhiteSpace(s, ref i);
29 if (i == length)
30 {
31 throw new FormatException(SR.Format_EmptyInputString);
32 }
33 }
34 int num2 = 1;
35 if (s[i] == '-')
36 {
37 if (num != 10)
38 {
39 throw new ArgumentException(SR.Arg_CannotHaveNegativeValue);
40 }
41 if (((uint)flags & 0x200u) != 0)
42 {
43 throw new OverflowException(SR.Overflow_NegativeUnsigned);
44 }
45 num2 = -1;
46 i++;
47 }
48 else if (s[i] == '+')
49 {
50 i++;
51 }
52 if ((radix == -1 || radix == 16) && i + 1 < length && s[i] == '0' && (s[i + 1] == 'x' || s[i + 1] == 'X'))
53 {
54 num = 16;
55 i += 2;
56 }
57 int num3 = i;
58 long num4 = GrabLongs(num, s, ref i, (flags & 0x200) != 0);
59 if (i == num3)
60 {
61 throw new FormatException(SR.Format_NoParsibleDigits);
62 }
63 if (((uint)flags & 0x1000u) != 0 && i < length)
64 {
65 throw new FormatException(SR.Format_ExtraJunkAtEnd);
66 }
67 currPos = i;
68 if (num4 == long.MinValue && num2 == 1 && num == 10 && (flags & 0x200) == 0)
69 {
70 Number.ThrowOverflowException(TypeCode.Int64);
71 }
72 if (num == 10)
73 {
74 num4 *= num2;
75 }
76 return num4;
77 }
static long GrabLongs(int radix, ReadOnlySpan< char > s, ref int i, bool isUnsigned)
static void EatWhiteSpace(ReadOnlySpan< char > s, ref int i)

References System.SR.Arg_CannotHaveNegativeValue, System.SR.Arg_InvalidBase, System.SR.ArgumentOutOfRange_Index, System.ParseNumbers.EatWhiteSpace(), System.SR.Format_EmptyInputString, System.SR.Format_ExtraJunkAtEnd, System.SR.Format_NoParsibleDigits, System.ParseNumbers.GrabLongs(), System.length, System.SR.Overflow_NegativeUnsigned, System.s, and System.Number.ThrowOverflowException().