14 [__DynamicallyInvokable]
23 private bool m_hasInitializedEncoding;
26 internal char charLeftOver;
28 public DefaultEncoder(
Encoding encoding)
30 m_encoding = encoding;
31 m_hasInitializedEncoding =
true;
44 charLeftOver = (char)info.GetValue(
"charLeftOver", typeof(
char));
54 if (m_hasInitializedEncoding)
59 if (m_fallback !=
null)
61 encoder.m_fallback = m_fallback;
63 if (charLeftOver != 0)
65 EncoderNLS encoderNLS = encoder as EncoderNLS;
66 if (encoderNLS !=
null)
68 encoderNLS.charLeftOver = charLeftOver;
81 info.AddValue(
"encoding", m_encoding);
84 public override int GetByteCount(
char[] chars,
int index,
int count,
bool flush)
90 public unsafe
override int GetByteCount(
char* chars,
int count,
bool flush)
95 public override int GetBytes(
char[] chars,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex,
bool flush)
97 return m_encoding.
GetBytes(chars, charIndex, charCount, bytes, byteIndex);
101 public unsafe
override int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount,
bool flush)
103 return m_encoding.
GetBytes(chars, charCount, bytes, byteCount);
113 private bool m_hasInitializedEncoding;
115 public DefaultDecoder(
Encoding encoding)
117 m_encoding = encoding;
118 m_hasInitializedEncoding =
true;
141 if (m_hasInitializedEncoding)
146 if (m_fallback !=
null)
148 decoder.m_fallback = m_fallback;
160 info.AddValue(
"encoding", m_encoding);
163 public override int GetCharCount(
byte[] bytes,
int index,
int count)
168 public override int GetCharCount(
byte[] bytes,
int index,
int count,
bool flush)
174 public unsafe
override int GetCharCount(
byte* bytes,
int count,
bool flush)
179 public override int GetChars(
byte[] bytes,
int byteIndex,
int byteCount,
char[] chars,
int charIndex)
181 return GetChars(bytes, byteIndex, byteCount, chars, charIndex, flush:
false);
184 public override int GetChars(
byte[] bytes,
int byteIndex,
int byteCount,
char[] chars,
int charIndex,
bool flush)
186 return m_encoding.
GetChars(bytes, byteIndex, byteCount, chars, charIndex);
190 public unsafe
override int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount,
bool flush)
192 return m_encoding.
GetChars(bytes, byteCount, chars, charCount);
196 internal class EncodingCharBuffer
199 private unsafe
char* chars;
202 private unsafe
char* charStart;
205 private unsafe
char* charEnd;
207 private int charCountResult;
211 private DecoderNLS decoder;
214 private unsafe
byte* byteStart;
217 private unsafe
byte* byteEnd;
220 private unsafe
byte* bytes;
224 internal unsafe
bool MoreData
229 return bytes < byteEnd;
233 internal unsafe
int BytesUsed
238 return (
int)(bytes - byteStart);
242 internal int Count => charCountResult;
245 internal unsafe EncodingCharBuffer(
Encoding enc, DecoderNLS decoder,
char* charStart,
int charCount,
byte* byteStart,
int byteCount)
248 this.decoder = decoder;
250 this.charStart = charStart;
251 charEnd = charStart + charCount;
252 this.byteStart = byteStart;
254 byteEnd = byteStart + byteCount;
255 if (this.decoder ==
null)
261 fallbackBuffer = this.decoder.FallbackBuffer;
263 fallbackBuffer.InternalInitialize(bytes, charEnd);
267 internal unsafe
bool AddChar(
char ch,
int numBytes)
271 if (chars >= charEnd)
274 enc.ThrowCharsOverflow(decoder, bytes <= byteStart);
286 internal bool AddChar(
char ch)
288 return AddChar(ch, 1);
292 internal unsafe
bool AddChar(
char ch1,
char ch2,
int numBytes)
294 if (chars >= charEnd - 1)
297 enc.ThrowCharsOverflow(decoder, bytes <= byteStart);
300 if (AddChar(ch1, numBytes))
302 return AddChar(ch2, numBytes);
308 internal unsafe
void AdjustBytes(
int count)
314 internal unsafe
bool EvenMoreData(
int count)
316 return bytes <= byteEnd - count;
320 internal unsafe
byte GetNextByte()
322 if (bytes >= byteEnd)
330 internal bool Fallback(
byte fallbackByte)
332 byte[] byteBuffer =
new byte[1]
336 return Fallback(byteBuffer);
340 internal bool Fallback(
byte byte1,
byte byte2)
342 byte[] byteBuffer =
new byte[2]
347 return Fallback(byteBuffer);
351 internal bool Fallback(
byte byte1,
byte byte2,
byte byte3,
byte byte4)
353 byte[] byteBuffer =
new byte[4]
360 return Fallback(byteBuffer);
364 internal unsafe
bool Fallback(
byte[] byteBuffer)
369 if (!fallbackBuffer.InternalFallback(byteBuffer, bytes, ref chars))
371 bytes -= byteBuffer.Length;
372 fallbackBuffer.InternalReset();
373 enc.ThrowCharsOverflow(decoder, chars == charStart);
376 charCountResult += (int)(chars - ptr);
380 charCountResult += fallbackBuffer.InternalFallback(byteBuffer, bytes);
386 internal class EncodingByteBuffer
389 private unsafe
byte* bytes;
392 private unsafe
byte* byteStart;
395 private unsafe
byte* byteEnd;
398 private unsafe
char* chars;
401 private unsafe
char* charStart;
404 private unsafe
char* charEnd;
406 private int byteCountResult;
410 private EncoderNLS encoder;
414 internal unsafe
bool MoreData
421 return chars < charEnd;
427 internal unsafe
int CharsUsed
432 return (
int)(chars - charStart);
436 internal int Count => byteCountResult;
439 internal unsafe EncodingByteBuffer(
Encoding inEncoding, EncoderNLS inEncoder,
byte* inByteStart,
int inByteCount,
char* inCharStart,
int inCharCount)
443 charStart = inCharStart;
445 charEnd = inCharStart + inCharCount;
447 byteStart = inByteStart;
448 byteEnd = inByteStart + inByteCount;
455 fallbackBuffer = encoder.FallbackBuffer;
456 if (encoder.m_throwOnOverflow && encoder.InternalHasFallbackBuffer && fallbackBuffer.
Remaining > 0)
458 throw new ArgumentException(
Environment.GetResourceString(
"Argument_EncoderFallbackNotEmpty", encoder.Encoding.EncodingName, encoder.Fallback.GetType()));
461 fallbackBuffer.InternalInitialize(chars, charEnd, encoder, bytes !=
null);
465 internal unsafe
bool AddByte(
byte b,
int moreBytesExpected)
469 if (bytes >= byteEnd - moreBytesExpected)
471 MovePrevious(bThrow:
true);
481 internal bool AddByte(
byte b1)
483 return AddByte(b1, 0);
487 internal bool AddByte(
byte b1,
byte b2)
489 return AddByte(b1, b2, 0);
493 internal bool AddByte(
byte b1,
byte b2,
int moreBytesExpected)
495 if (AddByte(b1, 1 + moreBytesExpected))
497 return AddByte(b2, moreBytesExpected);
503 internal bool AddByte(
byte b1,
byte b2,
byte b3)
505 return AddByte(b1, b2, b3, 0);
509 internal bool AddByte(
byte b1,
byte b2,
byte b3,
int moreBytesExpected)
511 if (AddByte(b1, 2 + moreBytesExpected) && AddByte(b2, 1 + moreBytesExpected))
513 return AddByte(b3, moreBytesExpected);
519 internal bool AddByte(
byte b1,
byte b2,
byte b3,
byte b4)
521 if (AddByte(b1, 3) && AddByte(b2, 2) && AddByte(b3, 1))
523 return AddByte(b4, 0);
529 internal unsafe
void MovePrevious(
bool bThrow)
531 if (fallbackBuffer.bFallingBack)
535 else if (chars > charStart)
541 enc.ThrowBytesOverflow(encoder, bytes == byteStart);
546 internal unsafe
bool Fallback(
char charFallback)
548 return fallbackBuffer.InternalFallback(charFallback, ref chars);
552 internal unsafe
char GetNextChar()
554 char c = fallbackBuffer.InternalGetNextChar();
555 if (c ==
'\0' && chars < charEnd)
565 private static volatile Encoding defaultEncoding;
567 private static volatile Encoding unicodeEncoding;
569 private static volatile Encoding bigEndianUnicode;
571 private static volatile Encoding utf7Encoding;
573 private static volatile Encoding utf8Encoding;
575 private static volatile Encoding utf32Encoding;
577 private static volatile Encoding asciiEncoding;
579 private static volatile Encoding latin1Encoding;
581 private static volatile Hashtable encodings;
583 private const int MIMECONTF_MAILNEWS = 1;
585 private const int MIMECONTF_BROWSER = 2;
587 private const int MIMECONTF_SAVABLE_MAILNEWS = 256;
589 private const int MIMECONTF_SAVABLE_BROWSER = 512;
591 private const int CodePageDefault = 0;
593 private const int CodePageNoOEM = 1;
595 private const int CodePageNoMac = 2;
597 private const int CodePageNoThread = 3;
599 private const int CodePageNoSymbol = 42;
601 private const int CodePageUnicode = 1200;
603 private const int CodePageBigEndian = 1201;
605 private const int CodePageWindows1252 = 1252;
607 private const int CodePageMacGB2312 = 10008;
609 private const int CodePageGB2312 = 20936;
611 private const int CodePageMacKorean = 10003;
613 private const int CodePageDLLKorean = 20949;
615 private const int ISO2022JP = 50220;
617 private const int ISO2022JPESC = 50221;
619 private const int ISO2022JPSISO = 50222;
621 private const int ISOKorean = 50225;
623 private const int ISOSimplifiedCN = 50227;
625 private const int EUCJP = 51932;
627 private const int ChineseHZ = 52936;
629 private const int DuplicateEUCCN = 51936;
631 private const int EUCCN = 936;
633 private const int EUCKR = 51949;
635 internal const int CodePageASCII = 20127;
637 internal const int ISO_8859_1 = 28591;
639 private const int ISCIIAssemese = 57006;
641 private const int ISCIIBengali = 57003;
643 private const int ISCIIDevanagari = 57002;
645 private const int ISCIIGujarathi = 57010;
647 private const int ISCIIKannada = 57008;
649 private const int ISCIIMalayalam = 57009;
651 private const int ISCIIOriya = 57007;
653 private const int ISCIIPanjabi = 57011;
655 private const int ISCIITamil = 57004;
657 private const int ISCIITelugu = 57005;
659 private const int GB18030 = 54936;
661 private const int ISO_8859_8I = 38598;
663 private const int ISO_8859_8_Visual = 28598;
665 private const int ENC50229 = 50229;
667 private const int CodePageUTF7 = 65000;
669 private const int CodePageUTF8 = 65001;
671 private const int CodePageUTF32 = 12000;
673 private const int CodePageUTF32BE = 12001;
675 internal int m_codePage;
677 internal CodePageDataItem dataItem;
680 internal bool m_deserializedFromEverett;
682 [OptionalField(VersionAdded = 2)]
683 private bool m_isReadOnly =
true;
685 [OptionalField(VersionAdded = 2)]
688 [OptionalField(VersionAdded = 2)]
691 private static object s_InternalSyncObject;
693 private static object InternalSyncObject
697 if (s_InternalSyncObject ==
null)
699 object value =
new object();
702 return s_InternalSyncObject;
712 if (dataItem ==
null)
716 return dataItem.BodyName;
722 [__DynamicallyInvokable]
725 [__DynamicallyInvokable]
728 return Environment.GetResourceString(
"Globalization.cp_" + m_codePage);
738 if (dataItem ==
null)
742 return dataItem.HeaderName;
748 [__DynamicallyInvokable]
751 [__DynamicallyInvokable]
754 if (dataItem ==
null)
758 return dataItem.WebName;
768 if (dataItem ==
null)
772 return dataItem.UIFamilyCodePage;
783 if (dataItem ==
null)
787 return (dataItem.Flags & 2) != 0;
798 if (dataItem ==
null)
802 return (dataItem.Flags & 0x200) != 0;
813 if (dataItem ==
null)
817 return (dataItem.Flags & 1) != 0;
828 if (dataItem ==
null)
832 return (dataItem.Flags & 0x100) != 0;
840 [__DynamicallyInvokable]
843 [__DynamicallyInvokable]
855 [__DynamicallyInvokable]
858 [__DynamicallyInvokable]
861 return encoderFallback;
873 encoderFallback = value;
882 [__DynamicallyInvokable]
885 [__DynamicallyInvokable]
888 return decoderFallback;
900 decoderFallback = value;
918 [__DynamicallyInvokable]
921 [__DynamicallyInvokable]
924 if (asciiEncoding ==
null)
928 return asciiEncoding;
936 if (latin1Encoding ==
null)
938 latin1Encoding =
new Latin1Encoding();
940 return latin1Encoding;
946 [__DynamicallyInvokable]
949 [__DynamicallyInvokable]
960 [SecuritySafeCritical]
963 if (defaultEncoding ==
null)
965 defaultEncoding = CreateDefaultEncoding();
967 return defaultEncoding;
973 [__DynamicallyInvokable]
976 [__DynamicallyInvokable]
979 if (unicodeEncoding ==
null)
981 unicodeEncoding =
new UnicodeEncoding(bigEndian:
false, byteOrderMark:
true);
983 return unicodeEncoding;
989 [__DynamicallyInvokable]
992 [__DynamicallyInvokable]
995 if (bigEndianUnicode ==
null)
997 bigEndianUnicode =
new UnicodeEncoding(bigEndian:
true, byteOrderMark:
true);
999 return bigEndianUnicode;
1005 [__DynamicallyInvokable]
1008 [__DynamicallyInvokable]
1011 if (utf7Encoding ==
null)
1015 return utf7Encoding;
1021 [__DynamicallyInvokable]
1024 [__DynamicallyInvokable]
1027 if (utf8Encoding ==
null)
1029 utf8Encoding =
new UTF8Encoding(encoderShouldEmitUTF8Identifier:
true);
1031 return utf8Encoding;
1037 [__DynamicallyInvokable]
1040 [__DynamicallyInvokable]
1043 if (utf32Encoding ==
null)
1045 utf32Encoding =
new UTF32Encoding(bigEndian:
false, byteOrderMark:
true);
1047 return utf32Encoding;
1052 [__DynamicallyInvokable]
1062 [__DynamicallyInvokable]
1069 m_codePage = codePage;
1070 SetDefaultFallbacks();
1079 [__DynamicallyInvokable]
1086 m_codePage = codePage;
1087 this.encoderFallback = (encoderFallback ??
new InternalEncoderBestFitFallback(
this));
1088 this.decoderFallback = (decoderFallback ??
new InternalDecoderBestFitFallback(
this));
1091 internal virtual void SetDefaultFallbacks()
1093 encoderFallback =
new InternalEncoderBestFitFallback(
this);
1094 decoderFallback =
new InternalDecoderBestFitFallback(
this);
1097 internal void OnDeserializing()
1099 encoderFallback =
null;
1100 decoderFallback =
null;
1101 m_isReadOnly =
true;
1104 internal void OnDeserialized()
1106 if (encoderFallback ==
null || decoderFallback ==
null)
1108 m_deserializedFromEverett =
true;
1109 SetDefaultFallbacks();
1136 throw new ArgumentNullException(
"info");
1138 m_codePage = (int)info.GetValue(
"m_codePage", typeof(
int));
1142 m_isReadOnly = (bool)info.GetValue(
"m_isReadOnly", typeof(
bool));
1148 m_deserializedFromEverett =
true;
1149 m_isReadOnly =
true;
1150 SetDefaultFallbacks();
1158 throw new ArgumentNullException(
"info");
1160 info.AddValue(
"m_isReadOnly", m_isReadOnly);
1163 info.AddValue(
"m_codePage", m_codePage);
1164 info.AddValue(
"dataItem",
null);
1165 info.AddValue(
"Encoding+m_codePage", m_codePage);
1166 info.AddValue(
"Encoding+dataItem",
null);
1184 [__DynamicallyInvokable]
1191 return Convert(srcEncoding, dstEncoding, bytes, 0, bytes.Length);
1213 [__DynamicallyInvokable]
1216 if (srcEncoding ==
null || dstEncoding ==
null)
1232 [__DynamicallyInvokable]
1247 [SecuritySafeCritical]
1248 [__DynamicallyInvokable]
1252 if (encoding !=
null)
1256 if (codepage < 0 || codepage > 65535)
1260 if (encodings !=
null)
1262 encoding = (
Encoding)encodings[codepage];
1264 if (encoding ==
null)
1266 lock (InternalSyncObject)
1268 if (encodings ==
null)
1272 if ((encoding = (
Encoding)encodings[codepage]) !=
null)
1288 encoding =
new SBCSCodePageEncoding(codepage);
1305 encoding = GetEncodingCodePage(codepage);
1306 if (encoding ==
null)
1308 encoding = GetEncodingRare(codepage);
1312 encodings.
Add(codepage, encoding);
1330 [__DynamicallyInvokable]
1333 Encoding encodingFromProvider =
EncodingProvider.GetEncodingFromProvider(codepage, encoderFallback, decoderFallback);
1334 if (encodingFromProvider !=
null)
1336 return encodingFromProvider;
1346 private static Encoding GetEncodingRare(
int codepage)
1355 return new UTF32Encoding(bigEndian:
true, byteOrderMark:
true);
1366 return new ISCIIEncoding(codepage);
1368 return new DBCSCodePageEncoding(10008, 20936);
1370 return new DBCSCodePageEncoding(10003, 20949);
1372 return new GB18030Encoding();
1378 return new ISO2022Encoding(codepage);
1381 return new DBCSCodePageEncoding(codepage, 936);
1383 return new EUCJPEncoding();
1385 return new DBCSCodePageEncoding(codepage, 20949);
1389 return new SBCSCodePageEncoding(codepage, 28598);
1398 switch (BaseCodePageEncoding.GetCodePageByteSize(
CodePage))
1401 return new SBCSCodePageEncoding(
CodePage);
1403 return new DBCSCodePageEncoding(
CodePage);
1414 [__DynamicallyInvokable]
1418 if (encodingFromProvider !=
null)
1420 return encodingFromProvider;
1422 return GetEncoding(EncodingTable.GetCodePageFromName(name));
1432 [__DynamicallyInvokable]
1436 if (encodingFromProvider !=
null)
1438 return encodingFromProvider;
1440 return GetEncoding(EncodingTable.GetCodePageFromName(name), encoderFallback, decoderFallback);
1447 return EncodingTable.GetEncodings();
1452 [__DynamicallyInvokable]
1455 return EmptyArray<byte>.Value;
1458 private void GetDataItem()
1460 if (dataItem ==
null)
1462 dataItem = EncodingTable.GetCodePageDataItem(m_codePage);
1463 if (dataItem ==
null)
1473 [__DynamicallyInvokable]
1477 encoding.m_isReadOnly =
false;
1488 [__DynamicallyInvokable]
1505 [__DynamicallyInvokable]
1512 char[] array = s.ToCharArray();
1528 [__DynamicallyInvokable]
1529 public abstract int GetByteCount(
char[] chars,
int index,
int count);
1542 [CLSCompliant(
false)]
1554 char[] array =
new char[count];
1555 for (
int i = 0; i < count; i++)
1557 array[i] = chars[i];
1563 internal unsafe
virtual int GetByteCount(
char* chars,
int count, EncoderNLS encoder)
1575 [__DynamicallyInvokable]
1582 return GetBytes(chars, 0, chars.Length);
1597 [__DynamicallyInvokable]
1598 public virtual byte[]
GetBytes(
char[] chars,
int index,
int count)
1600 byte[] array =
new byte[
GetByteCount(chars, index, count)];
1601 GetBytes(chars, index, count, array, 0);
1623 [__DynamicallyInvokable]
1624 public abstract int GetBytes(
char[] chars,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex);
1633 [__DynamicallyInvokable]
1641 byte[] array =
new byte[byteCount];
1642 int bytes =
GetBytes(s, 0, s.Length, array, 0);
1664 [__DynamicallyInvokable]
1665 public virtual int GetBytes(
string s,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex)
1671 return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
1675 internal unsafe
virtual int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount, EncoderNLS encoder)
1677 return GetBytes(chars, charCount, bytes, byteCount);
1696 [CLSCompliant(
false)]
1698 public unsafe
virtual int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount)
1700 if (bytes ==
null || chars ==
null)
1704 if (charCount < 0 || byteCount < 0)
1708 char[] array =
new char[charCount];
1709 for (
int i = 0; i < charCount; i++)
1711 array[i] = chars[i];
1713 byte[] array2 =
new byte[byteCount];
1714 int bytes2 =
GetBytes(array, 0, charCount, array2, 0);
1715 if (bytes2 < byteCount)
1719 for (
int i = 0; i < byteCount; i++)
1721 bytes[i] = array2[i];
1733 [__DynamicallyInvokable]
1755 [__DynamicallyInvokable]
1756 public abstract int GetCharCount(
byte[] bytes,
int index,
int count);
1769 [CLSCompliant(
false)]
1781 byte[] array =
new byte[count];
1782 for (
int i = 0; i < count; i++)
1784 array[i] = bytes[i];
1790 internal unsafe
virtual int GetCharCount(
byte* bytes,
int count, DecoderNLS decoder)
1802 [__DynamicallyInvokable]
1809 return GetChars(bytes, 0, bytes.Length);
1824 [__DynamicallyInvokable]
1825 public virtual char[]
GetChars(
byte[] bytes,
int index,
int count)
1827 char[] array =
new char[
GetCharCount(bytes, index, count)];
1828 GetChars(bytes, index, count, array, 0);
1850 [__DynamicallyInvokable]
1851 public abstract int GetChars(
byte[] bytes,
int byteIndex,
int byteCount,
char[] chars,
int charIndex);
1869 [CLSCompliant(
false)]
1871 public unsafe
virtual int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount)
1873 if (chars ==
null || bytes ==
null)
1877 if (byteCount < 0 || charCount < 0)
1881 byte[] array =
new byte[byteCount];
1882 for (
int i = 0; i < byteCount; i++)
1884 array[i] = bytes[i];
1886 char[] array2 =
new char[charCount];
1887 int chars2 =
GetChars(array, 0, byteCount, array2, 0);
1888 if (chars2 < charCount)
1892 for (
int i = 0; i < charCount; i++)
1894 chars[i] = array2[i];
1900 internal unsafe
virtual int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount, DecoderNLS decoder)
1902 return GetChars(bytes, byteCount, chars, charCount);
1916 [CLSCompliant(
false)]
1928 return string.CreateStringFromEncoding(bytes, byteCount,
this);
1952 [__DynamicallyInvokable]
1955 return new DefaultDecoder(
this);
1959 private static Encoding CreateDefaultEncoding()
1961 int aCP = Win32Native.GetACP();
1964 return new SBCSCodePageEncoding(aCP);
1971 [__DynamicallyInvokable]
1974 return new DefaultEncoder(
this);
1984 [__DynamicallyInvokable]
1994 [__DynamicallyInvokable]
2005 [__DynamicallyInvokable]
2012 return GetString(bytes, 0, bytes.Length);
2028 [__DynamicallyInvokable]
2029 public virtual string GetString(
byte[] bytes,
int index,
int count)
2031 return new string(
GetChars(bytes, index, count));
2038 [__DynamicallyInvokable]
2042 if (encoding !=
null)
2055 [__DynamicallyInvokable]
2061 internal virtual char[] GetBestFitUnicodeToBytesData()
2063 return EmptyArray<char>.Value;
2066 internal virtual char[] GetBestFitBytesToUnicodeData()
2068 return EmptyArray<char>.Value;
2071 internal void ThrowBytesOverflow()
2073 throw new ArgumentException(Environment.GetResourceString(
"Argument_EncodingConversionOverflowBytes",
EncodingName,
EncoderFallback.GetType()),
"bytes");
2077 internal void ThrowBytesOverflow(EncoderNLS encoder,
bool nothingEncoded)
2079 if ((encoder?.m_throwOnOverflow ??
true) | nothingEncoded)
2081 if (encoder !=
null && encoder.InternalHasFallbackBuffer)
2083 encoder.FallbackBuffer.InternalReset();
2085 ThrowBytesOverflow();
2087 encoder.ClearMustFlush();
2090 internal void ThrowCharsOverflow()
2092 throw new ArgumentException(Environment.GetResourceString(
"Argument_EncodingConversionOverflowChars",
EncodingName,
DecoderFallback.GetType()),
"chars");
2096 internal void ThrowCharsOverflow(DecoderNLS decoder,
bool nothingDecoded)
2098 if ((decoder?.m_throwOnOverflow ??
true) | nothingDecoded)
2100 if (decoder !=
null && decoder.InternalHasFallbackBuffer)
2102 decoder.FallbackBuffer.InternalReset();
2104 ThrowCharsOverflow();
2106 decoder.ClearMustFlush();
Represents a character encoding.To browse the .NET Framework source code for this type,...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
unsafe string GetString(byte *bytes, int byteCount)
When overridden in a derived class, decodes a specified number of bytes starting at a specified addre...
static void RegisterProvider(EncodingProvider provider)
Registers an encoding provider.
virtual unsafe int GetBytes(char *chars, int charCount, byte *bytes, int byteCount)
When overridden in a derived class, encodes a set of characters starting at the specified character p...
virtual char [] GetChars(byte[] bytes)
When overridden in a derived class, decodes all the bytes in the specified byte array into a set of c...
virtual void Add(object key, object value)
Adds an element with the specified key and value into the T:System.Collections.Hashtable.
Converts a set of characters into a sequence of bytes.
virtual byte [] GetBytes(char[] chars)
When overridden in a derived class, encodes all the characters in the specified character array into ...
virtual Encoder GetEncoder()
When overridden in a derived class, obtains an encoder that converts a sequence of Unicode characters...
virtual bool IsBrowserSave
When overridden in a derived class, gets a value indicating whether the current encoding can be used ...
Indicates that the current interface implementer is a reference to another object.
virtual byte [] GetBytes(string s)
When overridden in a derived class, encodes all the characters in the specified string into a sequenc...
static Encoding Default
Gets an encoding for the operating system's current ANSI code page.
static Encoding Unicode
Gets an encoding for the UTF-16 format using the little endian byte order.
abstract int GetMaxCharCount(int byteCount)
When overridden in a derived class, calculates the maximum number of characters produced by decoding ...
virtual object Clone()
When overridden in a derived class, creates a shallow copy of the current T:System....
virtual bool IsAlwaysNormalized(NormalizationForm form)
When overridden in a derived class, gets a value indicating whether the current encoding is always no...
The exception that is thrown when the value of an argument is outside the allowable range of values a...
abstract int Remaining
When overridden in a derived class, gets the number of characters in the current T:System....
DecoderFallback DecoderFallback
Gets or sets the T:System.Text.DecoderFallback object for the current T:System.Text....
static byte [] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes)
Converts an entire byte array from one encoding to another.
static Encoding GetEncoding(int codepage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
Returns the encoding associated with the specified code page identifier. Parameters specify an error ...
bool IsAlwaysNormalized()
Gets a value indicating whether the current encoding is always normalized, using the default normaliz...
virtual int GetCharCount(byte[] bytes)
When overridden in a derived class, calculates the number of characters produced by decoding all the ...
EncoderFallback EncoderFallback
Gets or sets the T:System.Text.EncoderFallback object for the current T:System.Text....
virtual Decoder GetDecoder()
When overridden in a derived class, obtains a decoder that converts an encoded sequence of bytes into...
Describes the source and destination of a given serialized stream, and provides an additional caller-...
virtual unsafe int GetByteCount(char *chars, int count)
When overridden in a derived class, calculates the number of bytes produced by encoding a set of char...
static Encoding GetEncoding(int codepage)
Returns the encoding associated with the specified code page identifier.
virtual string HeaderName
When overridden in a derived class, gets a name for the current encoding that can be used with mail a...
static Encoding ASCII
Gets an encoding for the ASCII (7-bit) character set.
virtual bool IsSingleByte
When overridden in a derived class, gets a value indicating whether the current encoding uses single-...
Provides a failure-handling mechanism, called a fallback, for an input character that cannot be conve...
Encoding(int codePage)
Initializes a new instance of the T:System.Text.Encoding class that corresponds to the specified code...
virtual bool IsMailNewsDisplay
When overridden in a derived class, gets a value indicating whether the current encoding can be used ...
static Encoding BigEndianUnicode
Gets an encoding for the UTF-16 format that uses the big endian byte order.
static EncodingInfo [] GetEncodings()
Returns an array that contains all encodings.
static Encoding UTF32
Gets an encoding for the UTF-32 format using the little endian byte order.
Encoding(int codePage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
Initializes a new instance of the T:System.Text.Encoding class that corresponds to the specified code...
Provides information about, and means to manipulate, the current environment and platform....
override bool Equals(object value)
Determines whether the specified T:System.Object is equal to the current instance.
virtual bool IsMailNewsSave
When overridden in a derived class, gets a value indicating whether the current encoding can be used ...
Represents a UTF-16 encoding of Unicode characters.
virtual int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
When overridden in a derived class, encodes a set of characters from the specified string into the sp...
virtual string WebName
When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Autho...
NormalizationForm
Defines the type of normalization to perform.
Provides a buffer that allows a fallback handler to return an alternate string to a decoder when it c...
virtual int CodePage
When overridden in a derived class, gets the code page identifier of the current T:System....
virtual char [] GetChars(byte[] bytes, int index, int count)
When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a ...
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
Represents a UTF-32 encoding of Unicode characters.
virtual int GetByteCount(string s)
When overridden in a derived class, calculates the number of bytes produced by encoding the character...
Converts a sequence of encoded bytes into a set of characters.
virtual string EncodingName
When overridden in a derived class, gets the human-readable description of the current encoding.
Represents a UTF-7 encoding of Unicode characters.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that can...
Represents a UTF-8 encoding of Unicode characters.
Represents an ASCII character encoding of Unicode characters.
virtual byte [] GetBytes(char[] chars, int index, int count)
When overridden in a derived class, encodes a set of characters from the specified character array in...
The exception thrown when an error occurs during serialization or deserialization.
static Encoding GetEncoding(string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
Returns the encoding associated with the specified code page name. Parameters specify an error handle...
abstract DecoderFallbackBuffer CreateFallbackBuffer()
When overridden in a derived class, initializes a new instance of the T:System.Text....
virtual unsafe int GetCharCount(byte *bytes, int count)
When overridden in a derived class, calculates the number of characters produced by decoding a sequen...
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
virtual string GetString(byte[] bytes)
When overridden in a derived class, decodes all the bytes in the specified byte array into a string.
virtual string GetString(byte[] bytes, int index, int count)
When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a ...
The exception that is thrown when one of the arguments provided to a method is not valid.
static byte [] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes, int index, int count)
Converts a range of bytes in a byte array from one encoding to another.
virtual unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount)
When overridden in a derived class, decodes a sequence of bytes starting at the specified byte pointe...
Allows an object to control its own serialization and deserialization.
virtual byte [] GetPreamble()
When overridden in a derived class, returns a sequence of bytes that specifies the encoding used.
virtual bool IsBrowserDisplay
When overridden in a derived class, gets a value indicating whether the current encoding can be used ...
virtual string BodyName
When overridden in a derived class, gets a name for the current encoding that can be used with mail a...
static Encoding UTF7
Gets an encoding for the UTF-7 format.
override int GetHashCode()
Returns the hash code for the current instance.
bool IsReadOnly
When overridden in a derived class, gets a value indicating whether the current encoding is read-only...
Provides a buffer that allows a fallback handler to return an alternate string to an encoder when it ...
Specifies that the class can be serialized.
static Encoding GetEncoding(string name)
Returns the encoding associated with the specified code page name.
static Encoding UTF8
Gets an encoding for the UTF-8 format.
virtual int GetByteCount(char[] chars)
When overridden in a derived class, calculates the number of bytes produced by encoding all the chara...
The exception that is thrown when a method call is invalid for the object's current state.
Encoding()
Initializes a new instance of the T:System.Text.Encoding class.
abstract EncoderFallbackBuffer CreateFallbackBuffer()
When overridden in a derived class, initializes a new instance of the T:System.Text....
virtual int WindowsCodePage
When overridden in a derived class, gets the Windows operating system code page that most closely cor...
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
abstract bool MovePrevious()
When overridden in a derived class, causes the next call to the M:System.Text.EncoderFallbackBuffer....
abstract int GetMaxByteCount(int charCount)
When overridden in a derived class, calculates the maximum number of bytes produced by encoding the s...
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
Provides atomic operations for variables that are shared by multiple threads.
Provides basic information about an encoding.
Provides the base class for an encoding provider, which supplies encodings that are unavailable on a ...