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

◆ GetChars() [2/6]

unsafe override int System.Text.UnicodeEncoding.GetChars ( byte * bytes,
int byteCount,
char * chars,
int charCount,
DecoderNLS baseDecoder )
inlinesealedpackagevirtual

Reimplemented from System.Text.Encoding.

Definition at line 875 of file UnicodeEncoding.cs.

876 {
877 Decoder decoder = (Decoder)baseDecoder;
878 int num = -1;
879 char c = '\0';
880 if (decoder != null)
881 {
882 num = decoder.lastByte;
883 c = decoder.lastChar;
884 }
885 DecoderFallbackBuffer decoderFallbackBuffer = null;
886 byte* ptr = bytes + byteCount;
887 char* ptr2 = chars + charCount;
888 byte* ptr3 = bytes;
889 char* ptr4 = chars;
890 while (bytes < ptr)
891 {
892 if ((bigEndian ^ BitConverter.IsLittleEndian) && ((ulong)chars & 7uL) == 0L && num == -1 && c == '\0')
893 {
894 ulong* ptr5 = (ulong*)(bytes - 7 + ((ptr - bytes >> 1 < ptr2 - chars) ? (ptr - bytes) : (ptr2 - chars << 1)));
895 ulong* ptr6 = (ulong*)bytes;
896 ulong* ptr7 = (ulong*)chars;
897 while (ptr6 < ptr5)
898 {
899 if ((0x8000800080008000uL & *ptr6) != 0L)
900 {
901 ulong num2 = (0xF800F800F800F800uL & *ptr6) ^ 0xD800D800D800D800uL;
902 if ((num2 & 0xFFFF000000000000uL) == 0L || (num2 & 0xFFFF00000000L) == 0L || (num2 & 0xFFFF0000u) == 0L || (num2 & 0xFFFF) == 0L)
903 {
904 long num3 = -287953294993589248L & (long)(*ptr6);
905 if (!BitConverter.IsLittleEndian)
906 {
907 }
908 if (num3 != -2593835887162763264L)
909 {
910 break;
911 }
912 }
913 }
914 Unsafe.WriteUnaligned(ptr7, *ptr6);
915 ptr6++;
916 ptr7++;
917 }
918 chars = (char*)ptr7;
919 bytes = (byte*)ptr6;
920 if (bytes >= ptr)
921 {
922 break;
923 }
924 }
925 if (num < 0)
926 {
927 num = *(bytes++);
928 continue;
929 }
930 char c2 = ((!bigEndian) ? ((char)((*(bytes++) << 8) | num)) : ((char)((num << 8) | *(bytes++))));
931 num = -1;
932 if (c2 >= '\ud800' && c2 <= '\udfff')
933 {
934 if (c2 <= '\udbff')
935 {
936 if (c > '\0')
937 {
938 byte[] array = null;
939 array = ((!bigEndian) ? new byte[2]
940 {
941 (byte)c,
942 (byte)((int)c >> 8)
943 } : new byte[2]
944 {
945 (byte)((int)c >> 8),
946 (byte)c
947 });
948 if (decoderFallbackBuffer == null)
949 {
950 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
951 decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
952 }
953 char* chars2 = chars;
954 bool flag = decoderFallbackBuffer.InternalFallback(array, bytes, ref chars2);
955 chars = chars2;
956 if (!flag)
957 {
958 bytes -= 2;
959 decoderFallbackBuffer.InternalReset();
960 ThrowCharsOverflow(decoder, chars == ptr4);
961 break;
962 }
963 }
964 c = c2;
965 continue;
966 }
967 if (c == '\0')
968 {
969 byte[] array2 = null;
970 array2 = ((!bigEndian) ? new byte[2]
971 {
972 (byte)c2,
973 (byte)((int)c2 >> 8)
974 } : new byte[2]
975 {
976 (byte)((int)c2 >> 8),
977 (byte)c2
978 });
979 if (decoderFallbackBuffer == null)
980 {
981 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
982 decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
983 }
984 char* chars2 = chars;
985 bool flag2 = decoderFallbackBuffer.InternalFallback(array2, bytes, ref chars2);
986 chars = chars2;
987 if (!flag2)
988 {
989 bytes -= 2;
990 decoderFallbackBuffer.InternalReset();
991 ThrowCharsOverflow(decoder, chars == ptr4);
992 break;
993 }
994 continue;
995 }
996 if (chars >= ptr2 - 1)
997 {
998 bytes -= 2;
999 ThrowCharsOverflow(decoder, chars == ptr4);
1000 break;
1001 }
1002 *(chars++) = c;
1003 c = '\0';
1004 }
1005 else if (c > '\0')
1006 {
1007 byte[] array3 = null;
1008 array3 = ((!bigEndian) ? new byte[2]
1009 {
1010 (byte)c,
1011 (byte)((int)c >> 8)
1012 } : new byte[2]
1013 {
1014 (byte)((int)c >> 8),
1015 (byte)c
1016 });
1017 if (decoderFallbackBuffer == null)
1018 {
1019 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1020 decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
1021 }
1022 char* chars2 = chars;
1023 bool flag3 = decoderFallbackBuffer.InternalFallback(array3, bytes, ref chars2);
1024 chars = chars2;
1025 if (!flag3)
1026 {
1027 bytes -= 2;
1028 decoderFallbackBuffer.InternalReset();
1029 ThrowCharsOverflow(decoder, chars == ptr4);
1030 break;
1031 }
1032 c = '\0';
1033 }
1034 if (chars >= ptr2)
1035 {
1036 bytes -= 2;
1037 ThrowCharsOverflow(decoder, chars == ptr4);
1038 break;
1039 }
1040 *(chars++) = c2;
1041 }
1042 if (decoder == null || decoder.MustFlush)
1043 {
1044 if (c > '\0')
1045 {
1046 byte[] array4 = null;
1047 array4 = ((!bigEndian) ? new byte[2]
1048 {
1049 (byte)c,
1050 (byte)((int)c >> 8)
1051 } : new byte[2]
1052 {
1053 (byte)((int)c >> 8),
1054 (byte)c
1055 });
1056 if (decoderFallbackBuffer == null)
1057 {
1058 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1059 decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
1060 }
1061 char* chars2 = chars;
1062 bool flag4 = decoderFallbackBuffer.InternalFallback(array4, bytes, ref chars2);
1063 chars = chars2;
1064 if (!flag4)
1065 {
1066 bytes -= 2;
1067 if (num >= 0)
1068 {
1069 bytes--;
1070 }
1071 decoderFallbackBuffer.InternalReset();
1072 ThrowCharsOverflow(decoder, chars == ptr4);
1073 bytes += 2;
1074 if (num >= 0)
1075 {
1076 bytes++;
1077 }
1078 goto IL_04df;
1079 }
1080 c = '\0';
1081 }
1082 if (num >= 0)
1083 {
1084 if (decoderFallbackBuffer == null)
1085 {
1086 decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1087 decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
1088 }
1089 char* chars2 = chars;
1090 bool flag5 = decoderFallbackBuffer.InternalFallback(new byte[1] { (byte)num }, bytes, ref chars2);
1091 chars = chars2;
1092 if (!flag5)
1093 {
1094 bytes--;
1095 decoderFallbackBuffer.InternalReset();
1096 ThrowCharsOverflow(decoder, chars == ptr4);
1097 bytes++;
1098 }
1099 else
1100 {
1101 num = -1;
1102 }
1103 }
1104 }
1105 goto IL_04df;
1106 IL_04df:
1107 if (decoder != null)
1108 {
1109 decoder._bytesUsed = (int)(bytes - ptr3);
1110 decoder.lastChar = c;
1111 decoder.lastByte = num;
1112 }
1113 return (int)(chars - ptr4);
1114 }
DecoderFallback decoderFallback
Definition Encoding.cs:343

References System.array, System.Text.UnicodeEncoding.bigEndian, System.byteCount, System.bytes, System.charCount, System.chars, System.Text.DecoderFallback.CreateFallbackBuffer(), System.Text.Encoding.decoderFallback, System.Text.DecoderNLS.FallbackBuffer, System.Text.DecoderFallbackBuffer.InternalFallback(), System.Text.DecoderFallbackBuffer.InternalInitialize(), System.Text.DecoderFallbackBuffer.InternalReset(), System.BitConverter.IsLittleEndian, System.L, System.Text.UnicodeEncoding.Decoder.lastByte, System.Text.UnicodeEncoding.Decoder.lastChar, System.Text.DecoderNLS.MustFlush, and System.Text.Encoding.ThrowCharsOverflow().