using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Text { /// Represents an ASCII character encoding of Unicode characters. /// 1 // Token: 0x020005DE RID: 1502 [ComVisible(true)] [MonoTODO("Serialization format not compatible with .NET")] [Serializable] public class ASCIIEncoding : Encoding { /// Initializes a new instance of the class. // Token: 0x060036B6 RID: 14006 RVA: 0x000BB950 File Offset: 0x000B9B50 public ASCIIEncoding() : base(20127) { this.body_name = (this.header_name = (this.web_name = "us-ascii")); this.encoding_name = "US-ASCII"; this.is_mail_news_display = true; this.is_mail_news_save = true; } /// Gets a value indicating whether the current encoding uses single-byte code points. /// This property is always true. /// 2 // Token: 0x17000AB4 RID: 2740 // (get) Token: 0x060036B7 RID: 14007 RVA: 0x000BB9A0 File Offset: 0x000B9BA0 [ComVisible(false)] public override bool IsSingleByte { get { return true; } } /// 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. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x060036B8 RID: 14008 RVA: 0x000BB9A4 File Offset: 0x000B9BA4 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")); } return count; } /// 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. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x060036B9 RID: 14009 RVA: 0x000BBA10 File Offset: 0x000B9C10 public override int GetByteCount(string chars) { if (chars == null) { throw new ArgumentNullException("chars"); } return chars.Length; } /// 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 . /// /// 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: 0x060036BA RID: 14010 RVA: 0x000BBA2C File Offset: 0x000B9C2C public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { EncoderFallbackBuffer encoderFallbackBuffer = null; char[] array = null; return this.GetBytes(chars, charIndex, charCount, bytes, byteIndex, ref encoderFallbackBuffer, ref array); } // Token: 0x060036BB RID: 14011 RVA: 0x000BBA50 File Offset: 0x000B9C50 private int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, ref EncoderFallbackBuffer buffer, ref char[] fallback_chars) { 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) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } int num = charCount; while (num-- > 0) { char c = chars[charIndex++]; if (c < '\u0080') { bytes[byteIndex++] = (byte)c; } else { if (buffer == null) { buffer = base.EncoderFallback.CreateFallbackBuffer(); } if (char.IsSurrogate(c) && num > 1 && char.IsSurrogate(chars[charIndex])) { buffer.Fallback(c, chars[charIndex], charIndex++ - 1); } else { buffer.Fallback(c, charIndex - 1); } if (fallback_chars == null || fallback_chars.Length < buffer.Remaining) { fallback_chars = new char[buffer.Remaining]; } for (int i = 0; i < fallback_chars.Length; i++) { fallback_chars[i] = buffer.GetNextChar(); } byteIndex += this.GetBytes(fallback_chars, 0, fallback_chars.Length, bytes, byteIndex, ref buffer, ref fallback_chars); } } return charCount; } /// 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 . /// /// 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: 0x060036BC RID: 14012 RVA: 0x000BBC10 File Offset: 0x000B9E10 public override int GetBytes(string chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { EncoderFallbackBuffer encoderFallbackBuffer = null; char[] array = null; return this.GetBytes(chars, charIndex, charCount, bytes, byteIndex, ref encoderFallbackBuffer, ref array); } // Token: 0x060036BD RID: 14013 RVA: 0x000BBC34 File Offset: 0x000B9E34 private int GetBytes(string chars, int charIndex, int charCount, byte[] bytes, int byteIndex, ref EncoderFallbackBuffer buffer, ref char[] fallback_chars) { 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_StringIndex")); } if (charCount < 0 || charCount > chars.Length - charIndex) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_StringRange")); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (bytes.Length - byteIndex < charCount) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } int num = charCount; while (num-- > 0) { char c = chars[charIndex++]; if (c < '\u0080') { bytes[byteIndex++] = (byte)c; } else { if (buffer == null) { buffer = base.EncoderFallback.CreateFallbackBuffer(); } if (char.IsSurrogate(c) && num > 1 && char.IsSurrogate(chars[charIndex])) { buffer.Fallback(c, chars[charIndex], charIndex++ - 1); } else { buffer.Fallback(c, charIndex - 1); } if (fallback_chars == null || fallback_chars.Length < buffer.Remaining) { fallback_chars = new char[buffer.Remaining]; } for (int i = 0; i < fallback_chars.Length; i++) { fallback_chars[i] = buffer.GetNextChar(); } byteIndex += this.GetBytes(fallback_chars, 0, fallback_chars.Length, bytes, byteIndex, ref buffer, ref fallback_chars); } } return charCount; } /// 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. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x060036BE RID: 14014 RVA: 0x000BBE04 File Offset: 0x000BA004 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; } /// 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 . /// /// 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: 0x060036BF RID: 14015 RVA: 0x000BBE70 File Offset: 0x000BA070 public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { DecoderFallbackBuffer decoderFallbackBuffer = null; return this.GetChars(bytes, byteIndex, byteCount, chars, charIndex, ref decoderFallbackBuffer); } // Token: 0x060036C0 RID: 14016 RVA: 0x000BBE90 File Offset: 0x000BA090 private int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, ref DecoderFallbackBuffer buffer) { 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) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } int num = byteCount; while (num-- > 0) { char c = (char)bytes[byteIndex++]; if (c < '\u0080') { chars[charIndex++] = c; } else { if (buffer == null) { buffer = base.DecoderFallback.CreateFallbackBuffer(); } buffer.Fallback(bytes, byteIndex); while (buffer.Remaining > 0) { chars[charIndex++] = buffer.GetNextChar(); } } } return byteCount; } /// 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. /// 1 // Token: 0x060036C1 RID: 14017 RVA: 0x000BBFD0 File Offset: 0x000BA1D0 public override int GetMaxByteCount(int charCount) { if (charCount < 0) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_NonNegative")); } return charCount; } /// 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. /// 1 // Token: 0x060036C2 RID: 14018 RVA: 0x000BBFF0 File Offset: 0x000BA1F0 public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) { throw new ArgumentOutOfRangeException("byteCount", Encoding._("ArgRange_NonNegative")); } return byteCount; } /// 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 . /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x060036C3 RID: 14019 RVA: 0x000BC010 File Offset: 0x000BA210 public unsafe override string GetString(byte[] bytes, int byteIndex, int byteCount) { if (bytes == null) { throw new ArgumentNullException("bytes"); } 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 (byteCount == 0) { return string.Empty; } fixed (byte* ptr = (ref bytes != null && bytes.Length != 0 ? ref bytes[0] : ref *null)) { string text = string.InternalAllocateStr(byteCount); fixed (string text2 = text) { fixed (char* ptr2 = text2 + RuntimeHelpers.OffsetToStringData / 2) { byte* ptr3 = ptr + byteIndex; byte* ptr4 = ptr3 + byteCount; char* ptr5 = ptr2; while (ptr3 < ptr4) { byte b = *(ptr3++); *(ptr5++) = ((b > 127) ? '?' : ((char)b)); } text2 = null; return text; } } } } /// 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 . /// 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. /// /// is less than the resulting number of bytes. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x060036C4 RID: 14020 RVA: 0x000BC0FC File Offset: 0x000BA2FC [CLSCompliant(false)] [ComVisible(false)] public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { if (chars == null) { throw new ArgumentNullException("chars"); } if (bytes == null) { throw new ArgumentNullException("bytes"); } if (charCount < 0) { throw new ArgumentOutOfRangeException("charCount"); } if (byteCount < 0) { throw new ArgumentOutOfRangeException("byteCount"); } if (byteCount < charCount) { throw new ArgumentException("bytecount is less than the number of bytes required", "byteCount"); } for (int i = 0; i < charCount; i++) { char c = chars[i]; bytes[i] = (byte)((c >= '\u0080') ? '?' : c); } return charCount; } /// 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. /// /// is less than the resulting number of characters. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x060036C5 RID: 14021 RVA: 0x000BC19C File Offset: 0x000BA39C [CLSCompliant(false)] [ComVisible(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (chars == null) { throw new ArgumentNullException("chars"); } if (charCount < 0) { throw new ArgumentOutOfRangeException("charCount"); } if (byteCount < 0) { throw new ArgumentOutOfRangeException("byteCount"); } if (charCount < byteCount) { throw new ArgumentException("charcount is less than the number of bytes required", "charCount"); } for (int i = 0; i < byteCount; i++) { byte b = bytes[i]; chars[i] = ((b <= 127) ? ((char)b) : '?'); } return byteCount; } /// 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. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x060036C6 RID: 14022 RVA: 0x000BC238 File Offset: 0x000BA438 [ComVisible(false)] [CLSCompliant(false)] public unsafe override int GetCharCount(byte* bytes, int count) { return count; } /// 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. /// A fallback occurred (see Understanding Encodings for complete explanation)-and- is set to . /// 1 // Token: 0x060036C7 RID: 14023 RVA: 0x000BC23C File Offset: 0x000BA43C [ComVisible(false)] [CLSCompliant(false)] public unsafe override int GetByteCount(char* chars, int count) { return count; } /// Obtains a decoder that converts an ASCII encoded sequence of bytes into a sequence of Unicode characters. /// A that converts an ASCII encoded sequence of bytes into a sequence of Unicode characters. /// 1 // Token: 0x060036C8 RID: 14024 RVA: 0x000BC240 File Offset: 0x000BA440 [ComVisible(false)] [MonoTODO("we have simple override to match method signature.")] public override Decoder GetDecoder() { return base.GetDecoder(); } /// Obtains an encoder that converts a sequence of Unicode characters into an ASCII encoded sequence of bytes. /// An that converts a sequence of Unicode characters into an ASCII encoded sequence of bytes. /// 1 // Token: 0x060036C9 RID: 14025 RVA: 0x000BC248 File Offset: 0x000BA448 [ComVisible(false)] [MonoTODO("we have simple override to match method signature.")] public override Encoder GetEncoder() { return base.GetEncoder(); } // Token: 0x04001662 RID: 5730 internal const int ASCII_CODE_PAGE = 20127; } }