10 [__DynamicallyInvokable]
16 internal int surrogateChar;
18 internal override bool HasState => surrogateChar != 0;
32 surrogateChar = (int)info.GetValue(
"surrogateChar", typeof(
int));
50 info.AddValue(
"encoding", m_encoding);
51 info.AddValue(
"surrogateChar", surrogateChar);
52 info.AddValue(
"m_fallback", m_fallback);
53 info.AddValue(
"storedSurrogate", (surrogateChar > 0) ?
true :
false);
54 info.AddValue(
"mustFlush", value:
false);
57 public override void Reset()
60 if (m_fallbackBuffer !=
null)
62 m_fallbackBuffer.Reset();
72 internal override bool HasState => bits != 0;
88 bits = (int)info.GetValue(
"wbits", typeof(
int));
105 info.AddValue(
"encoding", m_encoding);
106 info.AddValue(
"wbits", bits);
107 info.AddValue(
"m_fallback", m_fallback);
108 info.AddValue(
"bits", 0);
109 info.AddValue(
"trailCount", 0);
110 info.AddValue(
"isSurrogate", value:
false);
111 info.AddValue(
"byteSequence", 0);
114 public override void Reset()
117 if (m_fallbackBuffer !=
null)
119 m_fallbackBuffer.Reset();
124 private const int UTF8_CODEPAGE = 65001;
126 private bool emitUTF8Identifier;
128 private bool isThrowException;
130 private const int FinalByte = 536870912;
132 private const int SupplimentarySeq = 268435456;
134 private const int ThreeByteSeq = 134217728;
137 [__DynamicallyInvokable]
139 : this(encoderShouldEmitUTF8Identifier: false)
146 [__DynamicallyInvokable]
148 : this(encoderShouldEmitUTF8Identifier, throwOnInvalidBytes: false)
157 [__DynamicallyInvokable]
158 public UTF8Encoding(
bool encoderShouldEmitUTF8Identifier,
bool throwOnInvalidBytes)
161 emitUTF8Identifier = encoderShouldEmitUTF8Identifier;
162 isThrowException = throwOnInvalidBytes;
163 if (isThrowException)
165 SetDefaultFallbacks();
169 internal override void SetDefaultFallbacks()
171 if (isThrowException)
178 encoderFallback =
new EncoderReplacementFallback(
"�");
179 decoderFallback =
new DecoderReplacementFallback(
"�");
195 [SecuritySafeCritical]
196 [__DynamicallyInvokable]
197 public unsafe
override int GetByteCount(
char[] chars,
int index,
int count)
203 if (index < 0 || count < 0)
207 if (chars.Length - index < count)
211 if (chars.Length == 0)
215 fixed (
char* ptr = chars)
230 [SecuritySafeCritical]
231 [__DynamicallyInvokable]
238 fixed (
char* chars2 = chars)
256 [CLSCompliant(
false)]
289 [SecuritySafeCritical]
290 [__DynamicallyInvokable]
291 public unsafe
override int GetBytes(
string s,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex)
293 if (s ==
null || bytes ==
null)
297 if (charIndex < 0 || charCount < 0)
301 if (s.Length - charIndex < charCount)
305 if (byteIndex < 0 || byteIndex > bytes.Length)
309 int byteCount = bytes.Length - byteIndex;
310 if (bytes.Length == 0)
314 fixed (
char* ptr = s)
316 byte[] array = bytes;
317 fixed (
byte* ptr2 = array)
319 return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount,
null);
342 [SecuritySafeCritical]
343 [__DynamicallyInvokable]
344 public unsafe
override int GetBytes(
char[] chars,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex)
346 if (chars ==
null || bytes ==
null)
350 if (charIndex < 0 || charCount < 0)
354 if (chars.Length - charIndex < charCount)
358 if (byteIndex < 0 || byteIndex > bytes.Length)
362 if (chars.Length == 0)
366 int byteCount = bytes.Length - byteIndex;
367 if (bytes.Length == 0)
371 fixed (
char* ptr = chars)
373 byte[] array = bytes;
374 fixed (
byte* ptr2 = array)
376 return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount,
null);
397 [CLSCompliant(
false)]
399 public unsafe
override int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount)
401 if (bytes ==
null || chars ==
null)
405 if (charCount < 0 || byteCount < 0)
409 return GetBytes(chars, charCount, bytes, byteCount,
null);
425 [SecuritySafeCritical]
426 [__DynamicallyInvokable]
427 public unsafe
override int GetCharCount(
byte[] bytes,
int index,
int count)
433 if (index < 0 || count < 0)
437 if (bytes.Length - index < count)
441 if (bytes.Length == 0)
445 fixed (
byte* ptr = bytes)
463 [CLSCompliant(
false)]
496 [SecuritySafeCritical]
497 [__DynamicallyInvokable]
498 public unsafe
override int GetChars(
byte[] bytes,
int byteIndex,
int byteCount,
char[] chars,
int charIndex)
500 if (bytes ==
null || chars ==
null)
504 if (byteIndex < 0 || byteCount < 0)
508 if (bytes.Length - byteIndex < byteCount)
512 if (charIndex < 0 || charIndex > chars.Length)
516 if (bytes.Length == 0)
520 int charCount = chars.Length - charIndex;
521 if (chars.Length == 0)
525 fixed (
byte* ptr = bytes)
527 char[] array = chars;
528 fixed (
char* ptr2 = array)
530 return GetChars(ptr + byteIndex, byteCount, ptr2 + charIndex, charCount,
null);
551 [CLSCompliant(
false)]
553 public unsafe
override int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount)
555 if (bytes ==
null || chars ==
null)
559 if (charCount < 0 || byteCount < 0)
563 return GetChars(bytes, byteCount, chars, charCount,
null);
579 [SecuritySafeCritical]
581 [__DynamicallyInvokable]
582 public unsafe
override string GetString(
byte[] bytes,
int index,
int count)
588 if (index < 0 || count < 0)
592 if (bytes.Length - index < count)
596 if (bytes.Length == 0)
600 fixed (
byte* ptr = bytes)
602 return string.CreateStringFromEncoding(ptr + index, count,
this);
607 internal unsafe
override int GetByteCount(
char* chars,
int count, EncoderNLS baseEncoder)
610 char* chars2 = chars;
611 char* ptr = chars2 + count;
614 if (baseEncoder !=
null)
616 UTF8Encoder uTF8Encoder = (UTF8Encoder)baseEncoder;
617 num2 = uTF8Encoder.surrogateChar;
618 if (uTF8Encoder.InternalHasFallbackBuffer)
620 encoderFallbackBuffer = uTF8Encoder.FallbackBuffer;
625 encoderFallbackBuffer.InternalInitialize(chars, ptr, uTF8Encoder, setEncoder:
false);
634 num2 = (encoderFallbackBuffer?.InternalGetNextChar() ??
'\0');
643 if (encoderFallbackBuffer ==
null || !encoderFallbackBuffer.bFallingBack)
647 num2 = encoderFallbackBuffer.InternalGetNextChar();
649 if (InRange(num2, 56320, 57343))
668 if (InRange(ch, 56320, 57343))
675 if (encoderFallbackBuffer !=
null)
677 num2 = encoderFallbackBuffer.InternalGetNextChar();
689 if (InRange(num2, 55296, 56319))
696 if (InRange(num2, 55296, 57343))
698 if (encoderFallbackBuffer ==
null)
700 encoderFallbackBuffer = ((baseEncoder !=
null) ? baseEncoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
701 encoderFallbackBuffer.InternalInitialize(chars, chars + count, baseEncoder, setEncoder:
false);
703 encoderFallbackBuffer.InternalFallback((
char)num2, ref chars2);
720 if (encoderFallbackBuffer !=
null && (num2 = encoderFallbackBuffer.InternalGetNextChar()) != 0)
725 int num3 = PtrDiff(ptr, chars2);
729 while (chars2 < ptr2)
742 char* ptr3 = chars2 + num3 - 7;
743 while (chars2 < ptr3)
751 if ((num2 & 0xF800) == 55296)
759 if (((
int)chars2 & 2) != 0)
767 if ((num2 & 0xF800) == 55296)
776 for (; chars2 < ptr3; chars2 += 4)
778 num2 = *(
int*)chars2;
779 int num4 = *(
int*)(chars2 + 2);
780 if (((num2 | num4) & -8323200) != 0)
782 if (((num2 | num4) & -134154240) != 0)
786 if ((num2 & -8388608) != 0)
790 if ((num2 & 0xFF80) != 0)
794 if ((num4 & -8388608) != 0)
798 if ((num4 & 0xFF80) != 0)
804 num2 = *(
int*)chars2;
805 num4 = *(
int*)(chars2 + 2);
806 if (((num2 | num4) & -8323200) == 0)
810 if (((num2 | num4) & -134154240) == 0)
812 if ((num2 & -8388608) != 0)
816 if ((num2 & 0xFF80) != 0)
820 if ((num4 & -8388608) != 0)
824 if ((num4 & 0xFF80) != 0)
836 if (InRange(num2, 55296, 57343))
839 if (num2 > 56319 || !InRange(ch2, 56320, 57343))
862 if (num2 <= 0 || (baseEncoder !=
null && !baseEncoder.MustFlush))
871 throw new ArgumentException(Environment.GetResourceString(
"Argument_ConversionOverflow"));
877 private unsafe
static int PtrDiff(
char* a,
char* b)
879 return (
int)((uint)((
byte*)a - (
byte*)b) >> 1);
883 private unsafe
static int PtrDiff(
byte* a,
byte* b)
888 private static bool InRange(
int ch,
int start,
int end)
890 return (uint)(ch - start) <= (uint)(end - start);
894 internal unsafe
override int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount, EncoderNLS baseEncoder)
896 UTF8Encoder uTF8Encoder =
null;
897 EncoderFallbackBuffer encoderFallbackBuffer =
null;
898 char* chars2 = chars;
900 char* ptr2 = chars2 + charCount;
901 byte* ptr3 = ptr + byteCount;
903 if (baseEncoder !=
null)
905 uTF8Encoder = (UTF8Encoder)baseEncoder;
906 num = uTF8Encoder.surrogateChar;
907 if (uTF8Encoder.InternalHasFallbackBuffer)
909 encoderFallbackBuffer = uTF8Encoder.FallbackBuffer;
910 if (encoderFallbackBuffer.Remaining > 0 && uTF8Encoder.m_throwOnOverflow)
912 throw new ArgumentException(Environment.GetResourceString(
"Argument_EncoderFallbackNotEmpty",
EncodingName, uTF8Encoder.Fallback.GetType()));
914 encoderFallbackBuffer.InternalInitialize(chars, ptr2, uTF8Encoder, setEncoder:
true);
923 num = (encoderFallbackBuffer?.InternalGetNextChar() ??
'\0');
931 if (encoderFallbackBuffer ==
null || !encoderFallbackBuffer.bFallingBack)
936 num = encoderFallbackBuffer.InternalGetNextChar();
937 if (InRange(num, 56320, 57343))
939 num = num + (num2 << 10) + -56613888;
953 if (InRange(num3, 56320, 57343))
955 num = num3 + (num << 10) + -56613888;
960 if (encoderFallbackBuffer !=
null)
962 num = encoderFallbackBuffer.InternalGetNextChar();
973 if (InRange(num, 55296, 57343))
975 if (encoderFallbackBuffer ==
null)
977 encoderFallbackBuffer = ((baseEncoder !=
null) ? baseEncoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
978 encoderFallbackBuffer.InternalInitialize(chars, ptr2, baseEncoder, setEncoder:
true);
980 encoderFallbackBuffer.InternalFallback((
char)num, ref chars2);
997 if (ptr > ptr3 - num4)
999 if (encoderFallbackBuffer !=
null && encoderFallbackBuffer.bFallingBack)
1001 encoderFallbackBuffer.MovePrevious();
1004 encoderFallbackBuffer.MovePrevious();
1015 ThrowBytesOverflow(uTF8Encoder, ptr == bytes);
1028 num5 = (byte)(-64 | (num >> 6));
1034 num5 = (byte)(-32 | (num >> 12));
1038 *ptr = (byte)(-16 | (num >> 18));
1040 num5 = (-128 | ((num >> 12) & 0x3F));
1044 num5 = (-128 | ((num >> 6) & 0x3F));
1048 *ptr = (byte)(-128 | (num & 0x3F));
1051 if (encoderFallbackBuffer ==
null || (num = encoderFallbackBuffer.InternalGetNextChar()) == 0)
1053 int num6 = PtrDiff(ptr2, chars2);
1054 int num7 = PtrDiff(ptr3, ptr);
1063 while (chars2 < ptr4)
1082 char* ptr5 = chars2 + num6 - 5;
1083 while (chars2 < ptr5)
1091 if (((
int)chars2 & 2) != 0)
1102 while (chars2 < ptr5)
1104 num = *(
int*)chars2;
1105 int num8 = *(
int*)(chars2 + 2);
1106 if (((num | num8) & -8323200) == 0)
1109 ptr[1] = (byte)(num >> 16);
1111 ptr[2] = (byte)num8;
1112 ptr[3] = (byte)(num8 >> 16);
1135 num9 = (-64 | (num >> 6));
1139 if (!InRange(num, 55296, 57343))
1141 num9 = (-32 | (num >> 12));
1152 if (!InRange(num9, 56320, 57343))
1157 num = num9 + (num << 10) + -56613888;
1158 *ptr = (byte)(-16 | (num >> 18));
1160 num9 = (-128 | ((num >> 12) & 0x3F));
1165 num9 = (-128 | ((num >> 6) & 0x3F));
1170 *ptr = (byte)(-128 | (num & 0x3F));
1178 if (num <= 0 || (uTF8Encoder !=
null && !uTF8Encoder.MustFlush))
1184 if (InRange(num, 55296, 56319))
1190 if (uTF8Encoder !=
null)
1192 uTF8Encoder.surrogateChar = num;
1193 uTF8Encoder.m_charsUsed = (int)(chars2 - chars);
1195 return (
int)(ptr - bytes);
1199 internal unsafe
override int GetCharCount(
byte* bytes,
int count, DecoderNLS baseDecoder)
1202 byte* ptr2 = ptr + count;
1205 DecoderFallbackBuffer decoderFallbackBuffer =
null;
1206 if (baseDecoder !=
null)
1208 UTF8Decoder uTF8Decoder = (UTF8Decoder)baseDecoder;
1209 num2 = uTF8Decoder.bits;
1218 if ((num3 & -64) != 128)
1225 num2 = ((num2 << 6) | (num3 & 0x3F));
1226 if ((num2 & 0x20000000) != 0)
1228 if ((num2 & 0x101F0000) == 268435456)
1234 if ((num2 & 0x10000000) != 0)
1236 if ((num2 & 0x800000) != 0 || InRange(num2 & 0x1F0, 16, 256))
1241 else if ((num2 & 0x3E0) != 0 && (num2 & 0x3E0) != 864)
1252 int num4 = PtrDiff(ptr2, ptr);
1269 byte* ptr4 = ptr + num4 - 7;
1280 if (((
int)ptr & 1) != 0)
1289 if (((
int)ptr & 2) != 0)
1291 num2 = *(ushort*)ptr;
1292 if ((num2 & 0x8080) != 0)
1301 int num5 = *(
int*)(ptr + 4);
1302 if (((num2 | num5) & -2139062144) == 0)
1310 num5 = *(
int*)(ptr + 4);
1311 if (((num2 | num5) & -2139062144) == 0)
1325 if ((num2 & 0x40) != 0 && (num6 & -64) == 128)
1328 if ((num2 & 0x20) != 0)
1330 num6 |= (num2 & 0xF) << 6;
1331 if ((num2 & 0x10) != 0)
1334 if (InRange(num6 >> 4, 1, 16) && (num2 & -64) == 128)
1336 num6 = ((num6 << 6) | (num2 & 0x3F));
1338 if ((num2 & -64) == 128)
1349 if ((num6 & 0x3E0) != 0 && (num6 & 0x3E0) != 864 && (num2 & -64) == 128)
1357 else if ((num2 & 0x1E) != 0)
1379 if (decoderFallbackBuffer ==
null)
1381 decoderFallbackBuffer = ((baseDecoder !=
null) ? baseDecoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1382 decoderFallbackBuffer.InternalInitialize(bytes,
null);
1384 num += FallbackInvalidByteSequence(ptr, num2, decoderFallbackBuffer);
1391 if ((num2 & 0x40) != 0)
1393 if ((num2 & 0x20) != 0)
1395 if ((num2 & 0x10) == 0)
1397 num2 = ((num2 & 0xF) | 0x48228000);
1428 if (baseDecoder ==
null || baseDecoder.MustFlush)
1430 if (decoderFallbackBuffer ==
null)
1432 decoderFallbackBuffer = ((baseDecoder !=
null) ? baseDecoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1433 decoderFallbackBuffer.InternalInitialize(bytes,
null);
1435 num += FallbackInvalidByteSequence(ptr, num2, decoderFallbackBuffer);
1442 internal unsafe
override int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount, DecoderNLS baseDecoder)
1445 char* pTarget = chars;
1446 byte* ptr = pSrc + byteCount;
1447 char* ptr2 = pTarget + charCount;
1449 DecoderFallbackBuffer decoderFallbackBuffer =
null;
1450 if (baseDecoder !=
null)
1452 UTF8Decoder uTF8Decoder = (UTF8Decoder)baseDecoder;
1453 num = uTF8Decoder.bits;
1461 if ((num2 & -64) != 128)
1467 num = ((num << 6) | (num2 & 0x3F));
1468 if ((num & 0x20000000) != 0)
1470 if ((num & 0x101F0000) > 268435456 && pTarget < ptr2)
1472 *pTarget = (char)(((num >> 10) & 0x7FF) + -10304);
1474 num = (num & 0x3FF) + 56320;
1478 if ((num & 0x10000000) != 0)
1480 if ((num & 0x800000) != 0 || InRange(num & 0x1F0, 16, 256))
1485 else if ((num & 0x3E0) != 0 && (num & 0x3E0) != 864)
1496 if (pTarget >= ptr2)
1503 if (num >= 56320 && num <= 57343)
1508 else if (num > 65535)
1517 ThrowCharsOverflow(baseDecoder, pTarget == chars);
1521 *pTarget = (char)num;
1523 int num3 = PtrDiff(ptr2, pTarget);
1524 int num4 = PtrDiff(ptr, pSrc);
1539 *pTarget = (char)num;
1552 char* ptr4 = pTarget + num4 - 7;
1563 *pTarget = (char)num;
1565 if (((
int)pSrc & 1) != 0)
1573 *pTarget = (char)num;
1576 if (((
int)pSrc & 2) != 0)
1578 num = *(ushort*)pSrc;
1579 if ((num & 0x8080) != 0)
1583 *pTarget = (char)(num & 0x7F);
1585 pTarget[1] = (char)((num >> 8) & 0x7F);
1588 while (pTarget < ptr4)
1591 int num5 = *(
int*)(pSrc + 4);
1592 if (((num | num5) & -2139062144) == 0)
1594 *pTarget = (char)(num & 0x7F);
1595 pTarget[1] = (char)((num >> 8) & 0x7F);
1596 pTarget[2] = (char)((num >> 16) & 0x7F);
1597 pTarget[3] = (char)((num >> 24) & 0x7F);
1599 pTarget[4] = (char)(num5 & 0x7F);
1600 pTarget[5] = (char)((num5 >> 8) & 0x7F);
1601 pTarget[6] = (char)((num5 >> 16) & 0x7F);
1602 pTarget[7] = (char)((num5 >> 24) & 0x7F);
1614 if ((num & 0x40) != 0 && (num6 & -64) == 128)
1617 if ((num & 0x20) != 0)
1619 num6 |= (num & 0xF) << 6;
1620 if ((num & 0x10) != 0)
1623 if (InRange(num6 >> 4, 1, 16) && (num & -64) == 128)
1625 num6 = ((num6 << 6) | (num & 0x3F));
1627 if ((num & -64) == 128)
1630 num = ((num6 << 6) | (num & 0x3F));
1631 *pTarget = (char)(((num >> 10) & 0x7FF) + -10304);
1633 num = (num & 0x3FF) + -9216;
1642 if ((num6 & 0x3E0) != 0 && (num6 & 0x3E0) != 864 && (num & -64) == 128)
1645 num = ((num6 << 6) | (num & 0x3F));
1656 num = ((num << 6) | num6);
1665 *pTarget = (char)num;
1674 *pTarget = (char)num;
1684 if ((num & 0x40) != 0)
1686 if ((num & 0x20) != 0)
1688 if ((num & 0x10) == 0)
1690 num = ((num & 0xF) | 0x48228000);
1716 if (decoderFallbackBuffer ==
null)
1718 decoderFallbackBuffer = ((baseDecoder !=
null) ? baseDecoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1719 decoderFallbackBuffer.InternalInitialize(bytes, ptr2);
1721 if (!FallbackInvalidByteSequence(ref pSrc, num, decoderFallbackBuffer, ref pTarget))
1723 decoderFallbackBuffer.InternalReset();
1724 ThrowCharsOverflow(baseDecoder, pTarget == chars);
1730 if (num != 0 && (baseDecoder ==
null || baseDecoder.MustFlush))
1732 if (decoderFallbackBuffer ==
null)
1734 decoderFallbackBuffer = ((baseDecoder !=
null) ? baseDecoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1735 decoderFallbackBuffer.InternalInitialize(bytes, ptr2);
1737 if (!FallbackInvalidByteSequence(ref pSrc, num, decoderFallbackBuffer, ref pTarget))
1739 decoderFallbackBuffer.InternalReset();
1740 ThrowCharsOverflow(baseDecoder, pTarget == chars);
1744 if (baseDecoder !=
null)
1746 UTF8Decoder uTF8Decoder2 = (UTF8Decoder)baseDecoder;
1747 uTF8Decoder2.bits = num;
1748 baseDecoder.m_bytesUsed = (int)(pSrc - bytes);
1750 return PtrDiff(pTarget, chars);
1754 private unsafe
bool FallbackInvalidByteSequence(ref
byte* pSrc,
int ch, DecoderFallbackBuffer fallback, ref
char* pTarget)
1757 byte[] bytesUnknown = GetBytesUnknown(ref pSrc2, ch);
1758 if (!fallback.InternalFallback(bytesUnknown, pSrc, ref pTarget))
1767 private unsafe
int FallbackInvalidByteSequence(
byte* pSrc,
int ch, DecoderFallbackBuffer fallback)
1769 byte[] bytesUnknown = GetBytesUnknown(ref pSrc, ch);
1770 return fallback.InternalFallback(bytesUnknown, pSrc);
1774 private unsafe
byte[] GetBytesUnknown(ref
byte* pSrc,
int ch)
1776 byte[] array =
null;
1777 if (ch < 256 && ch >= 0)
1785 if ((ch & 0x18000000) == 0)
1790 (byte)((ch & 0x1F) | 0xC0)
1793 if ((ch & 0x10000000) != 0)
1795 if ((ch & 0x800000) != 0)
1800 (byte)(((ch >> 12) & 7) | 0xF0),
1801 (byte)(((ch >> 6) & 0x3F) | 0x80),
1802 (byte)((ch & 0x3F) | 0x80)
1805 if ((ch & 0x20000) != 0)
1810 (byte)(((ch >> 6) & 7) | 0xF0),
1811 (byte)((ch & 0x3F) | 0x80)
1817 (byte)((ch & 7) | 0xF0)
1820 if ((ch & 0x800000) != 0)
1825 (byte)(((ch >> 6) & 0xF) | 0xE0),
1826 (byte)((ch & 0x3F) | 0x80)
1832 (byte)((ch & 0xF) | 0xE0)
1838 [__DynamicallyInvokable]
1841 return new UTF8Decoder(
this);
1846 [__DynamicallyInvokable]
1849 return new UTF8Encoder(
this);
1859 [__DynamicallyInvokable]
1866 long num = (long)charCount + 1
L;
1867 if (base.EncoderFallback.MaxCharCount > 1)
1869 num *= base.EncoderFallback.MaxCharCount;
1872 if (num >
int.MaxValue)
1886 [__DynamicallyInvokable]
1893 long num = (long)byteCount + 1
L;
1894 if (base.DecoderFallback.MaxCharCount > 1)
1896 num *= base.DecoderFallback.MaxCharCount;
1898 if (num >
int.MaxValue)
1907 [__DynamicallyInvokable]
1910 if (emitUTF8Identifier)
1919 return EmptyArray<byte>.Value;
1926 [__DynamicallyInvokable]
1930 if (uTF8Encoding !=
null)
1932 if (emitUTF8Identifier == uTF8Encoding.emitUTF8Identifier && base.EncoderFallback.Equals(uTF8Encoding.
EncoderFallback))
1943 [__DynamicallyInvokable]
1946 return base.EncoderFallback.GetHashCode() + base.DecoderFallback.GetHashCode() + 65001 + (emitUTF8Identifier ? 1 : 0);
Represents a character encoding.To browse the .NET Framework source code for this type,...
override Decoder GetDecoder()
Obtains a decoder that converts a UTF-8 encoded sequence of bytes into a sequence of Unicode characte...
override Encoder GetEncoder()
Obtains an encoder that converts a sequence of Unicode characters into a UTF-8 encoded sequence of by...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Converts a set of characters into a sequence of bytes.
unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
Encodes a set of characters from the specified T:System.String into the specified byte array.
unsafe override int GetBytes(char *chars, int charCount, byte *bytes, int byteCount)
Encodes a set of characters starting at the specified character pointer into a sequence of bytes that...
override int GetMaxCharCount(int byteCount)
Calculates the maximum number of characters produced by decoding the specified number of bytes.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
UTF8Encoding(bool encoderShouldEmitUTF8Identifier)
Initializes a new instance of the T:System.Text.UTF8Encoding class. A parameter specifies whether to ...
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 DecoderFallback ExceptionFallback
Gets an object that throws an exception when an input byte sequence cannot be decoded.
unsafe override int GetByteCount(char *chars, int count)
Calculates the number of bytes produced by encoding a set of characters starting at the specified cha...
EncoderFallback EncoderFallback
Gets or sets the T:System.Text.EncoderFallback object for the current T:System.Text....
Describes the source and destination of a given serialized stream, and provides an additional caller-...
override int GetHashCode()
Returns the hash code for the current instance.
unsafe override string GetString(byte[] bytes, int index, int count)
Decodes a range of bytes from a byte array into a string.
Provides a failure-handling mechanism, called a fallback, for an input character that cannot be conve...
unsafe override int GetCharCount(byte[] bytes, int index, int count)
Calculates the number of characters produced by decoding a sequence of bytes from the specified byte ...
override byte [] GetPreamble()
Returns a Unicode byte order mark encoded in UTF-8 format, if the T:System.Text.UTF8Encoding encoding...
unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount)
Decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are ...
Provides information about, and means to manipulate, the current environment and platform....
unsafe override int GetByteCount(char[] chars, int index, int count)
Calculates the number of bytes produced by encoding a set of characters from the specified character ...
UTF8Encoding(bool encoderShouldEmitUTF8Identifier, bool throwOnInvalidBytes)
Initializes a new instance of the T:System.Text.UTF8Encoding class. Parameters specify whether to pro...
unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
Decodes a sequence of bytes from the specified byte array into the specified character array.
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.
Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that can...
Represents a UTF-8 encoding of Unicode characters.
The exception thrown when an error occurs during serialization or deserialization.
unsafe override int GetByteCount(string chars)
Calculates the number of bytes produced by encoding the characters in the specified T:System....
UTF8Encoding()
Initializes a new instance of the T:System.Text.UTF8Encoding class.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
override int GetMaxByteCount(int charCount)
Calculates the maximum number of bytes produced by encoding the specified number of characters.
unsafe override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
Encodes a set of characters from the specified character array into the specified byte array.
The exception that is thrown when one of the arguments provided to a method is not valid.
Allows an object to control its own serialization and deserialization.
override bool Equals(object value)
Determines whether the specified object is equal to the current T:System.Text.UTF8Encoding object.
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.
Encoding()
Initializes a new instance of the T:System.Text.Encoding class.
static EncoderFallback ExceptionFallback
Gets an object that throws an exception when an input character cannot be encoded.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
unsafe override int GetCharCount(byte *bytes, int count)
Calculates the number of characters produced by decoding a sequence of bytes starting at the specifie...