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

◆ ParseNonCanonical() [2/2]

static unsafe long System.IPv4AddressHelper.ParseNonCanonical ( char * name,
int start,
ref int end,
bool notImplicitFile )
inlinestaticpackage

Definition at line 128 of file IPv4AddressHelper.cs.

129 {
130 int num = 10;
131 long* ptr = stackalloc long[4];
132 long num2 = 0L;
133 bool flag = false;
134 int num3 = 0;
135 int i;
136 for (i = start; i < end; i++)
137 {
138 char c = name[i];
139 num2 = 0L;
140 num = 10;
141 if (c == '0')
142 {
143 num = 8;
144 i++;
145 flag = true;
146 if (i < end)
147 {
148 c = name[i];
149 if (c == 'x' || c == 'X')
150 {
151 num = 16;
152 i++;
153 flag = false;
154 }
155 }
156 }
157 for (; i < end; i++)
158 {
159 c = name[i];
160 int num4;
161 if ((num == 10 || num == 16) && '0' <= c && c <= '9')
162 {
163 num4 = c - 48;
164 }
165 else if (num == 8 && '0' <= c && c <= '7')
166 {
167 num4 = c - 48;
168 }
169 else if (num == 16 && 'a' <= c && c <= 'f')
170 {
171 num4 = c + 10 - 97;
172 }
173 else
174 {
175 if (num != 16 || 'A' > c || c > 'F')
176 {
177 break;
178 }
179 num4 = c + 10 - 65;
180 }
181 num2 = num2 * num + num4;
182 if (num2 > uint.MaxValue)
183 {
184 return -1L;
185 }
186 flag = true;
187 }
188 if (i >= end || name[i] != '.')
189 {
190 break;
191 }
192 if (num3 >= 3 || !flag || num2 > 255)
193 {
194 return -1L;
195 }
196 ptr[num3] = num2;
197 num3++;
198 flag = false;
199 }
200 if (!flag)
201 {
202 return -1L;
203 }
204 if (i < end)
205 {
206 char c;
207 if ((c = name[i]) != '/' && c != '\\' && (!notImplicitFile || (c != ':' && c != '?' && c != '#')))
208 {
209 return -1L;
210 }
211 end = i;
212 }
213 ptr[num3] = num2;
214 switch (num3)
215 {
216 case 0:
217 if (*ptr > uint.MaxValue)
218 {
219 return -1L;
220 }
221 return *ptr;
222 case 1:
223 if (ptr[1] > 16777215)
224 {
225 return -1L;
226 }
227 return (*ptr << 24) | (ptr[1] & 0xFFFFFF);
228 case 2:
229 if (ptr[2] > 65535)
230 {
231 return -1L;
232 }
233 return (*ptr << 24) | ((ptr[1] & 0xFF) << 16) | (ptr[2] & 0xFFFF);
234 case 3:
235 if (ptr[3] > 255)
236 {
237 return -1L;
238 }
239 return (*ptr << 24) | ((ptr[1] & 0xFF) << 16) | ((ptr[2] & 0xFF) << 8) | (ptr[3] & 0xFF);
240 default:
241 return -1L;
242 }
243 }

References System.L, and System.start.