using System; namespace System.Text { /// Represents a UTF-32 encoding of Unicode characters. /// 1 // Token: 0x020005FC RID: 1532 [Serializable] public sealed class UTF32Encoding : Encoding { /// Initializes a new instance of the class. // Token: 0x06003805 RID: 14341 RVA: 0x000C023C File Offset: 0x000BE43C public UTF32Encoding() : this(false, true, false) { } /// Initializes a new instance of the class. Parameters specify whether to use the big endian byte order and whether to provide a Unicode byte order mark. /// true to use the big endian byte order (most significant byte first), or false to use the little endian byte order (least significant byte first). /// true to specify that a Unicode byte order mark is provided; otherwise, false. // Token: 0x06003806 RID: 14342 RVA: 0x000C0248 File Offset: 0x000BE448 public UTF32Encoding(bool bigEndian, bool byteOrderMark) : this(bigEndian, byteOrderMark, false) { } /// Initializes a new instance of the class. Parameters specify whether to use the big endian byte order, whether to provide a Unicode byte order mark, and whether to throw an exception when an invalid encoding is detected. /// true to use the big endian byte order (most significant byte first), or false to use the little endian byte order (least significant byte first). /// true to specify that a Unicode byte order mark is provided; otherwise, false. /// true to specify that an exception should be thrown when an invalid encoding is detected; otherwise, false. // Token: 0x06003807 RID: 14343 RVA: 0x000C0254 File Offset: 0x000BE454 public UTF32Encoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidCharacters) : base((!bigEndian) ? 12000 : 12001) { this.bigEndian = bigEndian; this.byteOrderMark = byteOrderMark; if (throwOnInvalidCharacters) { base.SetFallbackInternal(EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback); } else { base.SetFallbackInternal(new EncoderReplacementFallback("\ufffd"), new DecoderReplacementFallback("\ufffd")); } if (bigEndian) { this.body_name = "utf-32BE"; this.encoding_name = "UTF-32 (Big-Endian)"; this.header_name = "utf-32BE"; this.web_name = "utf-32BE"; } else { this.body_name = "utf-32"; this.encoding_name = "UTF-32"; this.header_name = "utf-32"; this.web_name = "utf-32"; } this.windows_code_page = 12000; } /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// /// is null. /// /// or is less than zero.-or- and do not denote a valid range in .-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of characters. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003808 RID: 14344 RVA: 0x000C0330 File Offset: 0x000BE530 [MonoTODO("handle fallback")] public override int GetByteCount(char[] chars, int index, int count) { if (chars == null) { throw new ArgumentNullException("chars"); } if (index < 0 || index > chars.Length) { throw new ArgumentOutOfRangeException("index", Encoding._("ArgRange_Array")); } if (count < 0 || count > chars.Length - index) { throw new ArgumentOutOfRangeException("count", Encoding._("ArgRange_Array")); } int num = 0; for (int i = index; i < index + count; i++) { if (char.IsSurrogate(chars[i])) { if (i + 1 < chars.Length && char.IsSurrogate(chars[i + 1])) { num += 4; } else { num += 4; } } else { num += 4; } } return num; } /// Encodes a set of characters from the specified character array into the specified byte array. /// The actual number of bytes written into . /// The character array containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. /// The index at which to start writing the resulting sequence of bytes. /// /// is null.-or- is null. /// /// or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . /// Error detection is enabled, and contains an invalid sequence of characters.-or- does not have enough capacity from to the end of the array to accommodate the resulting bytes. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003809 RID: 14345 RVA: 0x000C03F0 File Offset: 0x000BE5F0 [MonoTODO("handle fallback")] public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { if (chars == null) { throw new ArgumentNullException("chars"); } if (bytes == null) { throw new ArgumentNullException("bytes"); } if (charIndex < 0 || charIndex > chars.Length) { throw new ArgumentOutOfRangeException("charIndex", Encoding._("ArgRange_Array")); } if (charCount < 0 || charCount > chars.Length - charIndex) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_Array")); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (bytes.Length - byteIndex < charCount * 4) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } int num = byteIndex; while (charCount-- > 0) { char c = chars[charIndex++]; if (char.IsSurrogate(c)) { if (charCount-- > 0) { int num2 = (int)('Ѐ' * (c - '\ud800')) + 65536 + (int)chars[charIndex++] - 56320; if (this.bigEndian) { for (int i = 0; i < 4; i++) { bytes[num + 3 - i] = (byte)(num2 % 256); num2 >>= 8; } num += 4; } else { for (int j = 0; j < 4; j++) { bytes[num++] = (byte)(num2 % 256); num2 >>= 8; } } } else if (this.bigEndian) { bytes[num++] = 0; bytes[num++] = 0; bytes[num++] = 0; bytes[num++] = 63; } else { bytes[num++] = 63; bytes[num++] = 0; bytes[num++] = 0; bytes[num++] = 0; } } else if (this.bigEndian) { bytes[num++] = 0; bytes[num++] = 0; bytes[num++] = (byte)(c >> 8); bytes[num++] = (byte)c; } else { bytes[num++] = (byte)c; bytes[num++] = (byte)(c >> 8); bytes[num++] = 0; bytes[num++] = 0; } } return num - byteIndex; } /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. /// The index of the first byte to decode. /// The number of bytes to decode. /// /// is null. /// /// or is less than zero.-or- and do not denote a valid range in .-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of bytes. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x0600380A RID: 14346 RVA: 0x000C0638 File Offset: 0x000BE838 public override int GetCharCount(byte[] bytes, int index, int count) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (index < 0 || index > bytes.Length) { throw new ArgumentOutOfRangeException("index", Encoding._("ArgRange_Array")); } if (count < 0 || count > bytes.Length - index) { throw new ArgumentOutOfRangeException("count", Encoding._("ArgRange_Array")); } return count / 4; } /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// The actual number of characters written into . /// The byte array containing the sequence of bytes to decode. /// The index of the first byte to decode. /// The number of bytes to decode. /// The character array to contain the resulting set of characters. /// The index at which to start writing the resulting set of characters. /// /// is null.-or- is null. /// /// or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . /// Error detection is enabled, and contains an invalid sequence of bytes.-or- does not have enough capacity from to the end of the array to accommodate the resulting characters. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x0600380B RID: 14347 RVA: 0x000C06A8 File Offset: 0x000BE8A8 public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (chars == null) { throw new ArgumentNullException("chars"); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (byteCount < 0 || byteCount > bytes.Length - byteIndex) { throw new ArgumentOutOfRangeException("byteCount", Encoding._("ArgRange_Array")); } if (charIndex < 0 || charIndex > chars.Length) { throw new ArgumentOutOfRangeException("charIndex", Encoding._("ArgRange_Array")); } if (chars.Length - charIndex < byteCount / 4) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } int num = charIndex; if (this.bigEndian) { while (byteCount >= 4) { chars[num++] = (char)(((int)bytes[byteIndex] << 24) | ((int)bytes[byteIndex + 1] << 16) | ((int)bytes[byteIndex + 2] << 8) | (int)bytes[byteIndex + 3]); byteIndex += 4; byteCount -= 4; } } else { while (byteCount >= 4) { chars[num++] = (char)((int)bytes[byteIndex] | ((int)bytes[byteIndex + 1] << 8) | ((int)bytes[byteIndex + 2] << 16) | ((int)bytes[byteIndex + 3] << 24)); byteIndex += 4; byteCount -= 4; } } return num - charIndex; } /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. /// /// is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x0600380C RID: 14348 RVA: 0x000C07FC File Offset: 0x000BE9FC public override int GetMaxByteCount(int charCount) { if (charCount < 0) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_NonNegative")); } return charCount * 4; } /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. /// /// is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x0600380D RID: 14349 RVA: 0x000C0820 File Offset: 0x000BEA20 public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) { throw new ArgumentOutOfRangeException("byteCount", Encoding._("ArgRange_NonNegative")); } return byteCount / 4; } /// Obtains a decoder that converts a UTF-32 encoded sequence of bytes into a sequence of Unicode characters. /// A that converts a UTF-32 encoded sequence of bytes into a sequence of Unicode characters. /// 1 // Token: 0x0600380E RID: 14350 RVA: 0x000C0844 File Offset: 0x000BEA44 public override Decoder GetDecoder() { return new UTF32Encoding.UTF32Decoder(this.bigEndian); } /// Returns a Unicode byte order mark encoded in UTF-32 format, if the constructor for this instance requests a byte order mark. /// A byte array containing the Unicode byte order mark, if the constructor for this instance requests a byte order mark. Otherwise, this method returns a byte array of length zero. /// 1 // Token: 0x0600380F RID: 14351 RVA: 0x000C0854 File Offset: 0x000BEA54 public override byte[] GetPreamble() { if (this.byteOrderMark) { byte[] array = new byte[4]; if (this.bigEndian) { array[2] = 254; array[3] = byte.MaxValue; } else { array[0] = byte.MaxValue; array[1] = 254; } return array; } return new byte[0]; } /// Determines whether the specified is equal to the current object. /// true if is an instance of and is equal to the current object; otherwise, false. /// The to compare with the current object. /// 2 // Token: 0x06003810 RID: 14352 RVA: 0x000C08AC File Offset: 0x000BEAAC public override bool Equals(object value) { UTF32Encoding utf32Encoding = value as UTF32Encoding; return utf32Encoding != null && (this.codePage == utf32Encoding.codePage && this.bigEndian == utf32Encoding.bigEndian && this.byteOrderMark == utf32Encoding.byteOrderMark) && base.Equals(value); } /// Returns the hash code for the current instance. /// The hash code for the current object. /// 1 // Token: 0x06003811 RID: 14353 RVA: 0x000C0908 File Offset: 0x000BEB08 public override int GetHashCode() { int num = base.GetHashCode(); if (this.bigEndian) { num ^= 31; } if (this.byteOrderMark) { num ^= 63; } return num; } /// Calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer. /// The number of bytes produced by encoding the specified characters. /// A pointer to the first character to encode. /// The number of characters to encode. /// /// is null. /// /// is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of characters. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003812 RID: 14354 RVA: 0x000C0940 File Offset: 0x000BEB40 [CLSCompliant(false)] public unsafe override int GetByteCount(char* chars, int count) { if (chars == null) { throw new ArgumentNullException("chars"); } return count * 4; } /// Calculates the number of bytes produced by encoding the characters in the specified . /// The number of bytes produced by encoding the specified characters. /// The containing the set of characters to encode. /// /// is null. /// The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of characters. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003813 RID: 14355 RVA: 0x000C0958 File Offset: 0x000BEB58 public override int GetByteCount(string s) { return base.GetByteCount(s); } /// Encodes a set of characters starting at the specified character pointer into a sequence of bytes that are stored starting at the specified byte pointer. /// The actual number of bytes written at the location indicated by the parameter. /// A pointer to the first character to encode. /// The number of characters to encode. /// A pointer to the location at which to start writing the resulting sequence of bytes. /// The maximum number of bytes to write. /// /// is null.-or- is null. /// /// or is less than zero. /// Error detection is enabled, and contains an invalid sequence of characters.-or- is less than the resulting number of bytes. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003814 RID: 14356 RVA: 0x000C0964 File Offset: 0x000BEB64 [CLSCompliant(false)] public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { return base.GetBytes(chars, charCount, bytes, byteCount); } /// Encodes a set of characters from the specified into the specified byte array. /// The actual number of bytes written into . /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. /// The index at which to start writing the resulting sequence of bytes. /// /// is null.-or- is null. /// /// or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . /// Error detection is enabled, and contains an invalid sequence of characters.-or- does not have enough capacity from to the end of the array to accommodate the resulting bytes. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003815 RID: 14357 RVA: 0x000C0974 File Offset: 0x000BEB74 public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { return base.GetBytes(s, charIndex, charCount, bytes, byteIndex); } /// Calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer. /// The number of characters produced by decoding the specified sequence of bytes. /// A pointer to the first byte to decode. /// The number of bytes to decode. /// /// is null. /// /// is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of bytes. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003816 RID: 14358 RVA: 0x000C0984 File Offset: 0x000BEB84 [CLSCompliant(false)] public unsafe override int GetCharCount(byte* bytes, int count) { return base.GetCharCount(bytes, count); } /// Decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are stored starting at the specified character pointer. /// The actual number of characters written at the location indicated by . /// A pointer to the first byte to decode. /// The number of bytes to decode. /// A pointer to the location at which to start writing the resulting set of characters. /// The maximum number of characters to write. /// /// is null.-or- is null. /// /// or is less than zero. /// Error detection is enabled, and contains an invalid sequence of bytes.-or- is less than the resulting number of characters. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003817 RID: 14359 RVA: 0x000C0990 File Offset: 0x000BEB90 [CLSCompliant(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { return base.GetChars(bytes, byteCount, chars, charCount); } /// Decodes a range of bytes from a byte array into a string. /// A containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. /// The index of the first byte to decode. /// The number of bytes to decode. /// /// is null. /// /// or is less than zero.-or- and do not denote a valid range in . /// Error detection is enabled, and contains an invalid sequence of bytes. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x06003818 RID: 14360 RVA: 0x000C09A0 File Offset: 0x000BEBA0 public override string GetString(byte[] bytes, int index, int count) { return base.GetString(bytes, index, count); } /// Obtains an encoder that converts a sequence of Unicode characters into a UTF-32 encoded sequence of bytes. /// A that converts a sequence of Unicode characters into a UTF-32 encoded sequence of bytes. /// 1 // Token: 0x06003819 RID: 14361 RVA: 0x000C09AC File Offset: 0x000BEBAC public override Encoder GetEncoder() { return base.GetEncoder(); } // Token: 0x040016BB RID: 5819 internal const int UTF32_CODE_PAGE = 12000; // Token: 0x040016BC RID: 5820 internal const int BIG_UTF32_CODE_PAGE = 12001; // Token: 0x040016BD RID: 5821 private bool bigEndian; // Token: 0x040016BE RID: 5822 private bool byteOrderMark; // Token: 0x020005FD RID: 1533 private sealed class UTF32Decoder : Decoder { // Token: 0x0600381A RID: 14362 RVA: 0x000C09B4 File Offset: 0x000BEBB4 public UTF32Decoder(bool bigEndian) { this.bigEndian = bigEndian; this.leftOverByte = -1; } // Token: 0x0600381B RID: 14363 RVA: 0x000C09CC File Offset: 0x000BEBCC public override int GetCharCount(byte[] bytes, int index, int count) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (index < 0 || index > bytes.Length) { throw new ArgumentOutOfRangeException("index", Encoding._("ArgRange_Array")); } if (count < 0 || count > bytes.Length - index) { throw new ArgumentOutOfRangeException("count", Encoding._("ArgRange_Array")); } if (this.leftOverByte != -1) { return (count + 1) / 4; } return count / 4; } // Token: 0x0600381C RID: 14364 RVA: 0x000C0A4C File Offset: 0x000BEC4C public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (chars == null) { throw new ArgumentNullException("chars"); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (byteCount < 0 || byteCount > bytes.Length - byteIndex) { throw new ArgumentOutOfRangeException("byteCount", Encoding._("ArgRange_Array")); } if (charIndex < 0 || charIndex > chars.Length) { throw new ArgumentOutOfRangeException("charIndex", Encoding._("ArgRange_Array")); } int num = charIndex; int num2 = this.leftOverByte; int num3 = chars.Length; int num4 = 4 - this.leftOverLength; if (this.leftOverLength > 0 && byteCount > num4) { if (this.bigEndian) { for (int i = 0; i < num4; i++) { num2 += (int)bytes[byteIndex++] << 4 - byteCount--; } } else { for (int j = 0; j < num4; j++) { num2 += (int)bytes[byteIndex++] << byteCount--; } } if ((num2 > 65535 && num + 1 < num3) || num < num3) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } if (num2 > 65535) { chars[num++] = (char)((num2 - 10000) / 1024 + 55296); chars[num++] = (char)((num2 - 10000) % 1024 + 56320); } else { chars[num++] = (char)num2; } this.leftOverLength = 0; } while (byteCount > 3) { char c; if (this.bigEndian) { c = (char)(((int)bytes[byteIndex++] << 24) | ((int)bytes[byteIndex++] << 16) | ((int)bytes[byteIndex++] << 8) | (int)bytes[byteIndex++]); } else { c = (char)((int)bytes[byteIndex++] | ((int)bytes[byteIndex++] << 8) | ((int)bytes[byteIndex++] << 16) | ((int)bytes[byteIndex++] << 24)); } byteCount -= 4; if (num >= num3) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } chars[num++] = c; } if (byteCount > 0) { this.leftOverLength = byteCount; num2 = 0; if (this.bigEndian) { for (int k = 0; k < byteCount; k++) { num2 += (int)bytes[byteIndex++] << 4 - byteCount--; } } else { for (int l = 0; l < byteCount; l++) { num2 += (int)bytes[byteIndex++] << byteCount--; } } this.leftOverByte = num2; } return num - charIndex; } // Token: 0x040016BF RID: 5823 private bool bigEndian; // Token: 0x040016C0 RID: 5824 private int leftOverByte; // Token: 0x040016C1 RID: 5825 private int leftOverLength; } } }