Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Encoder.cs
Go to the documentation of this file.
2
3namespace System.Text;
4
5public abstract class Encoder
6{
8
10
12 {
13 get
14 {
15 return _fallback;
16 }
17 set
18 {
19 if (value == null)
20 {
21 throw new ArgumentNullException("value");
22 }
23 if (_fallbackBuffer != null && _fallbackBuffer.Remaining > 0)
24 {
26 }
28 _fallbackBuffer = null;
29 }
30 }
31
33 {
34 get
35 {
36 if (_fallbackBuffer == null)
37 {
38 if (_fallback != null)
39 {
41 }
42 else
43 {
45 }
46 }
47 return _fallbackBuffer;
48 }
49 }
50
52
53 public virtual void Reset()
54 {
55 char[] chars = Array.Empty<char>();
56 byte[] bytes = new byte[GetByteCount(chars, 0, 0, flush: true)];
57 GetBytes(chars, 0, 0, bytes, 0, flush: true);
58 if (_fallbackBuffer != null)
59 {
61 }
62 }
63
64 public abstract int GetByteCount(char[] chars, int index, int count, bool flush);
65
66 [CLSCompliant(false)]
67 public unsafe virtual int GetByteCount(char* chars, int count, bool flush)
68 {
69 if (chars == null)
70 {
72 }
73 if (count < 0)
74 {
76 }
77 char[] array = new char[count];
78 for (int i = 0; i < count; i++)
79 {
80 array[i] = chars[i];
81 }
82 return GetByteCount(array, 0, count, flush);
83 }
84
85 public unsafe virtual int GetByteCount(ReadOnlySpan<char> chars, bool flush)
86 {
87 fixed (char* chars2 = &MemoryMarshal.GetNonNullPinnableReference(chars))
88 {
89 return GetByteCount(chars2, chars.Length, flush);
90 }
91 }
92
93 public abstract int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, bool flush);
94
95 [CLSCompliant(false)]
96 public unsafe virtual int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, bool flush)
97 {
98 if (bytes == null || chars == null)
99 {
100 throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", SR.ArgumentNull_Array);
101 }
102 if (charCount < 0 || byteCount < 0)
103 {
104 throw new ArgumentOutOfRangeException((charCount < 0) ? "charCount" : "byteCount", SR.ArgumentOutOfRange_NeedNonNegNum);
105 }
106 char[] array = new char[charCount];
107 for (int i = 0; i < charCount; i++)
108 {
109 array[i] = chars[i];
110 }
111 byte[] array2 = new byte[byteCount];
112 int bytes2 = GetBytes(array, 0, charCount, array2, 0, flush);
113 if (bytes2 < byteCount)
114 {
115 byteCount = bytes2;
116 }
117 for (int i = 0; i < byteCount; i++)
118 {
119 bytes[i] = array2[i];
120 }
121 return byteCount;
122 }
123
124 public unsafe virtual int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes, bool flush)
125 {
126 fixed (char* chars2 = &MemoryMarshal.GetNonNullPinnableReference(chars))
127 {
128 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
129 {
130 return GetBytes(chars2, chars.Length, bytes2, bytes.Length, flush);
131 }
132 }
133 }
134
135 public virtual void Convert(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, int byteCount, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
136 {
137 if (chars == null || bytes == null)
138 {
139 throw new ArgumentNullException((chars == null) ? "chars" : "bytes", SR.ArgumentNull_Array);
140 }
141 if (charIndex < 0 || charCount < 0)
142 {
143 throw new ArgumentOutOfRangeException((charIndex < 0) ? "charIndex" : "charCount", SR.ArgumentOutOfRange_NeedNonNegNum);
144 }
145 if (byteIndex < 0 || byteCount < 0)
146 {
147 throw new ArgumentOutOfRangeException((byteIndex < 0) ? "byteIndex" : "byteCount", SR.ArgumentOutOfRange_NeedNonNegNum);
148 }
149 if (chars.Length - charIndex < charCount)
150 {
152 }
153 if (bytes.Length - byteIndex < byteCount)
154 {
156 }
157 for (charsUsed = charCount; charsUsed > 0; charsUsed /= 2)
158 {
159 if (GetByteCount(chars, charIndex, charsUsed, flush) <= byteCount)
160 {
161 bytesUsed = GetBytes(chars, charIndex, charsUsed, bytes, byteIndex, flush);
162 completed = charsUsed == charCount && (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0);
163 return;
164 }
165 flush = false;
166 }
168 }
169
170 [CLSCompliant(false)]
171 public unsafe virtual void Convert(char* chars, int charCount, byte* bytes, int byteCount, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
172 {
173 if (bytes == null || chars == null)
174 {
175 throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", SR.ArgumentNull_Array);
176 }
177 if (charCount < 0 || byteCount < 0)
178 {
179 throw new ArgumentOutOfRangeException((charCount < 0) ? "charCount" : "byteCount", SR.ArgumentOutOfRange_NeedNonNegNum);
180 }
181 for (charsUsed = charCount; charsUsed > 0; charsUsed /= 2)
182 {
183 if (GetByteCount(chars, charsUsed, flush) <= byteCount)
184 {
185 bytesUsed = GetBytes(chars, charsUsed, bytes, byteCount, flush);
186 completed = charsUsed == charCount && (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0);
187 return;
188 }
189 flush = false;
190 }
192 }
193
194 public unsafe virtual void Convert(ReadOnlySpan<char> chars, Span<byte> bytes, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
195 {
196 fixed (char* chars2 = &MemoryMarshal.GetNonNullPinnableReference(chars))
197 {
198 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
199 {
200 Convert(chars2, chars.Length, bytes2, bytes.Length, flush, out charsUsed, out bytesUsed, out completed);
201 }
202 }
203 }
204}
static string Argument_ConversionOverflow
Definition SR.cs:538
static string Argument_FallbackBufferNotEmpty
Definition SR.cs:600
static string ArgumentOutOfRange_IndexCountBuffer
Definition SR.cs:78
static string ArgumentNull_Array
Definition SR.cs:24
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
Definition SR.cs:7
EncoderFallbackBuffer CreateFallbackBuffer()
static EncoderFallback ReplacementFallback
virtual unsafe void Convert(ReadOnlySpan< char > chars, Span< byte > bytes, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
Definition Encoder.cs:194
virtual unsafe int GetByteCount(char *chars, int count, bool flush)
Definition Encoder.cs:67
bool InternalHasFallbackBuffer
Definition Encoder.cs:51
EncoderFallback? Fallback
Definition Encoder.cs:12
int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, bool flush)
virtual void Reset()
Definition Encoder.cs:53
EncoderFallbackBuffer _fallbackBuffer
Definition Encoder.cs:9
EncoderFallback _fallback
Definition Encoder.cs:7
virtual unsafe int GetBytes(char *chars, int charCount, byte *bytes, int byteCount, bool flush)
Definition Encoder.cs:96
virtual unsafe int GetByteCount(ReadOnlySpan< char > chars, bool flush)
Definition Encoder.cs:85
virtual unsafe void Convert(char *chars, int charCount, byte *bytes, int byteCount, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
Definition Encoder.cs:171
EncoderFallbackBuffer FallbackBuffer
Definition Encoder.cs:33
virtual void Convert(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, int byteCount, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
Definition Encoder.cs:135
virtual unsafe int GetBytes(ReadOnlySpan< char > chars, Span< byte > bytes, bool flush)
Definition Encoder.cs:124
int GetByteCount(char[] chars, int index, int count, bool flush)