Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Decoder.cs
Go to the documentation of this file.
2
3namespace System.Text;
4
5public abstract class Decoder
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 byte[] bytes = Array.Empty<byte>();
56 char[] chars = new char[GetCharCount(bytes, 0, 0, flush: true)];
57 GetChars(bytes, 0, 0, chars, 0, flush: true);
59 }
60
61 public abstract int GetCharCount(byte[] bytes, int index, int count);
62
63 public virtual int GetCharCount(byte[] bytes, int index, int count, bool flush)
64 {
65 return GetCharCount(bytes, index, count);
66 }
67
68 [CLSCompliant(false)]
69 public unsafe virtual int GetCharCount(byte* bytes, int count, bool flush)
70 {
71 if (bytes == null)
72 {
74 }
75 if (count < 0)
76 {
78 }
79 byte[] array = new byte[count];
80 for (int i = 0; i < count; i++)
81 {
82 array[i] = bytes[i];
83 }
84 return GetCharCount(array, 0, count);
85 }
86
87 public unsafe virtual int GetCharCount(ReadOnlySpan<byte> bytes, bool flush)
88 {
89 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
90 {
91 return GetCharCount(bytes2, bytes.Length, flush);
92 }
93 }
94
95 public abstract int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex);
96
97 public virtual int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, bool flush)
98 {
100 }
101
102 [CLSCompliant(false)]
103 public unsafe virtual int GetChars(byte* bytes, int byteCount, char* chars, int charCount, bool flush)
104 {
105 if (chars == null || bytes == null)
106 {
107 throw new ArgumentNullException((chars == null) ? "chars" : "bytes", SR.ArgumentNull_Array);
108 }
109 if (byteCount < 0 || charCount < 0)
110 {
111 throw new ArgumentOutOfRangeException((byteCount < 0) ? "byteCount" : "charCount", SR.ArgumentOutOfRange_NeedNonNegNum);
112 }
113 byte[] array = new byte[byteCount];
114 for (int i = 0; i < byteCount; i++)
115 {
116 array[i] = bytes[i];
117 }
118 char[] array2 = new char[charCount];
119 int chars2 = GetChars(array, 0, byteCount, array2, 0, flush);
120 if (chars2 < charCount)
121 {
122 charCount = chars2;
123 }
124 for (int i = 0; i < charCount; i++)
125 {
126 chars[i] = array2[i];
127 }
128 return charCount;
129 }
130
131 public unsafe virtual int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars, bool flush)
132 {
133 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
134 {
135 fixed (char* chars2 = &MemoryMarshal.GetNonNullPinnableReference(chars))
136 {
137 return GetChars(bytes2, bytes.Length, chars2, chars.Length, flush);
138 }
139 }
140 }
141
142 public virtual void Convert(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
143 {
144 if (bytes == null || chars == null)
145 {
146 throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", SR.ArgumentNull_Array);
147 }
148 if (byteIndex < 0 || byteCount < 0)
149 {
150 throw new ArgumentOutOfRangeException((byteIndex < 0) ? "byteIndex" : "byteCount", SR.ArgumentOutOfRange_NeedNonNegNum);
151 }
152 if (charIndex < 0 || charCount < 0)
153 {
154 throw new ArgumentOutOfRangeException((charIndex < 0) ? "charIndex" : "charCount", SR.ArgumentOutOfRange_NeedNonNegNum);
155 }
156 if (bytes.Length - byteIndex < byteCount)
157 {
159 }
160 if (chars.Length - charIndex < charCount)
161 {
163 }
164 for (bytesUsed = byteCount; bytesUsed > 0; bytesUsed /= 2)
165 {
166 if (GetCharCount(bytes, byteIndex, bytesUsed, flush) <= charCount)
167 {
168 charsUsed = GetChars(bytes, byteIndex, bytesUsed, chars, charIndex, flush);
169 completed = bytesUsed == byteCount && (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0);
170 return;
171 }
172 flush = false;
173 }
175 }
176
177 [CLSCompliant(false)]
178 public unsafe virtual void Convert(byte* bytes, int byteCount, char* chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
179 {
180 if (chars == null || bytes == null)
181 {
182 throw new ArgumentNullException((chars == null) ? "chars" : "bytes", SR.ArgumentNull_Array);
183 }
184 if (byteCount < 0 || charCount < 0)
185 {
186 throw new ArgumentOutOfRangeException((byteCount < 0) ? "byteCount" : "charCount", SR.ArgumentOutOfRange_NeedNonNegNum);
187 }
188 for (bytesUsed = byteCount; bytesUsed > 0; bytesUsed /= 2)
189 {
190 if (GetCharCount(bytes, bytesUsed, flush) <= charCount)
191 {
192 charsUsed = GetChars(bytes, bytesUsed, chars, charCount, flush);
193 completed = bytesUsed == byteCount && (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0);
194 return;
195 }
196 flush = false;
197 }
199 }
200
201 public unsafe virtual void Convert(ReadOnlySpan<byte> bytes, Span<char> chars, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
202 {
203 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
204 {
205 fixed (char* chars2 = &MemoryMarshal.GetNonNullPinnableReference(chars))
206 {
207 Convert(bytes2, bytes.Length, chars2, chars.Length, flush, out bytesUsed, out charsUsed, out completed);
208 }
209 }
210 }
211}
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
static DecoderFallback ReplacementFallback
DecoderFallbackBuffer CreateFallbackBuffer()
virtual unsafe void Convert(byte *bytes, int byteCount, char *chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
Definition Decoder.cs:178
DecoderFallbackBuffer FallbackBuffer
Definition Decoder.cs:33
DecoderFallback _fallback
Definition Decoder.cs:7
virtual unsafe void Convert(ReadOnlySpan< byte > bytes, Span< char > chars, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
Definition Decoder.cs:201
virtual void Convert(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
Definition Decoder.cs:142
virtual unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, bool flush)
Definition Decoder.cs:103
virtual int GetCharCount(byte[] bytes, int index, int count, bool flush)
Definition Decoder.cs:63
virtual void Reset()
Definition Decoder.cs:53
DecoderFallback? Fallback
Definition Decoder.cs:12
DecoderFallbackBuffer _fallbackBuffer
Definition Decoder.cs:9
bool InternalHasFallbackBuffer
Definition Decoder.cs:51
virtual unsafe int GetCharCount(byte *bytes, int count, bool flush)
Definition Decoder.cs:69
virtual unsafe int GetCharCount(ReadOnlySpan< byte > bytes, bool flush)
Definition Decoder.cs:87
virtual unsafe int GetChars(ReadOnlySpan< byte > bytes, Span< char > chars, bool flush)
Definition Decoder.cs:131
int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
virtual int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, bool flush)
Definition Decoder.cs:97
int GetCharCount(byte[] bytes, int index, int count)