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

◆ GetBytes() [2/9]

unsafe override int System.Text.GB18030Encoding.GetBytes ( char * chars,
int charCount,
byte * bytes,
int byteCount,
System::Text::EncoderNLS encoder )
inlinevirtual

Reimplemented from System.Text.DBCSCodePageEncoding.

Definition at line 146 of file GB18030Encoding.cs.

147 {
148 char c = '\0';
149 if (encoder != null)
150 {
151 c = encoder.charLeftOver;
152 }
153 EncodingByteBuffer encodingByteBuffer = new EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount);
154 while (true)
155 {
156 if (encodingByteBuffer.MoreData)
157 {
158 char nextChar = encodingByteBuffer.GetNextChar();
159 if (c != 0)
160 {
161 if (!char.IsLowSurrogate(nextChar))
162 {
163 encodingByteBuffer.MovePrevious(bThrow: false);
164 if (encodingByteBuffer.Fallback(c))
165 {
166 c = '\0';
167 continue;
168 }
169 c = '\0';
170 }
171 else
172 {
173 int num = (c - 55296 << 10) + (nextChar - 56320);
174 byte b = (byte)(num % 10 + 48);
175 num /= 10;
176 byte b2 = (byte)(num % 126 + 129);
177 num /= 126;
178 byte b3 = (byte)(num % 10 + 48);
179 num /= 10;
180 c = '\0';
181 if (encodingByteBuffer.AddByte((byte)(num + 144), b3, b2, b))
182 {
183 c = '\0';
184 continue;
185 }
186 encodingByteBuffer.MovePrevious(bThrow: false);
187 }
188 }
189 else if (nextChar <= '\u007f')
190 {
191 if (encodingByteBuffer.AddByte((byte)nextChar))
192 {
193 continue;
194 }
195 }
196 else
197 {
198 if (char.IsHighSurrogate(nextChar))
199 {
200 c = nextChar;
201 continue;
202 }
203 if (char.IsLowSurrogate(nextChar))
204 {
205 if (encodingByteBuffer.Fallback(nextChar))
206 {
207 continue;
208 }
209 }
210 else
211 {
212 ushort num2 = mapUnicodeToBytes[(int)nextChar];
213 if (Is4Byte(nextChar))
214 {
215 byte b4 = (byte)(num2 % 10 + 48);
216 num2 /= 10;
217 byte b5 = (byte)(num2 % 126 + 129);
218 num2 /= 126;
219 byte b6 = (byte)(num2 % 10 + 48);
220 num2 /= 10;
221 if (encodingByteBuffer.AddByte((byte)(num2 + 129), b6, b5, b4))
222 {
223 continue;
224 }
225 }
226 else if (encodingByteBuffer.AddByte((byte)(num2 >> 8), (byte)(num2 & 0xFFu)))
227 {
228 continue;
229 }
230 }
231 }
232 }
233 if ((encoder != null && !encoder.MustFlush) || c <= '\0')
234 {
235 break;
236 }
237 encodingByteBuffer.Fallback(c);
238 c = '\0';
239 }
240 if (encoder != null)
241 {
242 if (bytes != null)
243 {
244 encoder.charLeftOver = c;
245 }
246 encoder.m_charsUsed = encodingByteBuffer.CharsUsed;
247 }
248 return encodingByteBuffer.Count;
249 }
unsafe bool Is4Byte(char charTest)

References System.Text.Encoding.EncodingByteBuffer.AddByte(), System.byteCount, System.bytes, System.charCount, System.chars, System.Text.Encoding.EncodingByteBuffer.CharsUsed, System.Text.Encoding.EncodingByteBuffer.Count, System.Text.Encoding.EncodingByteBuffer.GetNextChar(), System.Text.GB18030Encoding.Is4Byte(), System.Text.DBCSCodePageEncoding.mapUnicodeToBytes, System.Text.Encoding.EncodingByteBuffer.MoreData, and System.Text.Encoding.EncodingByteBuffer.MovePrevious().

Referenced by System.Text.GB18030Encoding.GetByteCount().