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

◆ TryParseDateTimeOffset()

static bool System.Text.Json.JsonHelpers.TryParseDateTimeOffset ( ReadOnlySpan< byte > source,
out DateTimeParseData parseData )
inlinestaticprivate

Definition at line 165 of file JsonHelpers.cs.

166 {
167 parseData = default(DateTimeParseData);
168 uint num = (uint)(source[0] - 48);
169 uint num2 = (uint)(source[1] - 48);
170 uint num3 = (uint)(source[2] - 48);
171 uint num4 = (uint)(source[3] - 48);
172 if (num > 9 || num2 > 9 || num3 > 9 || num4 > 9)
173 {
174 return false;
175 }
176 parseData.Year = (int)(num * 1000 + num2 * 100 + num3 * 10 + num4);
177 if (source[4] != 45 || !TryGetNextTwoDigits(source.Slice(5, 2), ref parseData.Month) || source[7] != 45 || !TryGetNextTwoDigits(source.Slice(8, 2), ref parseData.Day))
178 {
179 return false;
180 }
181 if (source.Length == 10)
182 {
183 return true;
184 }
185 if (source.Length < 16)
186 {
187 return false;
188 }
189 if (source[10] != 84 || source[13] != 58 || !TryGetNextTwoDigits(source.Slice(11, 2), ref parseData.Hour) || !TryGetNextTwoDigits(source.Slice(14, 2), ref parseData.Minute))
190 {
191 return false;
192 }
193 if (source.Length == 16)
194 {
195 return true;
196 }
197 byte b = source[16];
198 int num5 = 17;
199 switch (b)
200 {
201 case 90:
203 return num5 == source.Length;
204 case 43:
205 case 45:
207 return ParseOffset(ref parseData, source.Slice(num5));
208 default:
209 return false;
210 case 58:
211 if (source.Length < 19 || !TryGetNextTwoDigits(source.Slice(17, 2), ref parseData.Second))
212 {
213 return false;
214 }
215 if (source.Length == 19)
216 {
217 return true;
218 }
219 b = source[19];
220 num5 = 20;
221 switch (b)
222 {
223 case 90:
225 return num5 == source.Length;
226 case 43:
227 case 45:
229 return ParseOffset(ref parseData, source.Slice(num5));
230 default:
231 return false;
232 case 46:
233 {
234 if (source.Length < 21)
235 {
236 return false;
237 }
238 int i = 0;
239 for (int num6 = Math.Min(num5 + 16, source.Length); num5 < num6; num5++)
240 {
241 if (!IsDigit(b = source[num5]))
242 {
243 break;
244 }
245 if (i < 7)
246 {
248 i++;
249 }
250 }
251 if (parseData.Fraction != 0)
252 {
253 for (; i < 7; i++)
254 {
255 parseData.Fraction *= 10;
256 }
257 }
258 if (num5 == source.Length)
259 {
260 return true;
261 }
262 b = source[num5++];
263 switch (b)
264 {
265 case 90:
267 return num5 == source.Length;
268 case 43:
269 case 45:
271 return ParseOffset(ref parseData, source.Slice(num5));
272 default:
273 return false;
274 }
275 }
276 }
277 }
278 static bool ParseOffset(ref DateTimeParseData parseData, ReadOnlySpan<byte> offsetData)
279 {
280 if (offsetData.Length < 2 || !TryGetNextTwoDigits(offsetData.Slice(0, 2), ref parseData.OffsetHours))
281 {
282 return false;
283 }
284 if (offsetData.Length == 2)
285 {
286 return true;
287 }
288 if (offsetData.Length != 5 || offsetData[2] != 58 || !TryGetNextTwoDigits(offsetData.Slice(3), ref parseData.OffsetMinutes))
289 {
290 return false;
291 }
292 return true;
293 }
294 }
static bool TryGetNextTwoDigits(ReadOnlySpan< byte > source, ref int value)
static bool IsDigit(byte value)

References System.Text.Json.Dictionary, System.Text.Json.JsonHelpers.IsDigit(), System.Math.Min(), System.source, and System.Text.Json.JsonHelpers.TryGetNextTwoDigits().

Referenced by System.Text.Json.JsonHelpers.TryParseAsISO(), and System.Text.Json.JsonHelpers.TryParseAsISO().