Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DecoderNLS.cs
Go to the documentation of this file.
2
3namespace System.Text;
4
5internal class DecoderNLS : Decoder, ISerializable
6{
8
9 protected bool m_mustFlush;
10
11 internal bool m_throwOnOverflow;
12
13 internal int m_bytesUsed;
14
16
18
20
22
24 {
25 get
26 {
27 if (m_fallbackBuffer == null)
28 {
29 if (m_fallback != null)
30 {
32 }
33 else
34 {
36 }
37 }
38 return m_fallbackBuffer;
39 }
40 }
41
42 public bool MustFlush => m_mustFlush;
43
44 internal virtual bool HasState => false;
45
46 internal DecoderNLS(EncodingNLS encoding)
47 {
48 m_encoding = encoding;
50 Reset();
51 }
52
57
58 public override void Reset()
59 {
60 if (m_fallbackBuffer != null)
61 {
63 }
64 }
65
66 public override int GetCharCount(byte[] bytes, int index, int count)
67 {
68 return GetCharCount(bytes, index, count, flush: false);
69 }
70
71 public unsafe override int GetCharCount(byte[] bytes, int index, int count, bool flush)
72 {
73 if (bytes == null)
74 {
76 }
77 if (index < 0 || count < 0)
78 {
80 }
81 if (bytes.Length - index < count)
82 {
84 }
85 if (bytes.Length == 0)
86 {
87 bytes = new byte[1];
88 }
89 fixed (byte* ptr = &bytes[0])
90 {
91 return GetCharCount(ptr + index, count, flush);
92 }
93 }
94
95 public unsafe override int GetCharCount(byte* bytes, int count, bool flush)
96 {
97 if (bytes == null)
98 {
100 }
101 if (count < 0)
102 {
104 }
106 m_throwOnOverflow = true;
107 return m_encoding.GetCharCount(bytes, count, this);
108 }
109
110 public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
111 {
113 }
114
115 public unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, bool flush)
116 {
117 if (bytes == null || chars == null)
118 {
119 throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", System.SR.ArgumentNull_Array);
120 }
121 if (byteIndex < 0 || byteCount < 0)
122 {
123 throw new ArgumentOutOfRangeException((byteIndex < 0) ? "byteIndex" : "byteCount", System.SR.ArgumentOutOfRange_NeedNonNegNum);
124 }
125 if (bytes.Length - byteIndex < byteCount)
126 {
128 }
130 {
132 }
133 if (bytes.Length == 0)
134 {
135 bytes = new byte[1];
136 }
138 if (chars.Length == 0)
139 {
140 chars = new char[1];
141 }
142 fixed (byte* ptr = &bytes[0])
143 {
144 fixed (char* ptr2 = &chars[0])
145 {
147 }
148 }
149 }
150
151 public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount, bool flush)
152 {
153 if (chars == null || bytes == null)
154 {
155 throw new ArgumentNullException((chars == null) ? "chars" : "bytes", System.SR.ArgumentNull_Array);
156 }
157 if (byteCount < 0 || charCount < 0)
158 {
159 throw new ArgumentOutOfRangeException((byteCount < 0) ? "byteCount" : "charCount", System.SR.ArgumentOutOfRange_NeedNonNegNum);
160 }
162 m_throwOnOverflow = true;
164 }
165
166 public unsafe override 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)
167 {
168 if (bytes == null || chars == null)
169 {
170 throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", System.SR.ArgumentNull_Array);
171 }
172 if (byteIndex < 0 || byteCount < 0)
173 {
174 throw new ArgumentOutOfRangeException((byteIndex < 0) ? "byteIndex" : "byteCount", System.SR.ArgumentOutOfRange_NeedNonNegNum);
175 }
176 if (charIndex < 0 || charCount < 0)
177 {
178 throw new ArgumentOutOfRangeException((charIndex < 0) ? "charIndex" : "charCount", System.SR.ArgumentOutOfRange_NeedNonNegNum);
179 }
180 if (bytes.Length - byteIndex < byteCount)
181 {
183 }
184 if (chars.Length - charIndex < charCount)
185 {
187 }
188 if (bytes.Length == 0)
189 {
190 bytes = new byte[1];
191 }
192 if (chars.Length == 0)
193 {
194 chars = new char[1];
195 }
196 fixed (byte* ptr = &bytes[0])
197 {
198 fixed (char* ptr2 = &chars[0])
199 {
200 Convert(ptr + byteIndex, byteCount, ptr2 + charIndex, charCount, flush, out bytesUsed, out charsUsed, out completed);
201 }
202 }
203 }
204
205 public unsafe override void Convert(byte* bytes, int byteCount, char* chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
206 {
207 if (chars == null || bytes == null)
208 {
209 throw new ArgumentNullException((chars == null) ? "chars" : "bytes", System.SR.ArgumentNull_Array);
210 }
211 if (byteCount < 0 || charCount < 0)
212 {
213 throw new ArgumentOutOfRangeException((byteCount < 0) ? "byteCount" : "charCount", System.SR.ArgumentOutOfRange_NeedNonNegNum);
214 }
216 m_throwOnOverflow = false;
217 m_bytesUsed = 0;
218 charsUsed = m_encoding.GetChars(bytes, byteCount, chars, charCount, this);
219 bytesUsed = m_bytesUsed;
220 completed = bytesUsed == byteCount && (!flush || !HasState) && (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0);
221 }
222
223 internal void ClearMustFlush()
224 {
225 m_mustFlush = false;
226 }
227}
static string ArgumentOutOfRange_Index
Definition SR.cs:30
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()
override void Reset()
Definition DecoderNLS.cs:33
EncodingNLS m_encoding
Definition DecoderNLS.cs:7
virtual bool HasState
Definition DecoderNLS.cs:22
unsafe override void Convert(byte *bytes, int byteCount, char *chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
unsafe override int GetCharCount(byte *bytes, int count, bool flush)
Definition DecoderNLS.cs:95
DecoderNLS(EncodingNLS encoding)
Definition DecoderNLS.cs:46
DecoderFallbackBuffer m_fallbackBuffer
Definition DecoderNLS.cs:17
DecoderFallback m_fallback
Definition DecoderNLS.cs:15
override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
new DecoderFallbackBuffer FallbackBuffer
Definition DecoderNLS.cs:24
new DecoderFallback Fallback
Definition DecoderNLS.cs:19
unsafe override int GetCharCount(byte[] bytes, int index, int count, bool flush)
Definition DecoderNLS.cs:71
unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, bool flush)
unsafe override 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)
override int GetCharCount(byte[] bytes, int index, int count)
Definition DecoderNLS.cs:66
unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount, bool flush)
unsafe int GetCharCount(byte *bytes, int count, System.Text.DecoderNLS decoder)
unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, System.Text.DecoderNLS decoder)
DecoderFallback DecoderFallback
Definition Encoding.cs:480
void GetObjectData(SerializationInfo info, StreamingContext context)