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