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

◆ GetByteCount() [4/7]

unsafe override int System.Text.Base64Encoding.GetByteCount ( char[] chars,
int index,
int count )
inline

Definition at line 59 of file Base64Encoding.cs.

60 {
61 if (chars == null)
62 {
63 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
64 }
65 if (index < 0)
66 {
67 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("index", System.SR.ValueMustBeNonNegative));
68 }
69 if (index > chars.Length)
70 {
71 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("index", System.SR.Format(System.SR.OffsetExceedsBufferSize, chars.Length)));
72 }
73 if (count < 0)
74 {
75 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", System.SR.ValueMustBeNonNegative));
76 }
77 if (count > chars.Length - index)
78 {
79 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", System.SR.Format(System.SR.SizeExceedsRemainingBufferSpace, chars.Length - index)));
80 }
81 if (count == 0)
82 {
83 return 0;
84 }
85 if (count % 4 != 0)
86 {
88 }
89 fixed (byte* ptr4 = &Char2val[0])
90 {
91 fixed (char* ptr = &chars[index])
92 {
93 int num = 0;
94 char* ptr2 = ptr;
95 for (char* ptr3 = ptr + count; ptr2 < ptr3; ptr2 += 4)
96 {
97 char c = *ptr2;
98 char c2 = ptr2[1];
99 char c3 = ptr2[2];
100 char c4 = ptr2[3];
101 if ((c | c2 | c3 | c4) >= 128)
102 {
103 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.SR.Format(System.SR.XmlInvalidBase64Sequence, new string(ptr2, 0, 4), index + (int)(ptr2 - ptr))));
104 }
105 int v = ptr4[(int)c];
106 int v2 = ptr4[(int)c2];
107 int num2 = ptr4[(int)c3];
108 int num3 = ptr4[(int)c4];
110 {
111 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.SR.Format(System.SR.XmlInvalidBase64Sequence, new string(ptr2, 0, 4), index + (int)(ptr2 - ptr))));
112 }
113 int num4 = ((num3 != 64) ? 3 : ((num2 == 64) ? 1 : 2));
114 num += num4;
115 }
116 return num;
117 }
118 }
119 }
static string XmlInvalidBase64Sequence
Definition SR.cs:334
static string XmlInvalidBase64Length
Definition SR.cs:332
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ValueMustBeNonNegative
Definition SR.cs:296
static string SizeExceedsRemainingBufferSpace
Definition SR.cs:324
static string OffsetExceedsBufferSize
Definition SR.cs:322
Definition SR.cs:7
bool IsValidTailBytes(int v3, int v4)
static ReadOnlySpan< byte > Char2val
bool IsValidLeadBytes(int v1, int v2, int v3, int v4)

References System.Text.Base64Encoding.Char2val, System.chars, System.count, System.Runtime.Serialization.Dictionary, System.SR.Format(), System.index, System.Text.Base64Encoding.IsValidLeadBytes(), System.Text.Base64Encoding.IsValidTailBytes(), System.SR.OffsetExceedsBufferSize, System.SR.SizeExceedsRemainingBufferSpace, System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(), System.SR.ValueMustBeNonNegative, System.SR.XmlInvalidBase64Length, and System.SR.XmlInvalidBase64Sequence.