52 return new byte[4] { 0, 0, 254, 255 };
54 return new byte[4] { 255, 254, 0, 0 };
63 : this(bigEndian: false, byteOrderMark: true)
68 : base(bigEndian ? 12001 : 12000)
74 public UTF32Encoding(
bool bigEndian,
bool byteOrderMark,
bool throwOnInvalidCharacters)
75 : this(bigEndian, byteOrderMark)
116 fixed (
char* ptr =
chars)
128 fixed (
char* pChars =
s)
134 [CLSCompliant(
false)]
150 if (
s ==
null ||
bytes ==
null)
162 if (byteIndex < 0 || byteIndex >
bytes.Length)
167 fixed (
char* ptr =
s)
190 if (byteIndex < 0 || byteIndex >
bytes.Length)
199 fixed (
char* ptr =
chars)
208 [CLSCompliant(
false)]
240 fixed (
byte* ptr =
bytes)
246 [CLSCompliant(
false)]
274 if (charIndex < 0 || charIndex >
chars.Length)
283 fixed (
byte* ptr =
bytes)
292 [CLSCompliant(
false)]
324 fixed (
byte* ptr =
bytes)
326 return string.CreateStringFromEncoding(ptr +
index,
count,
this);
333 char* charStart =
chars;
363 if (
char.IsLowSurrogate(c2))
370 char* chars2 =
chars;
375 else if (
char.IsHighSurrogate(c2))
379 else if (
char.IsLowSurrogate(c2))
381 char* chars2 =
chars;
392 if ((encoder !=
null && !encoder.
MustFlush) || c <=
'\0')
396 char* chars2 =
chars;
444 if (!
char.IsLowSurrogate(c2))
455 if (
bytes + 3 < ptr4)
460 *(
bytes++) = (
byte)(surrogate >> 16);
461 *(
bytes++) = (
byte)(surrogate >> 8);
462 *(
bytes++) = (
byte)surrogate;
466 *(
bytes++) = (
byte)surrogate;
467 *(
bytes++) = (
byte)(surrogate >> 8);
468 *(
bytes++) = (
byte)(surrogate >> 16);
487 if (
char.IsHighSurrogate(c2))
492 if (
char.IsLowSurrogate(c2))
499 if (
bytes + 3 < ptr4)
505 *(
bytes++) = (
byte)((uint)c2 >> 8);
506 *(
bytes++) = (
byte)c2;
510 *(
bytes++) = (
byte)c2;
511 *(
bytes++) = (
byte)((uint)c2 >> 8);
528 if ((encoder !=
null && !encoder.
MustFlush) || c <=
'\0')
539 encoder._charLeftOver = c;
540 encoder._charsUsed = (int)(
chars - ptr);
542 return (
int)(
bytes - ptr3);
550 byte* byteStart =
bytes;
554 if (uTF32Decoder !=
null)
557 num3 = (uint)uTF32Decoder.
iChar;
565 while (bytes < ptr && num >= 0)
575 num3 += (uint)(*(
bytes++) << 24);
583 if (num3 > 1114111 || (num3 >= 55296 && num3 <= 57343))
611 if (num2 > 0 && (uTF32Decoder ==
null || uTF32Decoder.
MustFlush))
613 byte[]
array =
new byte[num2];
618 array[--num2] = (byte)num3;
626 array[--num2] = (byte)(num3 >> 24);
649 if (uTF32Decoder !=
null)
652 num2 = (uint)uTF32Decoder.
iChar;
670 num2 += (uint)(*(
bytes++) << 24);
678 if (num2 > 1114111 || (num2 >= 55296 && num2 <= 57343))
693 char* chars2 =
chars;
709 if (
chars >= ptr2 - 1)
719 else if (
chars >= ptr2)
726 *(
chars++) = (
char)num2;
729 if (num > 0 && (uTF32Decoder ==
null || uTF32Decoder.
MustFlush))
731 byte[]
array =
new byte[num];
737 array[--num3] = (byte)num2;
745 array[--num3] = (byte)(num2 >> 24);
749 char* chars2 =
chars;
763 if (uTF32Decoder !=
null)
765 uTF32Decoder.iChar = (int)num2;
766 uTF32Decoder.readByteCount = num;
767 uTF32Decoder._bytesUsed = (int)(
bytes - ptr3);
769 return (
int)(
chars - ptr);
774 return (uint)((cHigh - 55296) * 1024 + (cLow - 56320) + 65536);
779 return (
char)((iChar - 65536) / 1024 + 55296);
784 return (
char)((iChar - 65536) % 1024 + 56320);
804 if (base.EncoderFallback.MaxCharCount > 1)
806 num *= base.EncoderFallback.MaxCharCount;
809 if (num >
int.MaxValue)
823 if (base.DecoderFallback.MaxCharCount > 2)
825 num *= base.DecoderFallback.MaxCharCount;
828 if (num >
int.MaxValue)
841 return new byte[4] { 255, 254, 0, 0 };
843 return new byte[4] { 0, 0, 254, 255 };
845 return Array.Empty<
byte>();
852 if (
_emitUTF32ByteOrderMark == uTF32Encoding._emitUTF32ByteOrderMark &&
_bigEndian == uTF32Encoding._bigEndian && base.EncoderFallback.Equals(uTF32Encoding.EncoderFallback))
854 return base.DecoderFallback.Equals(uTF32Encoding.DecoderFallback);
static string ArgumentOutOfRange_Index
static string Argument_EncoderFallbackNotEmpty
static string ArgumentOutOfRange_IndexCount
static string ArgumentOutOfRange_GetCharCountOverflow
static string ArgumentOutOfRange_GetByteCountOverflow
static string Format(string resourceFormat, object p1)
static string ArgumentOutOfRange_IndexCountBuffer
static string ArgumentNull_Array
static string ArgumentOutOfRange_NeedNonNegNum
unsafe void InternalInitialize(byte *byteStart, char *charEnd)
virtual unsafe bool InternalFallback(byte[] bytes, byte *pBytes, ref char *chars)
unsafe void InternalReset()
static DecoderFallback ExceptionFallback
DecoderFallbackBuffer CreateFallbackBuffer()
new DecoderFallbackBuffer FallbackBuffer
DecoderFallbackBuffer _fallbackBuffer
bool InternalFallback(ReadOnlySpan< char > chars, out int charsConsumed)
unsafe void InternalInitialize(char *charStart, char *charEnd, EncoderNLS encoder, bool setEncoder)
char InternalGetNextChar()
EncoderFallbackBuffer CreateFallbackBuffer()
static EncoderFallback ExceptionFallback
new EncoderFallback Fallback
new EncoderFallbackBuffer FallbackBuffer
EncoderFallback encoderFallback
void ThrowBytesOverflow()
DecoderFallback decoderFallback
virtual string EncodingName
void ThrowCharsOverflow()
UTF32Decoder(UTF32Encoding encoding)
unsafe override int GetByteCount(string s)
override void SetDefaultFallbacks()
unsafe override int GetByteCount(char[] chars, int index, int count)
static readonly UTF32Encoding s_bigEndianDefault
unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount)
override int GetMaxCharCount(int byteCount)
static char GetHighSurrogate(uint iChar)
readonly bool _emitUTF32ByteOrderMark
override Encoder GetEncoder()
override int GetMaxByteCount(int charCount)
unsafe override int GetCharCount(byte *bytes, int count, DecoderNLS baseDecoder)
unsafe override string GetString(byte[] bytes, int index, int count)
override int GetHashCode()
unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
unsafe override int GetBytes(char *chars, int charCount, byte *bytes, int byteCount)
unsafe override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
override byte[] GetPreamble()
unsafe override int GetBytes(char *chars, int charCount, byte *bytes, int byteCount, EncoderNLS encoder)
unsafe override int GetByteCount(char *chars, int count, EncoderNLS encoder)
unsafe override int GetCharCount(byte[] bytes, int index, int count)
UTF32Encoding(bool bigEndian, bool byteOrderMark)
UTF32Encoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidCharacters)
unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
readonly bool _isThrowException
unsafe override int GetByteCount(char *chars, int count)
override Decoder GetDecoder()
override bool Equals([NotNullWhen(true)] object? value)
unsafe override int GetCharCount(byte *bytes, int count)
override ReadOnlySpan< byte > Preamble
static uint GetSurrogate(char cHigh, char cLow)
unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder)
static char GetLowSurrogate(uint iChar)
static readonly UTF32Encoding s_default
static void ThrowArgumentNullException(string name)