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

◆ DetectEncoding()

void System.IO.StreamReader.DetectEncoding ( )
inlineprivateinherited

Definition at line 447 of file StreamReader.cs.

448 {
449 if (_byteLen < 2)
450 {
451 return;
452 }
453 _detectEncoding = false;
454 bool flag = false;
455 if (_byteBuffer[0] == 254 && _byteBuffer[1] == byte.MaxValue)
456 {
459 flag = true;
460 }
461 else if (_byteBuffer[0] == byte.MaxValue && _byteBuffer[1] == 254)
462 {
463 if (_byteLen < 4 || _byteBuffer[2] != 0 || _byteBuffer[3] != 0)
464 {
467 flag = true;
468 }
469 else
470 {
473 flag = true;
474 }
475 }
476 else if (_byteLen >= 3 && _byteBuffer[0] == 239 && _byteBuffer[1] == 187 && _byteBuffer[2] == 191)
477 {
480 flag = true;
481 }
482 else if (_byteLen >= 4 && _byteBuffer[0] == 0 && _byteBuffer[1] == 0 && _byteBuffer[2] == 254 && _byteBuffer[3] == byte.MaxValue)
483 {
484 _encoding = new UTF32Encoding(bigEndian: true, byteOrderMark: true);
486 flag = true;
487 }
488 else if (_byteLen == 2)
489 {
490 _detectEncoding = true;
491 }
492 if (flag)
493 {
495 int maxCharCount = _encoding.GetMaxCharCount(_byteBuffer.Length);
496 if (maxCharCount > _maxCharsPerBuffer)
497 {
498 _charBuffer = new char[maxCharCount];
499 }
500 _maxCharsPerBuffer = maxCharCount;
501 }
502 }
readonly byte[] _byteBuffer
static Encoding BigEndianUnicode
Definition Encoding.cs:521
static Encoding Unicode
Definition Encoding.cs:519
static Encoding UTF8
Definition Encoding.cs:526
int GetMaxCharCount(int byteCount)
static Encoding UTF32
Definition Encoding.cs:528
virtual Decoder GetDecoder()
Definition Encoding.cs:1004

References System.IO.StreamReader._byteBuffer, System.IO.StreamReader._byteLen, System.IO.StreamReader._charBuffer, System.IO.StreamReader._decoder, System.IO.StreamReader._detectEncoding, System.IO.StreamReader._encoding, System.IO.StreamReader._maxCharsPerBuffer, System.Text.Encoding.BigEndianUnicode, System.IO.StreamReader.CompressBuffer(), System.Text.Encoding.GetDecoder(), System.Text.Encoding.GetMaxCharCount(), System.Text.Encoding.Unicode, System.Text.Encoding.UTF32, and System.Text.Encoding.UTF8.

Referenced by System.IO.StreamReader.ReadAsyncInternal(), System.IO.StreamReader.ReadBuffer(), System.IO.StreamReader.ReadBuffer(), and System.IO.StreamReader.ReadBufferAsync().