Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Encoding.cs
Go to the documentation of this file.
6using System.IO;
11
12namespace System.Text;
13
14public abstract class Encoding : ICloneable
15{
16 internal sealed class DefaultEncoder : Encoder, IObjectReference
17 {
18 private readonly Encoding _encoding;
19
20 public DefaultEncoder(Encoding encoding)
21 {
22 _encoding = encoding;
23 }
24
25 public object GetRealObject(StreamingContext context)
26 {
28 }
29
30 public override int GetByteCount(char[] chars, int index, int count, bool flush)
31 {
33 }
34
35 public unsafe override int GetByteCount(char* chars, int count, bool flush)
36 {
38 }
39
40 public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, bool flush)
41 {
43 }
44
45 public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, bool flush)
46 {
48 }
49 }
50
51 internal sealed class DefaultDecoder : Decoder, IObjectReference
52 {
53 private readonly Encoding _encoding;
54
55 public DefaultDecoder(Encoding encoding)
56 {
57 _encoding = encoding;
58 }
59
60 public object GetRealObject(StreamingContext context)
61 {
63 }
64
65 public override int GetCharCount(byte[] bytes, int index, int count)
66 {
67 return GetCharCount(bytes, index, count, flush: false);
68 }
69
70 public override int GetCharCount(byte[] bytes, int index, int count, bool flush)
71 {
73 }
74
75 public unsafe override int GetCharCount(byte* bytes, int count, bool flush)
76 {
78 }
79
80 public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
81 {
83 }
84
85 public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, bool flush)
86 {
88 }
89
90 public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount, bool flush)
91 {
93 }
94 }
95
96 internal sealed class EncodingCharBuffer
97 {
98 private unsafe char* _chars;
99
100 private unsafe readonly char* _charStart;
101
102 private unsafe readonly char* _charEnd;
103
104 private int _charCountResult;
105
106 private readonly Encoding _enc;
107
108 private readonly DecoderNLS _decoder;
109
110 private unsafe readonly byte* _byteStart;
111
112 private unsafe readonly byte* _byteEnd;
113
114 private unsafe byte* _bytes;
115
117
118 internal unsafe bool MoreData => _bytes < _byteEnd;
119
120 internal unsafe int BytesUsed => (int)(_bytes - _byteStart);
121
122 internal int Count => _charCountResult;
123
124 internal unsafe EncodingCharBuffer(Encoding enc, DecoderNLS decoder, char* charStart, int charCount, byte* byteStart, int byteCount)
125 {
126 _enc = enc;
127 _decoder = decoder;
128 _chars = charStart;
129 _charStart = charStart;
130 _charEnd = charStart + charCount;
131 _byteStart = byteStart;
132 _bytes = byteStart;
133 _byteEnd = byteStart + byteCount;
134 if (_decoder == null)
135 {
136 _fallbackBuffer = enc.DecoderFallback.CreateFallbackBuffer();
137 }
138 else
139 {
141 }
143 }
144
145 internal unsafe bool AddChar(char ch, int numBytes)
146 {
147 if (_chars != null)
148 {
149 if (_chars >= _charEnd)
150 {
151 _bytes -= numBytes;
153 return false;
154 }
155 *(_chars++) = ch;
156 }
158 return true;
159 }
160
161 internal bool AddChar(char ch)
162 {
163 return AddChar(ch, 1);
164 }
165
166 internal unsafe void AdjustBytes(int count)
167 {
168 _bytes += count;
169 }
170
171 internal unsafe byte GetNextByte()
172 {
173 if (_bytes >= _byteEnd)
174 {
175 return 0;
176 }
177 return *(_bytes++);
178 }
179
180 internal bool Fallback(byte fallbackByte)
181 {
182 byte[] byteBuffer = new byte[1] { fallbackByte };
183 return Fallback(byteBuffer);
184 }
185
186 internal unsafe bool Fallback(byte[] byteBuffer)
187 {
188 if (_chars != null)
189 {
190 char* chars = _chars;
192 {
193 _bytes -= byteBuffer.Length;
196 return false;
197 }
198 _charCountResult += (int)(_chars - chars);
199 }
200 else
201 {
203 }
204 return true;
205 }
206 }
207
208 internal sealed class EncodingByteBuffer
209 {
210 private unsafe byte* _bytes;
211
212 private unsafe readonly byte* _byteStart;
213
214 private unsafe readonly byte* _byteEnd;
215
216 private unsafe char* _chars;
217
218 private unsafe readonly char* _charStart;
219
220 private unsafe readonly char* _charEnd;
221
222 private int _byteCountResult;
223
224 private readonly Encoding _enc;
225
226 private readonly EncoderNLS _encoder;
227
229
230 internal unsafe bool MoreData
231 {
232 get
233 {
234 if (fallbackBuffer.Remaining <= 0)
235 {
236 return _chars < _charEnd;
237 }
238 return true;
239 }
240 }
241
242 internal unsafe int CharsUsed => (int)(_chars - _charStart);
243
244 internal int Count => _byteCountResult;
245
270
271 internal unsafe bool AddByte(byte b, int moreBytesExpected)
272 {
273 if (_bytes != null)
274 {
276 {
277 MovePrevious(bThrow: true);
278 return false;
279 }
280 *(_bytes++) = b;
281 }
283 return true;
284 }
285
286 internal bool AddByte(byte b1)
287 {
288 return AddByte(b1, 0);
289 }
290
291 internal bool AddByte(byte b1, byte b2)
292 {
293 return AddByte(b1, b2, 0);
294 }
295
296 internal bool AddByte(byte b1, byte b2, int moreBytesExpected)
297 {
298 if (AddByte(b1, 1 + moreBytesExpected))
299 {
301 }
302 return false;
303 }
304
305 internal unsafe void MovePrevious(bool bThrow)
306 {
308 {
310 }
311 else if (_chars > _charStart)
312 {
313 _chars--;
314 }
315 if (bThrow)
316 {
318 }
319 }
320
321 internal unsafe char GetNextChar()
322 {
324 if (c == '\0' && _chars < _charEnd)
325 {
326 c = *(_chars++);
327 }
328 return c;
329 }
330 }
331
333
334 internal int _codePage;
335
337
338 [OptionalField(VersionAdded = 2)]
339 private bool _isReadOnly = true;
340
342
344
346
348
349 public virtual string BodyName
350 {
351 get
352 {
353 if (_dataItem == null)
354 {
355 GetDataItem();
356 }
357 return _dataItem.BodyName;
358 }
359 }
360
361 public virtual string EncodingName
362 {
363 get
364 {
365 if (_dataItem == null)
366 {
367 GetDataItem();
368 }
369 return _dataItem.DisplayName;
370 }
371 }
372
373 public virtual string HeaderName
374 {
375 get
376 {
377 if (_dataItem == null)
378 {
379 GetDataItem();
380 }
381 return _dataItem.HeaderName;
382 }
383 }
384
385 public virtual string WebName
386 {
387 get
388 {
389 if (_dataItem == null)
390 {
391 GetDataItem();
392 }
393 return _dataItem.WebName;
394 }
395 }
396
397 public virtual int WindowsCodePage
398 {
399 get
400 {
401 if (_dataItem == null)
402 {
403 GetDataItem();
404 }
406 }
407 }
408
409 public virtual bool IsBrowserDisplay
410 {
411 get
412 {
413 if (_dataItem == null)
414 {
415 GetDataItem();
416 }
417 return (_dataItem.Flags & 2) != 0;
418 }
419 }
420
421 public virtual bool IsBrowserSave
422 {
423 get
424 {
425 if (_dataItem == null)
426 {
427 GetDataItem();
428 }
429 return (_dataItem.Flags & 0x200) != 0;
430 }
431 }
432
433 public virtual bool IsMailNewsDisplay
434 {
435 get
436 {
437 if (_dataItem == null)
438 {
439 GetDataItem();
440 }
441 return (_dataItem.Flags & 1) != 0;
442 }
443 }
444
445 public virtual bool IsMailNewsSave
446 {
447 get
448 {
449 if (_dataItem == null)
450 {
451 GetDataItem();
452 }
453 return (_dataItem.Flags & 0x100) != 0;
454 }
455 }
456
457 public virtual bool IsSingleByte => false;
458
460 {
461 get
462 {
463 return encoderFallback;
464 }
465 set
466 {
467 if (IsReadOnly)
468 {
470 }
471 if (value == null)
472 {
473 throw new ArgumentNullException("value");
474 }
476 }
477 }
478
480 {
481 get
482 {
483 return decoderFallback;
484 }
485 set
486 {
487 if (IsReadOnly)
488 {
490 }
491 if (value == null)
492 {
493 throw new ArgumentNullException("value");
494 }
496 }
497 }
498
499 public bool IsReadOnly
500 {
501 get
502 {
503 return _isReadOnly;
504 }
505 private protected set
506 {
508 }
509 }
510
512
514
515 public virtual int CodePage => _codePage;
516
517 internal bool IsUTF8CodePage => CodePage == 65001;
518
520
522
523 [Obsolete("The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead.", DiagnosticId = "SYSLIB0001", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
525
527
529
531
532 protected Encoding()
533 : this(0)
534 {
535 }
536
537 protected Encoding(int codePage)
538 {
539 if (codePage < 0)
540 {
541 throw new ArgumentOutOfRangeException("codePage");
542 }
545 }
546
557
558 [MemberNotNull("encoderFallback")]
559 [MemberNotNull("decoderFallback")]
565
566 public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes)
567 {
568 if (bytes == null)
569 {
570 throw new ArgumentNullException("bytes");
571 }
572 return Convert(srcEncoding, dstEncoding, bytes, 0, bytes.Length);
573 }
574
575 public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes, int index, int count)
576 {
577 if (srcEncoding == null || dstEncoding == null)
578 {
579 throw new ArgumentNullException((srcEncoding == null) ? "srcEncoding" : "dstEncoding", SR.ArgumentNull_Array);
580 }
581 if (bytes == null)
582 {
583 throw new ArgumentNullException("bytes", SR.ArgumentNull_Array);
584 }
585 return dstEncoding.GetBytes(srcEncoding.GetChars(bytes, index, count));
586 }
587
592
593 public static Encoding GetEncoding(int codepage)
594 {
596 if (encoding != null)
597 {
598 return encoding;
599 }
600 switch (codepage)
601 {
602 case 0:
603 return Default;
604 case 1200:
605 return Unicode;
606 case 1201:
607 return BigEndianUnicode;
608 case 12000:
609 return UTF32;
610 case 12001:
611 return BigEndianUTF32;
612 case 65001:
613 return UTF8;
614 case 20127:
615 return ASCII;
616 case 28591:
617 return Latin1;
618 case 1:
619 case 2:
620 case 3:
621 case 42:
623 case 65000:
624 {
626 {
627 return UTF7;
628 }
629 string p = string.Format(CultureInfo.InvariantCulture, "https://aka.ms/dotnet-warnings/{0}", "SYSLIB0001");
630 string message = SR.Format(SR.Encoding_UTF7_Disabled, p);
631 throw new NotSupportedException(message);
632 }
633 default:
635 {
636 throw new ArgumentOutOfRangeException("codepage", SR.Format(SR.ArgumentOutOfRange_Range, 0, 65535));
637 }
639 }
640 }
641
655
660
665
667 {
669 {
670 return encoding;
671 }
672 if (encoding == null || encoding.CodePage != 65000)
673 {
674 return encoding;
675 }
676 return null;
677 }
678
688
689 public virtual byte[] GetPreamble()
690 {
691 return Array.Empty<byte>();
692 }
693
694 private void GetDataItem()
695 {
696 if (_dataItem == null)
697 {
699 if (_dataItem == null)
700 {
702 }
703 }
704 }
705
706 public virtual object Clone()
707 {
708 Encoding encoding = (Encoding)MemberwiseClone();
709 encoding._isReadOnly = false;
710 return encoding;
711 }
712
713 public virtual int GetByteCount(char[] chars)
714 {
715 if (chars == null)
716 {
717 throw new ArgumentNullException("chars", SR.ArgumentNull_Array);
718 }
719 return GetByteCount(chars, 0, chars.Length);
720 }
721
722 public virtual int GetByteCount(string s)
723 {
724 if (s == null)
725 {
727 }
728 char[] array = s.ToCharArray();
729 return GetByteCount(array, 0, array.Length);
730 }
731
732 public abstract int GetByteCount(char[] chars, int index, int count);
733
734 public unsafe int GetByteCount(string s, int index, int count)
735 {
736 if (s == null)
737 {
739 }
740 if (index < 0)
741 {
743 }
744 if (count < 0)
745 {
747 }
748 if (index > s.Length - count)
749 {
751 }
752 fixed (char* ptr = s)
753 {
754 return GetByteCount(ptr + index, count);
755 }
756 }
757
758 [CLSCompliant(false)]
759 public unsafe virtual int GetByteCount(char* chars, int count)
760 {
761 if (chars == null)
762 {
763 throw new ArgumentNullException("chars", SR.ArgumentNull_Array);
764 }
765 if (count < 0)
766 {
768 }
769 char[] chars2 = new ReadOnlySpan<char>(chars, count).ToArray();
770 return GetByteCount(chars2, 0, count);
771 }
772
773 public unsafe virtual int GetByteCount(ReadOnlySpan<char> chars)
774 {
775 fixed (char* chars2 = &MemoryMarshal.GetNonNullPinnableReference(chars))
776 {
777 return GetByteCount(chars2, chars.Length);
778 }
779 }
780
781 public virtual byte[] GetBytes(char[] chars)
782 {
783 if (chars == null)
784 {
785 throw new ArgumentNullException("chars", SR.ArgumentNull_Array);
786 }
787 return GetBytes(chars, 0, chars.Length);
788 }
789
790 public virtual byte[] GetBytes(char[] chars, int index, int count)
791 {
792 byte[] array = new byte[GetByteCount(chars, index, count)];
794 return array;
795 }
796
797 public abstract int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex);
798
799 public virtual byte[] GetBytes(string s)
800 {
801 if (s == null)
802 {
804 }
805 int byteCount = GetByteCount(s);
806 byte[] array = new byte[byteCount];
807 int bytes = GetBytes(s, 0, s.Length, array, 0);
808 return array;
809 }
810
811 public unsafe byte[] GetBytes(string s, int index, int count)
812 {
813 if (s == null)
814 {
816 }
817 if (index < 0)
818 {
820 }
821 if (count < 0)
822 {
824 }
825 if (index > s.Length - count)
826 {
828 }
829 fixed (char* ptr = s)
830 {
832 if (byteCount == 0)
833 {
834 return Array.Empty<byte>();
835 }
836 byte[] array = new byte[byteCount];
837 fixed (byte* bytes = &array[0])
838 {
840 }
841 return array;
842 }
843 }
844
845 public virtual int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
846 {
847 if (s == null)
848 {
850 }
851 return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
852 }
853
854 [CLSCompliant(false)]
855 public unsafe virtual int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
856 {
857 if (bytes == null || chars == null)
858 {
859 throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", SR.ArgumentNull_Array);
860 }
861 if (charCount < 0 || byteCount < 0)
862 {
863 throw new ArgumentOutOfRangeException((charCount < 0) ? "charCount" : "byteCount", SR.ArgumentOutOfRange_NeedNonNegNum);
864 }
865 char[] chars2 = new ReadOnlySpan<char>(chars, charCount).ToArray();
866 byte[] array = new byte[byteCount];
867 int bytes2 = GetBytes(chars2, 0, charCount, array, 0);
868 if (bytes2 < byteCount)
869 {
871 }
873 return byteCount;
874 }
875
877 {
878 fixed (char* chars2 = &MemoryMarshal.GetNonNullPinnableReference(chars))
879 {
880 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
881 {
882 return GetBytes(chars2, chars.Length, bytes2, bytes.Length);
883 }
884 }
885 }
886
887 public virtual int GetCharCount(byte[] bytes)
888 {
889 if (bytes == null)
890 {
891 throw new ArgumentNullException("bytes", SR.ArgumentNull_Array);
892 }
893 return GetCharCount(bytes, 0, bytes.Length);
894 }
895
896 public abstract int GetCharCount(byte[] bytes, int index, int count);
897
898 [CLSCompliant(false)]
899 public unsafe virtual int GetCharCount(byte* bytes, int count)
900 {
901 if (bytes == null)
902 {
903 throw new ArgumentNullException("bytes", SR.ArgumentNull_Array);
904 }
905 if (count < 0)
906 {
908 }
909 byte[] bytes2 = new ReadOnlySpan<byte>(bytes, count).ToArray();
910 return GetCharCount(bytes2, 0, count);
911 }
912
913 public unsafe virtual int GetCharCount(ReadOnlySpan<byte> bytes)
914 {
915 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
916 {
917 return GetCharCount(bytes2, bytes.Length);
918 }
919 }
920
921 public virtual char[] GetChars(byte[] bytes)
922 {
923 if (bytes == null)
924 {
925 throw new ArgumentNullException("bytes", SR.ArgumentNull_Array);
926 }
927 return GetChars(bytes, 0, bytes.Length);
928 }
929
930 public virtual char[] GetChars(byte[] bytes, int index, int count)
931 {
932 char[] array = new char[GetCharCount(bytes, index, count)];
934 return array;
935 }
936
937 public abstract int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex);
938
939 [CLSCompliant(false)]
940 public unsafe virtual int GetChars(byte* bytes, int byteCount, char* chars, int charCount)
941 {
942 if (chars == null || bytes == null)
943 {
944 throw new ArgumentNullException((chars == null) ? "chars" : "bytes", SR.ArgumentNull_Array);
945 }
946 if (byteCount < 0 || charCount < 0)
947 {
948 throw new ArgumentOutOfRangeException((byteCount < 0) ? "byteCount" : "charCount", SR.ArgumentOutOfRange_NeedNonNegNum);
949 }
950 byte[] bytes2 = new ReadOnlySpan<byte>(bytes, byteCount).ToArray();
951 char[] array = new char[charCount];
952 int chars2 = GetChars(bytes2, 0, byteCount, array, 0);
953 if (chars2 < charCount)
954 {
956 }
958 return charCount;
959 }
960
962 {
963 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
964 {
965 fixed (char* chars2 = &MemoryMarshal.GetNonNullPinnableReference(chars))
966 {
967 return GetChars(bytes2, bytes.Length, chars2, chars.Length);
968 }
969 }
970 }
971
972 [CLSCompliant(false)]
973 public unsafe string GetString(byte* bytes, int byteCount)
974 {
975 if (bytes == null)
976 {
977 throw new ArgumentNullException("bytes", SR.ArgumentNull_Array);
978 }
979 if (byteCount < 0)
980 {
982 }
983 return string.CreateStringFromEncoding(bytes, byteCount, this);
984 }
985
986 public unsafe string GetString(ReadOnlySpan<byte> bytes)
987 {
988 fixed (byte* bytes2 = &MemoryMarshal.GetNonNullPinnableReference(bytes))
989 {
990 return string.CreateStringFromEncoding(bytes2, bytes.Length, this);
991 }
992 }
993
994 public bool IsAlwaysNormalized()
995 {
997 }
998
1000 {
1001 return false;
1002 }
1003
1004 public virtual Decoder GetDecoder()
1005 {
1006 return new DefaultDecoder(this);
1007 }
1008
1009 public virtual Encoder GetEncoder()
1010 {
1011 return new DefaultEncoder(this);
1012 }
1013
1014 public abstract int GetMaxByteCount(int charCount);
1015
1016 public abstract int GetMaxCharCount(int byteCount);
1017
1018 public virtual string GetString(byte[] bytes)
1019 {
1020 if (bytes == null)
1021 {
1022 throw new ArgumentNullException("bytes", SR.ArgumentNull_Array);
1023 }
1024 return GetString(bytes, 0, bytes.Length);
1025 }
1026
1027 public virtual string GetString(byte[] bytes, int index, int count)
1028 {
1029 return new string(GetChars(bytes, index, count));
1030 }
1031
1032 public override bool Equals([NotNullWhen(true)] object? value)
1033 {
1034 if (value is Encoding encoding && _codePage == encoding._codePage && EncoderFallback.Equals(encoding.EncoderFallback))
1035 {
1036 return DecoderFallback.Equals(encoding.DecoderFallback);
1037 }
1038 return false;
1039 }
1040
1041 public override int GetHashCode()
1042 {
1043 return _codePage + EncoderFallback.GetHashCode() + DecoderFallback.GetHashCode();
1044 }
1045
1047 {
1048 if (innerStream == null)
1049 {
1050 throw new ArgumentNullException("innerStream");
1051 }
1052 if (innerStreamEncoding == null)
1053 {
1054 throw new ArgumentNullException("innerStreamEncoding");
1055 }
1056 if (outerStreamEncoding == null)
1057 {
1058 throw new ArgumentNullException("outerStreamEncoding");
1059 }
1061 }
1062
1064 internal void ThrowBytesOverflow()
1065 {
1067 }
1068
1069 internal void ThrowBytesOverflow(EncoderNLS encoder, bool nothingEncoded)
1070 {
1071 if ((encoder?._throwOnOverflow ?? true) || nothingEncoded)
1072 {
1073 if (encoder != null && encoder.InternalHasFallbackBuffer)
1074 {
1075 encoder.FallbackBuffer.InternalReset();
1076 }
1078 }
1079 encoder.ClearMustFlush();
1080 }
1081
1084 internal static void ThrowConversionOverflow()
1085 {
1087 }
1088
1091 internal void ThrowCharsOverflow()
1092 {
1094 }
1095
1096 internal void ThrowCharsOverflow(DecoderNLS decoder, bool nothingDecoded)
1097 {
1098 if ((decoder?._throwOnOverflow ?? true) || nothingDecoded)
1099 {
1100 if (decoder != null && decoder.InternalHasFallbackBuffer)
1101 {
1102 decoder.FallbackBuffer.InternalReset();
1103 }
1105 }
1106 decoder.ClearMustFlush();
1107 }
1108
1113
1115 {
1117 }
1118
1119 internal virtual bool TryGetByteCount(Rune value, out int byteCount)
1120 {
1122 }
1123
1124 internal unsafe virtual int GetByteCount(char* pChars, int charCount, EncoderNLS encoder)
1125 {
1126 int num = 0;
1127 int charsConsumed = 0;
1128 if (!encoder.HasLeftoverData)
1129 {
1131 if (charsConsumed == charCount)
1132 {
1133 return num;
1134 }
1135 }
1137 if (num < 0)
1138 {
1140 }
1141 return num;
1142 }
1143
1144 private protected unsafe virtual int GetByteCountFast(char* pChars, int charsLength, EncoderFallback fallback, out int charsConsumed)
1145 {
1147 }
1148
1149 [MethodImpl(MethodImplOptions.NoInlining)]
1150 private protected unsafe int GetByteCountWithFallback(char* pCharsOriginal, int originalCharCount, int charsConsumedSoFar)
1151 {
1152 return GetByteCountWithFallback(new ReadOnlySpan<char>(pCharsOriginal, originalCharCount).Slice(charsConsumedSoFar), originalCharCount, null);
1153 }
1154
1155 private unsafe int GetByteCountWithFallback(char* pOriginalChars, int originalCharCount, int charsConsumedSoFar, EncoderNLS encoder)
1156 {
1160 num += GetByteCountFast((char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(readOnlySpan)), readOnlySpan.Length, encoder.Fallback, out charsConsumed);
1161 if (num < 0)
1162 {
1164 }
1166 if (!readOnlySpan.IsEmpty)
1167 {
1168 num += GetByteCountWithFallback(readOnlySpan, originalCharCount, encoder);
1169 if (num < 0)
1170 {
1172 }
1173 }
1174 return num;
1175 }
1176
1177 private protected unsafe virtual int GetByteCountWithFallback(ReadOnlySpan<char> chars, int originalCharsLength, EncoderNLS encoder)
1178 {
1179 fixed (char* ptr = &MemoryMarshal.GetReference(chars))
1180 {
1182 int num = 0;
1183 Rune result;
1184 int charsConsumed;
1185 while (Rune.DecodeFromUtf16(chars, out result, out charsConsumed) != OperationStatus.NeedMoreData || encoder == null || encoder.MustFlush)
1186 {
1187 int num2 = encoderFallbackBuffer.InternalFallbackGetByteCount(chars, out charsConsumed);
1188 num += num2;
1189 if (num < 0)
1190 {
1192 }
1193 chars = chars.Slice(charsConsumed);
1194 if (!chars.IsEmpty)
1195 {
1196 num2 = GetByteCountFast((char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)), chars.Length, null, out charsConsumed);
1197 num += num2;
1198 if (num < 0)
1199 {
1201 }
1202 chars = chars.Slice(charsConsumed);
1203 }
1204 if (chars.IsEmpty)
1205 {
1206 break;
1207 }
1208 }
1209 return num;
1210 }
1211 }
1212
1213 internal unsafe virtual int GetBytes(char* pChars, int charCount, byte* pBytes, int byteCount, EncoderNLS encoder)
1214 {
1215 int num = 0;
1216 int charsConsumed = 0;
1217 if (!encoder.HasLeftoverData)
1218 {
1220 if (charsConsumed == charCount)
1221 {
1223 return num;
1224 }
1225 }
1227 }
1228
1229 private protected unsafe virtual int GetBytesFast(char* pChars, int charsLength, byte* pBytes, int bytesLength, out int charsConsumed)
1230 {
1232 }
1233
1234 [MethodImpl(MethodImplOptions.NoInlining)]
1235 private protected unsafe int GetBytesWithFallback(char* pOriginalChars, int originalCharCount, byte* pOriginalBytes, int originalByteCount, int charsConsumedSoFar, int bytesWrittenSoFar)
1236 {
1238 }
1239
1240 private unsafe int GetBytesWithFallback(char* pOriginalChars, int originalCharCount, byte* pOriginalBytes, int originalByteCount, int charsConsumedSoFar, int bytesWrittenSoFar, EncoderNLS encoder)
1241 {
1244 int charsConsumed;
1245 int bytesWritten;
1248 span = span.Slice(bytesWritten);
1249 if (!flag)
1250 {
1251 ThrowBytesOverflow(encoder, span.Length == originalByteCount);
1252 }
1253 else
1254 {
1255 bytesWritten = GetBytesFast((char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(readOnlySpan)), readOnlySpan.Length, (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span)), span.Length, out charsConsumed);
1257 span = span.Slice(bytesWritten);
1258 if (!readOnlySpan.IsEmpty)
1259 {
1260 encoder._charsUsed = originalCharCount;
1261 return GetBytesWithFallback(readOnlySpan, originalCharCount, span, originalByteCount, encoder);
1262 }
1263 }
1264 encoder._charsUsed = originalCharCount - readOnlySpan.Length;
1265 return originalByteCount - span.Length;
1266 }
1267
1269 {
1270 fixed (char* ptr2 = &MemoryMarshal.GetReference(chars))
1271 {
1272 fixed (byte* ptr = &MemoryMarshal.GetReference(bytes))
1273 {
1275 do
1276 {
1277 Rune result;
1278 int charsConsumed;
1280 if (operationStatus != OperationStatus.NeedMoreData)
1281 {
1282 if (operationStatus != OperationStatus.InvalidData && EncodeRune(result, bytes, out var _) == OperationStatus.DestinationTooSmall)
1283 {
1284 break;
1285 }
1286 }
1287 else if (encoder != null && !encoder.MustFlush)
1288 {
1290 chars = ReadOnlySpan<char>.Empty;
1291 break;
1292 }
1293 int bytesWritten2;
1294 bool flag = encoderFallbackBuffer.TryInternalFallbackGetBytes(chars, bytes, out charsConsumed, out bytesWritten2);
1295 chars = chars.Slice(charsConsumed);
1296 bytes = bytes.Slice(bytesWritten2);
1297 if (!flag)
1298 {
1299 break;
1300 }
1301 if (!chars.IsEmpty)
1302 {
1303 bytesWritten2 = GetBytesFast((char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)), chars.Length, (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)), bytes.Length, out charsConsumed);
1304 chars = chars.Slice(charsConsumed);
1305 bytes = bytes.Slice(bytesWritten2);
1306 }
1307 }
1308 while (!chars.IsEmpty);
1309 if (!chars.IsEmpty || encoderFallbackBuffer.Remaining > 0)
1310 {
1311 ThrowBytesOverflow(encoder, bytes.Length == originalBytesLength);
1312 }
1313 if (encoder != null)
1314 {
1316 }
1317 return originalBytesLength - bytes.Length;
1318 }
1319 }
1320 }
1321
1322 internal unsafe virtual int GetCharCount(byte* pBytes, int byteCount, DecoderNLS decoder)
1323 {
1324 int num = 0;
1325 int bytesConsumed = 0;
1326 if (!decoder.HasLeftoverData)
1327 {
1329 if (bytesConsumed == byteCount)
1330 {
1331 return num;
1332 }
1333 }
1335 if (num < 0)
1336 {
1338 }
1339 return num;
1340 }
1341
1342 private protected unsafe virtual int GetCharCountFast(byte* pBytes, int bytesLength, DecoderFallback fallback, out int bytesConsumed)
1343 {
1345 }
1346
1347 [MethodImpl(MethodImplOptions.NoInlining)]
1352
1354 {
1356 int num = 0;
1357 int bytesConsumed;
1358 if (decoder.HasLeftoverData)
1359 {
1362 }
1363 num += GetCharCountFast((byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(readOnlySpan)), readOnlySpan.Length, decoder.Fallback, out bytesConsumed);
1364 if (num < 0)
1365 {
1367 }
1369 if (!readOnlySpan.IsEmpty)
1370 {
1372 if (num < 0)
1373 {
1375 }
1376 }
1377 return num;
1378 }
1379
1381 {
1382 fixed (byte* ptr = &MemoryMarshal.GetReference(bytes))
1383 {
1385 int num = 0;
1386 Rune value;
1387 int bytesConsumed;
1388 while (DecodeFirstRune(bytes, out value, out bytesConsumed) != OperationStatus.NeedMoreData || decoder == null || decoder.MustFlush)
1389 {
1390 int num2 = decoderFallbackBuffer.InternalFallbackGetCharCount(bytes, bytesConsumed);
1391 num += num2;
1392 if (num < 0)
1393 {
1395 }
1396 bytes = bytes.Slice(bytesConsumed);
1397 if (!bytes.IsEmpty)
1398 {
1399 num2 = GetCharCountFast((byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)), bytes.Length, null, out bytesConsumed);
1400 num += num2;
1401 if (num < 0)
1402 {
1404 }
1405 bytes = bytes.Slice(bytesConsumed);
1406 }
1407 if (bytes.IsEmpty)
1408 {
1409 break;
1410 }
1411 }
1412 return num;
1413 }
1414 }
1415
1416 internal unsafe virtual int GetChars(byte* pBytes, int byteCount, char* pChars, int charCount, DecoderNLS decoder)
1417 {
1418 int num = 0;
1419 int bytesConsumed = 0;
1420 if (!decoder.HasLeftoverData)
1421 {
1423 if (bytesConsumed == byteCount)
1424 {
1426 return num;
1427 }
1428 }
1430 }
1431
1432 private protected unsafe virtual int GetCharsFast(byte* pBytes, int bytesLength, char* pChars, int charsLength, out int bytesConsumed)
1433 {
1435 }
1436
1437 [MethodImpl(MethodImplOptions.NoInlining)]
1438 private protected unsafe int GetCharsWithFallback(byte* pOriginalBytes, int originalByteCount, char* pOriginalChars, int originalCharCount, int bytesConsumedSoFar, int charsWrittenSoFar)
1439 {
1441 }
1442
1443 private protected unsafe int GetCharsWithFallback(byte* pOriginalBytes, int originalByteCount, char* pOriginalChars, int originalCharCount, int bytesConsumedSoFar, int charsWrittenSoFar, DecoderNLS decoder)
1444 {
1446 Span<char> span = new Span<char>(pOriginalChars, originalCharCount).Slice(charsWrittenSoFar);
1447 int bytesConsumed;
1448 int start;
1449 if (decoder.HasLeftoverData)
1450 {
1453 span = span.Slice(start);
1454 }
1455 start = GetCharsFast((byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(readOnlySpan)), readOnlySpan.Length, (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span)), span.Length, out bytesConsumed);
1457 span = span.Slice(start);
1459 if (readOnlySpan.IsEmpty)
1460 {
1461 return originalCharCount - span.Length;
1462 }
1463 return GetCharsWithFallback(readOnlySpan, originalByteCount, span, originalCharCount, decoder);
1464 }
1465
1467 {
1468 fixed (byte* ptr2 = &MemoryMarshal.GetReference(bytes))
1469 {
1470 fixed (char* ptr = &MemoryMarshal.GetReference(chars))
1471 {
1473 do
1474 {
1475 Rune value;
1476 int bytesConsumed;
1478 if (operationStatus != OperationStatus.NeedMoreData)
1479 {
1480 if (operationStatus != OperationStatus.InvalidData)
1481 {
1482 break;
1483 }
1484 }
1485 else if (decoder != null && !decoder.MustFlush)
1486 {
1487 decoder.SetLeftoverData(bytes);
1488 bytes = ReadOnlySpan<byte>.Empty;
1489 break;
1490 }
1491 if (!decoderFallbackBuffer.TryInternalFallbackGetChars(bytes, bytesConsumed, chars, out var charsWritten))
1492 {
1493 break;
1494 }
1495 bytes = bytes.Slice(bytesConsumed);
1496 chars = chars.Slice(charsWritten);
1497 if (!bytes.IsEmpty)
1498 {
1499 charsWritten = GetCharsFast((byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)), bytes.Length, (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)), chars.Length, out bytesConsumed);
1500 bytes = bytes.Slice(bytesConsumed);
1501 chars = chars.Slice(charsWritten);
1502 }
1503 }
1504 while (!bytes.IsEmpty);
1505 if (!bytes.IsEmpty)
1506 {
1507 ThrowCharsOverflow(decoder, chars.Length == originalCharsLength);
1508 }
1509 if (decoder != null)
1510 {
1512 }
1513 return originalCharsLength - chars.Length;
1514 }
1515 }
1516 }
1517}
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
static CultureInfo InvariantCulture
static Exception ByDesign
static string ArgumentOutOfRange_Range
Definition SR.cs:1096
static string Argument_EncodingConversionOverflowBytes
Definition SR.cs:84
static string NotSupported_NoCodepageData
Definition SR.cs:1688
static string Argument_ConversionOverflow
Definition SR.cs:538
static string Argument_EncoderFallbackNotEmpty
Definition SR.cs:590
static string Encoding_UTF7_Disabled
Definition SR.cs:2168
static string ArgumentOutOfRange_IndexCount
Definition SR.cs:80
static string Argument_EncodingConversionOverflowChars
Definition SR.cs:86
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_CodepageNotSupported
Definition SR.cs:522
static string ArgumentNull_Array
Definition SR.cs:24
static string ArgumentNull_String
Definition SR.cs:960
static string InvalidOperation_ReadOnly
Definition SR.cs:1504
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
Definition SR.cs:7
static readonly ASCIIEncodingSealed s_default
unsafe void InternalInitialize(byte *byteStart, char *charEnd)
static DecoderFallbackBuffer CreateAndInitialize(Encoding encoding, DecoderNLS decoder, int originalByteCount)
virtual unsafe bool InternalFallback(byte[] bytes, byte *pBytes, ref char *chars)
static DecoderFallback ReplacementFallback
int DrainLeftoverDataForGetChars(ReadOnlySpan< byte > bytes, Span< char > chars, out int bytesConsumed)
void SetLeftoverData(ReadOnlySpan< byte > bytes)
int DrainLeftoverDataForGetCharCount(ReadOnlySpan< byte > bytes, out int bytesConsumed)
new DecoderFallbackBuffer FallbackBuffer
Definition DecoderNLS.cs:24
new DecoderFallback Fallback
Definition DecoderNLS.cs:19
static EncoderFallbackBuffer CreateAndInitialize(Encoding encoding, EncoderNLS encoder, int originalCharCount)
unsafe void InternalInitialize(char *charStart, char *charEnd, EncoderNLS encoder, bool setEncoder)
EncoderFallbackBuffer CreateFallbackBuffer()
static EncoderFallback ReplacementFallback
new EncoderFallback Fallback
Definition EncoderNLS.cs:21
int DrainLeftoverDataForGetByteCount(ReadOnlySpan< char > chars, out int charsConsumed)
bool TryDrainLeftoverDataForGetBytes(ReadOnlySpan< char > chars, Span< byte > bytes, out int charsConsumed, out int bytesWritten)
new EncoderFallbackBuffer FallbackBuffer
Definition EncoderNLS.cs:26
static void AddProvider(EncodingProvider provider)
static Encoding GetEncodingFromProvider(int codepage)
static Dictionary< int, EncodingInfo > GetEncodingListFromProviders()
static CodePageDataItem GetCodePageDataItem(int codePage)
static EncodingInfo[] GetEncodings()
static int GetCodePageFromName(string name)
override int GetCharCount(byte[] bytes, int index, int count, bool flush)
Definition Encoding.cs:70
unsafe override int GetCharCount(byte *bytes, int count, bool flush)
Definition Encoding.cs:75
DefaultDecoder(Encoding encoding)
Definition Encoding.cs:55
object GetRealObject(StreamingContext context)
Definition Encoding.cs:60
override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, bool flush)
Definition Encoding.cs:85
override int GetCharCount(byte[] bytes, int index, int count)
Definition Encoding.cs:65
override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
Definition Encoding.cs:80
unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount, bool flush)
Definition Encoding.cs:90
override int GetByteCount(char[] chars, int index, int count, bool flush)
Definition Encoding.cs:30
unsafe override int GetBytes(char *chars, int charCount, byte *bytes, int byteCount, bool flush)
Definition Encoding.cs:45
DefaultEncoder(Encoding encoding)
Definition Encoding.cs:20
object GetRealObject(StreamingContext context)
Definition Encoding.cs:25
override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, bool flush)
Definition Encoding.cs:40
unsafe override int GetByteCount(char *chars, int count, bool flush)
Definition Encoding.cs:35
bool AddByte(byte b1, byte b2, int moreBytesExpected)
Definition Encoding.cs:296
unsafe bool AddByte(byte b, int moreBytesExpected)
Definition Encoding.cs:271
unsafe readonly byte * _byteEnd
Definition Encoding.cs:214
unsafe readonly byte * _byteStart
Definition Encoding.cs:212
EncoderFallbackBuffer fallbackBuffer
Definition Encoding.cs:228
unsafe EncodingByteBuffer(Encoding inEncoding, EncoderNLS inEncoder, byte *inByteStart, int inByteCount, char *inCharStart, int inCharCount)
Definition Encoding.cs:246
unsafe readonly char * _charStart
Definition Encoding.cs:218
unsafe void MovePrevious(bool bThrow)
Definition Encoding.cs:305
unsafe readonly char * _charEnd
Definition Encoding.cs:220
unsafe readonly char * _charStart
Definition Encoding.cs:100
unsafe EncodingCharBuffer(Encoding enc, DecoderNLS decoder, char *charStart, int charCount, byte *byteStart, int byteCount)
Definition Encoding.cs:124
unsafe readonly byte * _byteEnd
Definition Encoding.cs:112
unsafe readonly char * _charEnd
Definition Encoding.cs:102
unsafe bool Fallback(byte[] byteBuffer)
Definition Encoding.cs:186
unsafe bool AddChar(char ch, int numBytes)
Definition Encoding.cs:145
bool Fallback(byte fallbackByte)
Definition Encoding.cs:180
readonly DecoderFallbackBuffer _fallbackBuffer
Definition Encoding.cs:116
unsafe readonly byte * _byteStart
Definition Encoding.cs:110
unsafe void AdjustBytes(int count)
Definition Encoding.cs:166
static Encoding BigEndianUnicode
Definition Encoding.cs:521
virtual unsafe int GetBytesWithFallback(ReadOnlySpan< char > chars, int originalCharsLength, Span< byte > bytes, int originalBytesLength, EncoderNLS encoder)
Definition Encoding.cs:1268
virtual bool IsBrowserDisplay
Definition Encoding.cs:410
void ThrowCharsOverflow(DecoderNLS decoder, bool nothingDecoded)
Definition Encoding.cs:1096
unsafe int GetCharsWithFallback(byte *pOriginalBytes, int originalByteCount, char *pOriginalChars, int originalCharCount, int bytesConsumedSoFar, int charsWrittenSoFar, DecoderNLS decoder)
Definition Encoding.cs:1443
virtual unsafe int GetChars(byte *pBytes, int byteCount, char *pChars, int charCount, DecoderNLS decoder)
Definition Encoding.cs:1416
static Encoding Unicode
Definition Encoding.cs:519
EncoderFallback encoderFallback
Definition Encoding.cs:341
virtual unsafe int GetBytesFast(char *pChars, int charsLength, byte *pBytes, int bytesLength, out int charsConsumed)
Definition Encoding.cs:1229
unsafe int GetByteCountWithFallback(char *pCharsOriginal, int originalCharCount, int charsConsumedSoFar)
Definition Encoding.cs:1150
unsafe int GetCharCountWithFallback(ReadOnlySpan< byte > bytes, int originalBytesLength, DecoderNLS decoder)
Definition Encoding.cs:1380
static readonly UTF8Encoding.UTF8EncodingSealed s_defaultEncoding
Definition Encoding.cs:332
virtual unsafe int GetBytes(ReadOnlySpan< char > chars, Span< byte > bytes)
Definition Encoding.cs:876
virtual bool IsSingleByte
Definition Encoding.cs:457
Encoding(int codePage, EncoderFallback? encoderFallback, DecoderFallback? decoderFallback)
Definition Encoding.cs:547
virtual int WindowsCodePage
Definition Encoding.cs:398
static EncodingInfo[] GetEncodings()
Definition Encoding.cs:679
static Encoding UTF7
Definition Encoding.cs:524
bool IsAlwaysNormalized()
Definition Encoding.cs:994
virtual unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount)
Definition Encoding.cs:940
virtual ReadOnlySpan< byte > Preamble
Definition Encoding.cs:347
static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes)
Definition Encoding.cs:566
static Encoding Latin1
Definition Encoding.cs:513
virtual unsafe int GetCharCount(byte *pBytes, int byteCount, DecoderNLS decoder)
Definition Encoding.cs:1322
unsafe int GetCharCountWithFallback(byte *pOriginalBytes, int originalByteCount, int bytesConsumedSoFar, DecoderNLS decoder)
Definition Encoding.cs:1353
static Encoding UTF8
Definition Encoding.cs:526
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
virtual unsafe int GetByteCountFast(char *pChars, int charsLength, EncoderFallback fallback, out int charsConsumed)
Definition Encoding.cs:1144
int GetCharCount(byte[] bytes, int index, int count)
virtual bool IsMailNewsDisplay
Definition Encoding.cs:434
virtual unsafe int GetCharsWithFallback(ReadOnlySpan< byte > bytes, int originalBytesLength, Span< char > chars, int originalCharsLength, DecoderNLS decoder)
Definition Encoding.cs:1466
virtual byte[] GetBytes(string s)
Definition Encoding.cs:799
virtual unsafe int GetChars(ReadOnlySpan< byte > bytes, Span< char > chars)
Definition Encoding.cs:961
int GetMaxCharCount(int byteCount)
void ThrowBytesOverflow(EncoderNLS encoder, bool nothingEncoded)
Definition Encoding.cs:1069
static void ThrowConversionOverflow()
Definition Encoding.cs:1084
unsafe int GetBytesWithFallback(char *pOriginalChars, int originalCharCount, byte *pOriginalBytes, int originalByteCount, int charsConsumedSoFar, int bytesWrittenSoFar)
Definition Encoding.cs:1235
static Encoding UTF32
Definition Encoding.cs:528
unsafe int GetByteCount(string s, int index, int count)
Definition Encoding.cs:734
virtual string WebName
Definition Encoding.cs:386
static Encoding ASCII
Definition Encoding.cs:511
virtual int GetCharCount(byte[] bytes)
Definition Encoding.cs:887
override bool Equals([NotNullWhen(true)] object? value)
Definition Encoding.cs:1032
Encoding(int codePage)
Definition Encoding.cs:537
static void RegisterProvider(EncodingProvider provider)
Definition Encoding.cs:588
virtual unsafe int GetByteCount(ReadOnlySpan< char > chars)
Definition Encoding.cs:773
virtual OperationStatus EncodeRune(Rune value, Span< byte > bytes, out int bytesWritten)
Definition Encoding.cs:1114
unsafe int GetByteCountWithFallback(char *pOriginalChars, int originalCharCount, int charsConsumedSoFar, EncoderNLS encoder)
Definition Encoding.cs:1155
virtual OperationStatus DecodeFirstRune(ReadOnlySpan< byte > bytes, out Rune value, out int bytesConsumed)
Definition Encoding.cs:1109
virtual bool IsAlwaysNormalized(NormalizationForm form)
Definition Encoding.cs:999
static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes, int index, int count)
Definition Encoding.cs:575
virtual int GetByteCount(string s)
Definition Encoding.cs:722
virtual byte[] GetBytes(char[] chars)
Definition Encoding.cs:781
int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
DecoderFallback decoderFallback
Definition Encoding.cs:343
virtual string EncodingName
Definition Encoding.cs:362
virtual unsafe int GetBytes(char *chars, int charCount, byte *bytes, int byteCount)
Definition Encoding.cs:855
static Encoding GetEncoding(string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
Definition Encoding.cs:661
virtual char[] GetChars(byte[] bytes, int index, int count)
Definition Encoding.cs:930
unsafe int GetBytesWithFallback(char *pOriginalChars, int originalCharCount, byte *pOriginalBytes, int originalByteCount, int charsConsumedSoFar, int bytesWrittenSoFar, EncoderNLS encoder)
Definition Encoding.cs:1240
virtual unsafe int GetByteCountWithFallback(ReadOnlySpan< char > chars, int originalCharsLength, EncoderNLS encoder)
Definition Encoding.cs:1177
int GetMaxByteCount(int charCount)
EncoderFallback EncoderFallback
Definition Encoding.cs:460
static Encoding GetEncoding(string name)
Definition Encoding.cs:656
virtual bool IsMailNewsSave
Definition Encoding.cs:446
virtual Decoder GetDecoder()
Definition Encoding.cs:1004
virtual unsafe int GetCharCount(byte *bytes, int count)
Definition Encoding.cs:899
CodePageDataItem _dataItem
Definition Encoding.cs:336
virtual string GetString(byte[] bytes, int index, int count)
Definition Encoding.cs:1027
unsafe int GetCharsWithFallback(byte *pOriginalBytes, int originalByteCount, char *pOriginalChars, int originalCharCount, int bytesConsumedSoFar, int charsWrittenSoFar)
Definition Encoding.cs:1438
static Encoding BigEndianUTF32
Definition Encoding.cs:530
virtual int CodePage
Definition Encoding.cs:515
virtual string BodyName
Definition Encoding.cs:350
static Encoding Default
Definition Encoding.cs:345
virtual Encoder GetEncoder()
Definition Encoding.cs:1009
unsafe int GetCharCountWithFallback(byte *pBytesOriginal, int originalByteCount, int bytesConsumedSoFar)
Definition Encoding.cs:1348
virtual unsafe int GetCharCount(ReadOnlySpan< byte > bytes)
Definition Encoding.cs:913
virtual unsafe int GetCharCountFast(byte *pBytes, int bytesLength, DecoderFallback fallback, out int bytesConsumed)
Definition Encoding.cs:1342
static Encoding GetEncoding(int codepage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
Definition Encoding.cs:642
virtual int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
Definition Encoding.cs:845
virtual void SetDefaultFallbacks()
Definition Encoding.cs:560
virtual unsafe int GetCharsFast(byte *pBytes, int bytesLength, char *pChars, int charsLength, out int bytesConsumed)
Definition Encoding.cs:1432
int GetByteCount(char[] chars, int index, int count)
virtual char[] GetChars(byte[] bytes)
Definition Encoding.cs:921
static Encoding FilterDisallowedEncodings(Encoding encoding)
Definition Encoding.cs:666
virtual bool TryGetByteCount(Rune value, out int byteCount)
Definition Encoding.cs:1119
virtual int GetByteCount(char[] chars)
Definition Encoding.cs:713
virtual string GetString(byte[] bytes)
Definition Encoding.cs:1018
virtual object Clone()
Definition Encoding.cs:706
virtual bool IsBrowserSave
Definition Encoding.cs:422
virtual unsafe int GetBytes(char *pChars, int charCount, byte *pBytes, int byteCount, EncoderNLS encoder)
Definition Encoding.cs:1213
virtual unsafe int GetByteCount(char *chars, int count)
Definition Encoding.cs:759
virtual byte[] GetBytes(char[] chars, int index, int count)
Definition Encoding.cs:790
override int GetHashCode()
Definition Encoding.cs:1041
unsafe string GetString(ReadOnlySpan< byte > bytes)
Definition Encoding.cs:986
virtual unsafe int GetByteCount(char *pChars, int charCount, EncoderNLS encoder)
Definition Encoding.cs:1124
virtual string HeaderName
Definition Encoding.cs:374
virtual byte[] GetPreamble()
Definition Encoding.cs:689
static Stream CreateTranscodingStream(Stream innerStream, Encoding innerStreamEncoding, Encoding outerStreamEncoding, bool leaveOpen=false)
Definition Encoding.cs:1046
int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973
unsafe byte[] GetBytes(string s, int index, int count)
Definition Encoding.cs:811
static readonly Latin1EncodingSealed s_default
static readonly UTF32Encoding s_bigEndianDefault
static readonly UTF32Encoding s_default
static readonly UTF7Encoding s_default
static readonly UTF8EncodingSealed s_default
static readonly UnicodeEncoding s_littleEndianDefault
static readonly UnicodeEncoding s_bigEndianDefault
static void ThrowArgumentNullException(string name)
static OperationStatus DecodeFromUtf16(ReadOnlySpan< char > source, out Rune result, out int charsConsumed)
Definition Rune.cs:168