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

◆ StringToInt() [2/2]

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

Definition at line 85 of file ParseNumbers.cs.

86 {
87 int i = currPos;
88 int num = ((-1 == radix) ? 10 : radix);
89 if (num != 2 && num != 10 && num != 8 && num != 16)
90 {
91 throw new ArgumentException(SR.Arg_InvalidBase, "radix");
92 }
93 int length = s.Length;
94 if (i < 0 || i >= length)
95 {
96 throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Index);
97 }
98 if ((flags & 0x1000) == 0 && (flags & 0x2000) == 0)
99 {
100 EatWhiteSpace(s, ref i);
101 if (i == length)
102 {
103 throw new FormatException(SR.Format_EmptyInputString);
104 }
105 }
106 int num2 = 1;
107 if (s[i] == '-')
108 {
109 if (num != 10)
110 {
111 throw new ArgumentException(SR.Arg_CannotHaveNegativeValue);
112 }
113 if (((uint)flags & 0x200u) != 0)
114 {
115 throw new OverflowException(SR.Overflow_NegativeUnsigned);
116 }
117 num2 = -1;
118 i++;
119 }
120 else if (s[i] == '+')
121 {
122 i++;
123 }
124 if ((radix == -1 || radix == 16) && i + 1 < length && s[i] == '0' && (s[i + 1] == 'x' || s[i + 1] == 'X'))
125 {
126 num = 16;
127 i += 2;
128 }
129 int num3 = i;
130 int num4 = GrabInts(num, s, ref i, (flags & 0x200) != 0);
131 if (i == num3)
132 {
133 throw new FormatException(SR.Format_NoParsibleDigits);
134 }
135 if (((uint)flags & 0x1000u) != 0 && i < length)
136 {
137 throw new FormatException(SR.Format_ExtraJunkAtEnd);
138 }
139 currPos = i;
140 if (((uint)flags & 0x400u) != 0)
141 {
142 if ((uint)num4 > 255u)
143 {
144 Number.ThrowOverflowException(TypeCode.SByte);
145 }
146 }
147 else if (((uint)flags & 0x800u) != 0)
148 {
149 if ((uint)num4 > 65535u)
150 {
151 Number.ThrowOverflowException(TypeCode.Int16);
152 }
153 }
154 else if (num4 == int.MinValue && num2 == 1 && num == 10 && (flags & 0x200) == 0)
155 {
156 Number.ThrowOverflowException(TypeCode.Int32);
157 }
158 if (num == 10)
159 {
160 num4 *= num2;
161 }
162 return num4;
163 }
static int GrabInts(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.GrabInts(), System.length, System.SR.Overflow_NegativeUnsigned, System.s, and System.Number.ThrowOverflowException().