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

◆ ProcessBuffer()

static ArraySegment< byte > System.Xml.EncodingStreamWrapper.ProcessBuffer ( byte[] buffer,
int offset,
int count,
Encoding encoding )
inlinestaticpackage

Definition at line 522 of file EncodingStreamWrapper.cs.

523 {
524 if (count < 4)
525 {
527 }
528 try
529 {
530 SupportedEncoding supportedEncoding = GetSupportedEncoding(encoding);
531 int preserve;
532 SupportedEncoding supportedEncoding2 = ReadBOMEncoding(buffer[offset], buffer[offset + 1], buffer[offset + 2], buffer[offset + 3], encoding == null, out preserve);
533 if (supportedEncoding != SupportedEncoding.None && supportedEncoding != supportedEncoding2)
534 {
536 }
537 offset += 4 - preserve;
538 count -= 4 - preserve;
539 if (supportedEncoding2 == SupportedEncoding.UTF8)
540 {
541 if (buffer[offset + 1] != 63 || buffer[offset] != 60)
542 {
543 return new ArraySegment<byte>(buffer, offset, count);
544 }
546 return new ArraySegment<byte>(buffer, offset, count);
547 }
549 int byteCount = Math.Min(count, 256);
550 char[] chars = new char[safeEncoding.GetMaxCharCount(byteCount)];
551 int chars2 = safeEncoding.GetChars(buffer, offset, byteCount, chars, 0);
552 byte[] array = new byte[s_validatingUTF8.GetMaxByteCount(chars2)];
553 int bytes = s_validatingUTF8.GetBytes(chars, 0, chars2, array, 0);
554 if (array[1] == 63 && array[0] == 60)
555 {
557 }
558 else if (supportedEncoding == SupportedEncoding.None)
559 {
561 }
562 return new ArraySegment<byte>(s_validatingUTF8.GetBytes(GetEncoding(supportedEncoding2).GetChars(buffer, offset, count)));
563 }
565 {
567 }
568 }
static string XmlDeclarationRequired
Definition SR.cs:362
static string XmlInvalidBytes
Definition SR.cs:416
static string UnexpectedEndOfFile
Definition SR.cs:292
Definition SR.cs:7
static Encoding GetSafeEncoding(SupportedEncoding e)
static void CheckUTF8DeclarationEncoding(byte[] buffer, int offset, int count, SupportedEncoding e, SupportedEncoding expectedEnc)
static void ThrowExpectedEncodingMismatch(SupportedEncoding expEnc, SupportedEncoding actualEnc)
SupportedEncoding ReadBOMEncoding(bool notOutOfBand)
static Encoding GetEncoding(SupportedEncoding e)
static readonly UTF8Encoding s_validatingUTF8
static SupportedEncoding GetSupportedEncoding(Encoding encoding)

References System.array, System.buffer, System.byteCount, System.bytes, System.chars, System.Xml.EncodingStreamWrapper.CheckUTF8DeclarationEncoding(), System.count, System.Xml.Dictionary, System.Xml.EncodingStreamWrapper.GetEncoding(), System.Xml.EncodingStreamWrapper.GetSafeEncoding(), System.Xml.EncodingStreamWrapper.GetSupportedEncoding(), System.Math.Min(), System.offset, System.Xml.EncodingStreamWrapper.ReadBOMEncoding(), System.Xml.EncodingStreamWrapper.s_validatingUTF8, System.Xml.EncodingStreamWrapper.ThrowExpectedEncodingMismatch(), System.SR.UnexpectedEndOfFile, System.SR.XmlDeclarationRequired, System.Xml.XmlException, and System.SR.XmlInvalidBytes.

Referenced by System.Xml.XmlUTF8TextReader.SetInput().