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

◆ IsValidCustomTimeFormat()

static bool System.DateTimeFormat.IsValidCustomTimeFormat ( ReadOnlySpan< char > format,
bool throwOnError )
inlinestaticpackage

Definition at line 746 of file DateTimeFormat.cs.

747 {
748 int length = format.Length;
749 int i = 0;
750 while (i < length)
751 {
752 switch (format[i])
753 {
754 case '\\':
755 if (i == length - 1)
756 {
757 if (throwOnError)
758 {
759 throw new FormatException(SR.Format_InvalidString);
760 }
761 return false;
762 }
763 i += 2;
764 break;
765 case '"':
766 case '\'':
767 {
768 char c;
769 for (c = format[i++]; i < length && format[i] != c; i++)
770 {
771 }
772 if (i >= length)
773 {
774 if (throwOnError)
775 {
776 throw new FormatException(SR.Format(SR.Format_BadQuote, c));
777 }
778 return false;
779 }
780 i++;
781 break;
782 }
783 case '/':
784 case 'M':
785 case 'd':
786 case 'k':
787 case 'y':
788 case 'z':
789 if (throwOnError)
790 {
791 throw new FormatException(SR.Format_InvalidString);
792 }
793 return false;
794 default:
795 i++;
796 break;
797 }
798 }
799 return true;
800 }

References System.SR.Format(), System.format, System.SR.Format_BadQuote, System.SR.Format_InvalidString, and System.length.

Referenced by System.TimeOnly.ToString(), and System.TimeOnly.TryFormat().