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

◆ ParseByFormat()

static bool System.DateTimeParse.ParseByFormat ( ref __DTString str,
ref __DTString format,
ref ParsingInfo parseInfo,
DateTimeFormatInfo dtfi,
ref DateTimeResult result )
inlinestaticprivate

Definition at line 3224 of file DateTimeParse.cs.

3225 {
3226 int result2 = 0;
3227 int result3 = 0;
3228 int result4 = 0;
3229 int result5 = 0;
3230 int result6 = 0;
3231 int result7 = 0;
3232 int result8 = 0;
3233 double result9 = 0.0;
3234 TM result10 = TM.AM;
3235 char @char = format.GetChar();
3236 switch (@char)
3237 {
3238 case 'y':
3239 {
3240 int repeatCount = format.GetRepeatCount();
3241 bool flag;
3242 if (ParseJapaneseEraStart(ref str, dtfi))
3243 {
3244 result2 = 1;
3245 flag = true;
3246 }
3247 else if (dtfi.HasForceTwoDigitYears)
3248 {
3249 flag = ParseDigits(ref str, 1, 4, out result2);
3250 }
3251 else
3252 {
3253 if (repeatCount <= 2)
3254 {
3255 parseInfo.fUseTwoDigitYear = true;
3256 }
3257 flag = ParseDigits(ref str, repeatCount, out result2);
3258 }
3259 if (!flag && parseInfo.fCustomNumberParser)
3260 {
3261 flag = parseInfo.parseNumberDelegate(ref str, repeatCount, out result2);
3262 }
3263 if (!flag)
3264 {
3265 result.SetBadDateTimeFailure();
3266 return false;
3267 }
3268 if (!CheckNewValue(ref result.Year, result2, @char, ref result))
3269 {
3270 return false;
3271 }
3272 break;
3273 }
3274 case 'M':
3275 {
3276 int repeatCount = format.GetRepeatCount();
3277 if (repeatCount <= 2)
3278 {
3279 if (!ParseDigits(ref str, repeatCount, out result3) && (!parseInfo.fCustomNumberParser || !parseInfo.parseNumberDelegate(ref str, repeatCount, out result3)))
3280 {
3281 result.SetBadDateTimeFailure();
3282 return false;
3283 }
3284 }
3285 else
3286 {
3287 if (repeatCount == 3)
3288 {
3289 if (!MatchAbbreviatedMonthName(ref str, dtfi, ref result3))
3290 {
3291 result.SetBadDateTimeFailure();
3292 return false;
3293 }
3294 }
3295 else if (!MatchMonthName(ref str, dtfi, ref result3))
3296 {
3297 result.SetBadDateTimeFailure();
3298 return false;
3299 }
3300 result.flags |= ParseFlags.ParsedMonthName;
3301 }
3302 if (!CheckNewValue(ref result.Month, result3, @char, ref result))
3303 {
3304 return false;
3305 }
3306 break;
3307 }
3308 case 'd':
3309 {
3310 int repeatCount = format.GetRepeatCount();
3311 if (repeatCount <= 2)
3312 {
3313 if (!ParseDigits(ref str, repeatCount, out result4) && (!parseInfo.fCustomNumberParser || !parseInfo.parseNumberDelegate(ref str, repeatCount, out result4)))
3314 {
3315 result.SetBadDateTimeFailure();
3316 return false;
3317 }
3318 if (!CheckNewValue(ref result.Day, result4, @char, ref result))
3319 {
3320 return false;
3321 }
3322 break;
3323 }
3324 if (repeatCount == 3)
3325 {
3326 if (!MatchAbbreviatedDayName(ref str, dtfi, ref result5))
3327 {
3328 result.SetBadDateTimeFailure();
3329 return false;
3330 }
3331 }
3332 else if (!MatchDayName(ref str, dtfi, ref result5))
3333 {
3334 result.SetBadDateTimeFailure();
3335 return false;
3336 }
3337 if (!CheckNewValue(ref parseInfo.dayOfWeek, result5, @char, ref result))
3338 {
3339 return false;
3340 }
3341 break;
3342 }
3343 case 'g':
3344 format.GetRepeatCount();
3345 if (!MatchEraName(ref str, dtfi, ref result.era))
3346 {
3347 result.SetBadDateTimeFailure();
3348 return false;
3349 }
3350 break;
3351 case 'h':
3352 {
3353 parseInfo.fUseHour12 = true;
3354 int repeatCount = format.GetRepeatCount();
3355 if (!ParseDigits(ref str, (repeatCount < 2) ? 1 : 2, out result6))
3356 {
3357 result.SetBadDateTimeFailure();
3358 return false;
3359 }
3360 if (!CheckNewValue(ref result.Hour, result6, @char, ref result))
3361 {
3362 return false;
3363 }
3364 break;
3365 }
3366 case 'H':
3367 {
3368 int repeatCount = format.GetRepeatCount();
3369 if (!ParseDigits(ref str, (repeatCount < 2) ? 1 : 2, out result6))
3370 {
3371 result.SetBadDateTimeFailure();
3372 return false;
3373 }
3374 if (!CheckNewValue(ref result.Hour, result6, @char, ref result))
3375 {
3376 return false;
3377 }
3378 break;
3379 }
3380 case 'm':
3381 {
3382 int repeatCount = format.GetRepeatCount();
3383 if (!ParseDigits(ref str, (repeatCount < 2) ? 1 : 2, out result7))
3384 {
3385 result.SetBadDateTimeFailure();
3386 return false;
3387 }
3388 if (!CheckNewValue(ref result.Minute, result7, @char, ref result))
3389 {
3390 return false;
3391 }
3392 break;
3393 }
3394 case 's':
3395 {
3396 int repeatCount = format.GetRepeatCount();
3397 if (!ParseDigits(ref str, (repeatCount < 2) ? 1 : 2, out result8))
3398 {
3399 result.SetBadDateTimeFailure();
3400 return false;
3401 }
3402 if (!CheckNewValue(ref result.Second, result8, @char, ref result))
3403 {
3404 return false;
3405 }
3406 break;
3407 }
3408 case 'F':
3409 case 'f':
3410 {
3411 int repeatCount = format.GetRepeatCount();
3412 if (repeatCount <= 7)
3413 {
3414 if (!ParseFractionExact(ref str, repeatCount, ref result9) && @char == 'f')
3415 {
3416 result.SetBadDateTimeFailure();
3417 return false;
3418 }
3419 if (result.fraction < 0.0)
3420 {
3421 result.fraction = result9;
3422 }
3423 else if (result9 != result.fraction)
3424 {
3425 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", @char);
3426 return false;
3427 }
3428 break;
3429 }
3430 result.SetBadDateTimeFailure();
3431 return false;
3432 }
3433 case 't':
3434 {
3435 int repeatCount = format.GetRepeatCount();
3436 if (repeatCount == 1)
3437 {
3438 if (!MatchAbbreviatedTimeMark(ref str, dtfi, ref result10))
3439 {
3440 result.SetBadDateTimeFailure();
3441 return false;
3442 }
3443 }
3444 else if (!MatchTimeMark(ref str, dtfi, ref result10))
3445 {
3446 result.SetBadDateTimeFailure();
3447 return false;
3448 }
3449 if (parseInfo.timeMark == TM.NotSet)
3450 {
3451 parseInfo.timeMark = result10;
3452 }
3453 else if (parseInfo.timeMark != result10)
3454 {
3455 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", @char);
3456 return false;
3457 }
3458 break;
3459 }
3460 case 'z':
3461 {
3462 int repeatCount = format.GetRepeatCount();
3463 TimeSpan result11 = new TimeSpan(0L);
3464 if (!ParseTimeZoneOffset(ref str, repeatCount, ref result11))
3465 {
3466 result.SetBadDateTimeFailure();
3467 return false;
3468 }
3469 if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result11 != result.timeZoneOffset)
3470 {
3471 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", 'z');
3472 return false;
3473 }
3474 result.timeZoneOffset = result11;
3475 result.flags |= ParseFlags.TimeZoneUsed;
3476 break;
3477 }
3478 case 'Z':
3479 if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result.timeZoneOffset != TimeSpan.Zero)
3480 {
3481 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", 'Z');
3482 return false;
3483 }
3484 result.flags |= ParseFlags.TimeZoneUsed;
3485 result.timeZoneOffset = new TimeSpan(0L);
3486 result.flags |= ParseFlags.TimeZoneUtc;
3487 str.Index++;
3488 if (!GetTimeZoneName(ref str))
3489 {
3490 result.SetBadDateTimeFailure();
3491 return false;
3492 }
3493 str.Index--;
3494 break;
3495 case 'K':
3496 if (str.Match('Z'))
3497 {
3498 if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result.timeZoneOffset != TimeSpan.Zero)
3499 {
3500 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", 'K');
3501 return false;
3502 }
3503 result.flags |= ParseFlags.TimeZoneUsed;
3504 result.timeZoneOffset = new TimeSpan(0L);
3505 result.flags |= ParseFlags.TimeZoneUtc;
3506 }
3507 else if (str.Match('+') || str.Match('-'))
3508 {
3509 str.Index--;
3510 TimeSpan result12 = new TimeSpan(0L);
3511 if (!ParseTimeZoneOffset(ref str, 3, ref result12))
3512 {
3513 result.SetBadDateTimeFailure();
3514 return false;
3515 }
3516 if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result12 != result.timeZoneOffset)
3517 {
3518 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", 'K');
3519 return false;
3520 }
3521 result.timeZoneOffset = result12;
3522 result.flags |= ParseFlags.TimeZoneUsed;
3523 }
3524 break;
3525 case ':':
3526 if (((dtfi.TimeSeparator.Length > 1 && dtfi.TimeSeparator[0] == ':') || !str.Match(':')) && !str.Match(dtfi.TimeSeparator))
3527 {
3528 result.SetBadDateTimeFailure();
3529 return false;
3530 }
3531 break;
3532 case '/':
3533 if (((dtfi.DateSeparator.Length > 1 && dtfi.DateSeparator[0] == '/') || !str.Match('/')) && !str.Match(dtfi.DateSeparator))
3534 {
3535 result.SetBadDateTimeFailure();
3536 return false;
3537 }
3538 break;
3539 case '"':
3540 case '\'':
3541 {
3542 StringBuilder stringBuilder = StringBuilderCache.Acquire();
3543 if (!TryParseQuoteString(format.Value, format.Index, stringBuilder, out var repeatCount))
3544 {
3545 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadQuote", @char);
3546 StringBuilderCache.Release(stringBuilder);
3547 return false;
3548 }
3549 format.Index += repeatCount - 1;
3550 string stringAndRelease = StringBuilderCache.GetStringAndRelease(stringBuilder);
3551 for (int i = 0; i < stringAndRelease.Length; i++)
3552 {
3553 if (stringAndRelease[i] == ' ' && parseInfo.fAllowInnerWhite)
3554 {
3555 str.SkipWhiteSpaces();
3556 }
3557 else if (!str.Match(stringAndRelease[i]))
3558 {
3559 result.SetBadDateTimeFailure();
3560 return false;
3561 }
3562 }
3563 if ((result.flags & ParseFlags.CaptureOffset) != 0 && (((result.flags & ParseFlags.Rfc1123Pattern) != 0 && stringAndRelease == "GMT") || ((result.flags & ParseFlags.UtcSortPattern) != 0 && stringAndRelease == "Z")))
3564 {
3565 result.flags |= ParseFlags.TimeZoneUsed;
3566 result.timeZoneOffset = TimeSpan.Zero;
3567 }
3568 break;
3569 }
3570 case '%':
3571 if (format.Index >= format.Value.Length - 1 || format.Value[format.Index + 1] == '%')
3572 {
3573 result.SetBadFormatSpecifierFailure(format.Value);
3574 return false;
3575 }
3576 break;
3577 case '\\':
3578 if (format.GetNext())
3579 {
3580 if (!str.Match(format.GetChar()))
3581 {
3582 result.SetBadDateTimeFailure();
3583 return false;
3584 }
3585 break;
3586 }
3587 result.SetBadFormatSpecifierFailure(format.Value);
3588 return false;
3589 case '.':
3590 if (!str.Match(@char))
3591 {
3592 if (!format.GetNext() || !format.Match('F'))
3593 {
3594 result.SetBadDateTimeFailure();
3595 return false;
3596 }
3597 format.GetRepeatCount();
3598 }
3599 break;
3600 default:
3601 if (@char == ' ')
3602 {
3603 if (!parseInfo.fAllowInnerWhite && !str.Match(@char))
3604 {
3605 if (parseInfo.fAllowTrailingWhite && format.GetNext() && ParseByFormat(ref str, ref format, ref parseInfo, dtfi, ref result))
3606 {
3607 return true;
3608 }
3609 result.SetBadDateTimeFailure();
3610 return false;
3611 }
3612 }
3613 else if (format.MatchSpecifiedWord("GMT"))
3614 {
3615 format.Index += "GMT".Length - 1;
3616 result.flags |= ParseFlags.TimeZoneUsed;
3617 result.timeZoneOffset = TimeSpan.Zero;
3618 if (!str.Match("GMT"))
3619 {
3620 result.SetBadDateTimeFailure();
3621 return false;
3622 }
3623 }
3624 else if (!str.Match(@char))
3625 {
3626 result.SetBadDateTimeFailure();
3627 return false;
3628 }
3629 break;
3630 }
3631 return true;
3632 }
static bool ParseJapaneseEraStart(ref __DTString str, DateTimeFormatInfo dtfi)
static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref double result)
static bool MatchEraName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static bool GetTimeZoneName(ref __DTString str)
static bool ParseDigits(ref __DTString str, int digitLen, out int result)
static bool ParseTimeZoneOffset(ref __DTString str, int len, ref TimeSpan result)
static bool CheckNewValue(ref int currentValue, int newValue, char patternChar, ref DateTimeResult result)
static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
static bool TryParseQuoteString(ReadOnlySpan< char > format, int pos, StringBuilder result, out int returnValue)
static bool ParseByFormat(ref __DTString str, ref __DTString format, ref ParsingInfo parseInfo, DateTimeFormatInfo dtfi, ref DateTimeResult result)
static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static string GetStringAndRelease(StringBuilder sb)
static void Release(StringBuilder sb)
static StringBuilder Acquire(int capacity=16)

References System.Text.StringBuilderCache.Acquire(), System.DateTimeParse.CheckNewValue(), System.Globalization.DateTimeFormatInfo.DateSeparator, System.format, System.Text.StringBuilderCache.GetStringAndRelease(), System.DateTimeParse.GetTimeZoneName(), System.L, System.DateTimeParse.MatchAbbreviatedDayName(), System.DateTimeParse.MatchAbbreviatedMonthName(), System.DateTimeParse.MatchAbbreviatedTimeMark(), System.DateTimeParse.MatchDayName(), System.DateTimeParse.MatchEraName(), System.DateTimeParse.MatchMonthName(), System.DateTimeParse.MatchTimeMark(), System.DateTimeParse.ParseByFormat(), System.DateTimeParse.ParseDigits(), System.DateTimeParse.ParseFractionExact(), System.DateTimeParse.ParseJapaneseEraStart(), System.DateTimeParse.ParseTimeZoneOffset(), System.Text.StringBuilderCache.Release(), System.str, System.DateTimeParse.TryParseQuoteString(), and System.TimeSpan.Zero.

Referenced by System.DateTimeParse.DoStrictParse(), and System.DateTimeParse.ParseByFormat().