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

◆ TryDetectEncoding()

static bool System.Net.Http.HttpContent.TryDetectEncoding ( ArraySegment< byte > buffer,
[NotNullWhen(true)] out Encoding encoding,
out int preambleLength )
inlinestaticprivateinherited

Definition at line 807 of file HttpContent.cs.

808 {
809 byte[] array = buffer.Array;
810 int offset = buffer.Offset;
811 int count = buffer.Count;
812 if (count >= 2)
813 {
814 switch ((array[offset] << 8) | array[offset + 1])
815 {
816 case 61371:
817 if (count >= 3 && array[offset + 2] == 191)
818 {
819 encoding = Encoding.UTF8;
820 preambleLength = 3;
821 return true;
822 }
823 break;
824 case 65534:
825 if (count >= 4 && array[offset + 2] == 0 && array[offset + 3] == 0)
826 {
827 encoding = Encoding.UTF32;
828 preambleLength = 4;
829 }
830 else
831 {
832 encoding = Encoding.Unicode;
833 preambleLength = 2;
834 }
835 return true;
836 case 65279:
837 encoding = Encoding.BigEndianUnicode;
838 preambleLength = 2;
839 return true;
840 }
841 }
842 encoding = null;
843 preambleLength = 0;
844 return false;
845 }
static Encoding BigEndianUnicode
Definition Encoding.cs:521
static Encoding Unicode
Definition Encoding.cs:519
static Encoding UTF8
Definition Encoding.cs:526
static Encoding UTF32
Definition Encoding.cs:528

References System.array, System.Text.Encoding.BigEndianUnicode, System.buffer, System.count, System.offset, System.Text.Encoding.Unicode, System.Text.Encoding.UTF32, and System.Text.Encoding.UTF8.

Referenced by System.Net.Http.HttpContent.ReadBufferAsString().