public unsafe override string GetString(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 (count == 0) { return(string.Empty); } int num = count / 2; string text = string.InternalAllocateStr(num); fixed(byte *ptr = ref (bytes != null && bytes.Length != 0)?ref bytes[0] : ref *null) { fixed(string text2 = text) { fixed(char *chars = text2 + RuntimeHelpers.OffsetToStringData / 2) { this.GetCharsInternal(ptr + index, count, chars, num); text2 = null; ptr = null; return(text); } } } }
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) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } int num = byteCount; while (num-- > 0) { chars[charIndex++] = (char)bytes[byteIndex++]; } return(byteCount); }
/// <summary>Calculates the maximum number of characters produced by decoding the specified number of bytes.</summary> /// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns> /// <param name="byteCount">The number of bytes to decode. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="byteCount" /> is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. </exception> /// <exception cref="T:System.Text.DecoderFallbackException">A fallback occurred (see Understanding Encodings for complete explanation)-and-<see cref="P:System.Text.Encoding.DecoderFallback" /> is set to <see cref="T:System.Text.DecoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) { throw new ArgumentOutOfRangeException("byteCount", Encoding._("ArgRange_NonNegative")); } return(byteCount / 4); }
private unsafe int GetCharsInternal(byte *bytes, int byteCount, char *chars, int charCount) { int num = byteCount / 2; if (charCount < num) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } UnicodeEncoding.CopyChars(bytes, (byte *)chars, byteCount, this.bigEndian); return(num); }
/// <summary>Decodes a sequence of bytes from the specified byte array into the specified character array.</summary> /// <returns>The actual number of characters written into <paramref name="chars" />.</returns> /// <param name="bytes">The byte array containing the sequence of bytes to decode. </param> /// <param name="byteIndex">The index of the first byte to decode. </param> /// <param name="byteCount">The number of bytes to decode. </param> /// <param name="chars">The character array to contain the resulting set of characters. </param> /// <param name="charIndex">The index at which to start writing the resulting set of characters. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="bytes" /> is null (Nothing).-or- <paramref name="chars" /> is null (Nothing). </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="byteIndex" /> or <paramref name="byteCount" /> or <paramref name="charIndex" /> is less than zero.-or- <paramref name="byteindex" /> and <paramref name="byteCount" /> do not denote a valid range in <paramref name="bytes" />.-or- <paramref name="charIndex" /> is not a valid index in <paramref name="chars" />. </exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="chars" /> does not have enough capacity from <paramref name="charIndex" /> to the end of the array to accommodate the resulting characters. </exception> /// <exception cref="T:System.Text.DecoderFallbackException">A fallback occurred (see Understanding Encodings for complete explanation)-and-<see cref="P:System.Text.Encoding.DecoderFallback" /> is set to <see cref="T:System.Text.DecoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { int num = 0; int result = UTF7Encoding.InternalGetChars(bytes, byteIndex, byteCount, chars, charIndex, ref num); if ((num & 67108864) != 0) { throw new ArgumentException(Encoding._("Arg_InvalidUTF7"), "chars"); } return(result); }
/// <summary>Calculates the maximum number of bytes produced by encoding the specified number of characters.</summary> /// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns> /// <param name="charCount">The number of characters to encode. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="charCount" /> is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an int. </exception> /// <exception cref="T:System.Text.EncoderFallbackException">A fallback occurred (see Understanding Encodings for complete explanation)-and-<see cref="P:System.Text.Encoding.EncoderFallback" /> is set to <see cref="T:System.Text.EncoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> public override int GetMaxByteCount(int charCount) { if (charCount < 0) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_NonNegative")); } if (charCount == 0) { return(0); } return(8 * (charCount / 3) + charCount % 3 * 3 + 2); }
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); }
/// <summary>Decodes a sequence of bytes from the specified byte array into the specified character array.</summary> /// <returns>The actual number of characters written into <paramref name="chars" />.</returns> /// <param name="bytes">The byte array containing the sequence of bytes to decode. </param> /// <param name="byteIndex">The index of the first byte to decode. </param> /// <param name="byteCount">The number of bytes to decode. </param> /// <param name="chars">The character array to contain the resulting set of characters. </param> /// <param name="charIndex">The index at which to start writing the resulting set of characters. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="bytes" /> is null.-or- <paramref name="chars" /> is null. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="byteIndex" /> or <paramref name="byteCount" /> or <paramref name="charIndex" /> is less than zero.-or- <paramref name="byteindex" /> and <paramref name="byteCount" /> do not denote a valid range in <paramref name="bytes" />.-or- <paramref name="charIndex" /> is not a valid index in <paramref name="chars" />. </exception> /// <exception cref="T:System.ArgumentException">Error detection is enabled, and <paramref name="bytes" /> contains an invalid sequence of bytes.-or- <paramref name="chars" /> does not have enough capacity from <paramref name="charIndex" /> to the end of the array to accommodate the resulting characters. </exception> /// <exception cref="T:System.Text.DecoderFallbackException">A fallback occurred (see Understanding Encodings for complete explanation)-and-<see cref="P:System.Text.Encoding.DecoderFallback" /> is set to <see cref="T:System.Text.DecoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> 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); }
/// <summary>Calculates the number of bytes produced by encoding a set of characters from the specified character array.</summary> /// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <param name="chars">The character array containing the set of characters to encode. </param> /// <param name="index">The index of the first character to encode. </param> /// <param name="count">The number of characters to encode. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="chars" /> is null (Nothing). </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="index" /> or <paramref name="count" /> is less than zero.-or- <paramref name="index" /> and <paramref name="count" /> do not denote a valid range in <paramref name="chars" />.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. </exception> /// <exception cref="T:System.ArgumentException">Error detection is enabled, and <paramref name="chars" /> contains an invalid sequence of characters. </exception> /// <exception cref="T:System.Text.EncoderFallbackException">A fallback occurred (see Understanding Encodings for fuller explanation)-and-<see cref="P:System.Text.Encoding.EncoderFallback" /> is set to <see cref="T:System.Text.EncoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> 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 * 2); }
/// <summary>Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.</summary> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <param name="bytes">The byte array containing the sequence of bytes to decode. </param> /// <param name="index">The index of the first byte to decode. </param> /// <param name="count">The number of bytes to decode. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="bytes" /> is null. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="index" /> or <paramref name="count" /> is less than zero.-or- <paramref name="index" /> and <paramref name="count" /> do not denote a valid range in <paramref name="bytes" />.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. </exception> /// <exception cref="T:System.ArgumentException">Error detection is enabled, and <paramref name="bytes" /> contains an invalid sequence of bytes. </exception> /// <exception cref="T:System.Text.DecoderFallbackException">A fallback occurred (see Understanding Encodings for complete explanation)-and-<see cref="P:System.Text.Encoding.DecoderFallback" /> is set to <see cref="T:System.Text.DecoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> 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); }
/// <summary>Decodes a range of bytes from a byte array into a string.</summary> /// <returns>A <see cref="T:System.String" /> containing the results of decoding the specified sequence of bytes.</returns> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="byteIndex">The index of the first byte to decode.</param> /// <param name="byteCount">The number of bytes to decode.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="bytes" /> is null. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="index" /> or <paramref name="count" /> is less than zero.-or- <paramref name="index" /> and <paramref name="count" /> do not denote a valid range in <paramref name="bytes" />. </exception> /// <exception cref="T:System.Text.DecoderFallbackException">A fallback occurred (see Understanding Encodings for complete explanation)-and-<see cref="P:System.Text.Encoding.DecoderFallback" /> is set to <see cref="T:System.Text.DecoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> 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); } } } }
/// <summary>Encodes a set of characters from the specified <see cref="T:System.String" /> into the specified byte array.</summary> /// <returns>The actual number of bytes written into <paramref name="bytes" />.</returns> /// <param name="s">The <see cref="T:System.String" /> containing the set of characters to encode. </param> /// <param name="charIndex">The index of the first character to encode. </param> /// <param name="charCount">The number of characters to encode. </param> /// <param name="bytes">The byte array to contain the resulting sequence of bytes. </param> /// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="s" /> is null (Nothing).-or- <paramref name="bytes" /> is null (Nothing). </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="charIndex" /> or <paramref name="charCount" /> or <paramref name="byteIndex" /> is less than zero.-or- <paramref name="charIndex" /> and <paramref name="charCount" /> do not denote a valid range in <paramref name="chars" />.-or- <paramref name="byteIndex" /> is not a valid index in <paramref name="bytes" />. </exception> /// <exception cref="T:System.ArgumentException">Error detection is enabled, and <paramref name="s" /> contains an invalid sequence of characters.-or- <paramref name="bytes" /> does not have enough capacity from <paramref name="byteIndex" /> to the end of the array to accommodate the resulting bytes. </exception> /// <exception cref="T:System.Text.EncoderFallbackException">A fallback occurred (see Understanding Encodings for fuller explanation)-and-<see cref="P:System.Text.Encoding.EncoderFallback" /> is set to <see cref="T:System.Text.EncoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> public unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { if (s == null) { throw new ArgumentNullException("s"); } if (bytes == null) { throw new ArgumentNullException("bytes"); } if (charIndex < 0 || charIndex > s.Length) { throw new ArgumentOutOfRangeException("charIndex", Encoding._("ArgRange_StringIndex")); } if (charCount < 0 || charCount > s.Length - charIndex) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_StringRange")); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (charCount == 0) { return(0); } int byteCount = bytes.Length - byteIndex; if (bytes.Length == 0) { bytes = new byte[1]; } fixed(char *ptr = s + RuntimeHelpers.OffsetToStringData / 2) { fixed(byte *ptr2 = ref (bytes != null && bytes.Length != 0)?ref bytes[0] : ref *null) { return(this.GetBytesInternal(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount)); } } }
/// <summary>Decodes a sequence of bytes from the specified byte array into the specified character array.</summary> /// <returns>The actual number of characters written into <paramref name="chars" />.</returns> /// <param name="bytes">The byte array containing the sequence of bytes to decode. </param> /// <param name="byteIndex">The index of the first byte to decode. </param> /// <param name="byteCount">The number of bytes to decode. </param> /// <param name="chars">The character array to contain the resulting set of characters. </param> /// <param name="charIndex">The index at which to start writing the resulting set of characters. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="bytes" /> is null (Nothing).-or- <paramref name="chars" /> is null (Nothing). </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="byteIndex" /> or <paramref name="byteCount" /> or <paramref name="charIndex" /> is less than zero.-or- <paramref name="byteindex" /> and <paramref name="byteCount" /> do not denote a valid range in <paramref name="bytes" />.-or- <paramref name="charIndex" /> is not a valid index in <paramref name="chars" />. </exception> /// <exception cref="T:System.ArgumentException">Error detection is enabled, and <paramref name="bytes" /> contains an invalid sequence of bytes.-or- <paramref name="chars" /> does not have enough capacity from <paramref name="charIndex" /> to the end of the array to accommodate the resulting characters. </exception> /// <exception cref="T:System.Text.DecoderFallbackException">A fallback occurred (see Understanding Encodings for fuller explanation)-and-<see cref="P:System.Text.Encoding.DecoderFallback" /> is set to <see cref="T:System.Text.DecoderExceptionFallback" />.</exception> /// <filterpriority>1</filterpriority> public unsafe 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 (byteCount == 0) { return(0); } int charCount = chars.Length - charIndex; if (chars.Length == 0) { chars = new char[1]; } fixed(byte *ptr = ref (bytes != null && bytes.Length != 0)?ref bytes[0] : ref *null) { fixed(char *ptr2 = ref (chars != null && chars.Length != 0)?ref chars[0] : ref *null) { return(this.GetCharsInternal(ptr + byteIndex, byteCount, ptr2 + charIndex, charCount)); } } }
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); }
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); }
private static int InternalGetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, bool flush, ref int leftOver, ref bool isInShifted, bool allowOptionals) { 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")); } int num = byteIndex; int num2 = bytes.Length; int i = leftOver >> 8; int num3 = leftOver & 255; byte[] array = UTF7Encoding.encodingRules; string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; while (charCount > 0) { int num4 = (int)chars[charIndex++]; charCount--; int num5; if (num4 < 128) { num5 = (int)array[num4]; } else { num5 = 0; } switch (num5) { case 0: break; case 1: goto IL_19D; case 2: if (allowOptionals) { goto IL_19D; } break; case 3: if (isInShifted) { if (i != 0) { if (num + 1 > num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } bytes[num++] = (byte)text[num3 << 6 - i]; } if (num + 1 > num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } bytes[num++] = 45; isInShifted = false; i = 0; num3 = 0; } if (num + 2 > num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } bytes[num++] = 43; bytes[num++] = 45; continue; default: continue; } if (!isInShifted) { if (num >= num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } bytes[num++] = 43; isInShifted = true; i = 0; } num3 = (num3 << 16 | num4); i += 16; while (i >= 6) { if (num >= num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } i -= 6; bytes[num++] = (byte)text[num3 >> i]; num3 &= (1 << i) - 1; } continue; IL_19D: if (isInShifted) { if (i != 0) { if (num + 1 > num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } bytes[num++] = (byte)text[num3 << 6 - i]; } if (num + 1 > num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } bytes[num++] = 45; isInShifted = false; i = 0; num3 = 0; } if (num >= num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } bytes[num++] = (byte)num4; } if (isInShifted && flush) { if (i != 0) { if (num + 1 > num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "bytes"); } bytes[num++] = (byte)text[num3 << 6 - i]; } bytes[num++] = 45; i = 0; num3 = 0; isInShifted = false; } leftOver = (i << 8 | num3); return(num - byteIndex); }
private static int InternalGetByteCount(char[] chars, int index, int count, bool flush, int leftOver, bool isInShifted, bool allowOptionals) { 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; int i = leftOver >> 8; byte[] array = UTF7Encoding.encodingRules; while (count > 0) { int num2 = (int)chars[index++]; count--; int num3; if (num2 < 128) { num3 = (int)array[num2]; } else { num3 = 0; } switch (num3) { case 0: break; case 1: goto IL_E3; case 2: if (allowOptionals) { goto IL_E3; } break; case 3: if (isInShifted) { if (i != 0) { num++; i = 0; } num++; isInShifted = false; } num += 2; continue; default: continue; } if (!isInShifted) { num++; i = 0; isInShifted = true; } for (i += 16; i >= 6; i -= 6) { num++; } continue; IL_E3: if (isInShifted) { if (i != 0) { num++; i = 0; } num++; isInShifted = false; } num++; } if (isInShifted && flush) { if (i != 0) { num++; } num++; } return(num); }
private static int InternalGetCharCount(byte[] bytes, int index, int count, int leftOver) { 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")); } int num = 0; bool flag = (leftOver & 16777216) == 0; bool flag2 = (leftOver & 33554432) != 0; int num2 = leftOver >> 16 & 255; sbyte[] array = UTF7Encoding.base64Values; while (count > 0) { int num3 = (int)bytes[index++]; count--; if (flag) { if (num3 != 43) { num++; } else { flag = false; flag2 = true; } } else { if (num3 == 45) { if (flag2) { num++; } num2 = 0; flag = true; } else if ((int)array[num3] != -1) { num2 += 6; if (num2 >= 16) { num++; num2 -= 16; } } else { num++; flag = true; num2 = 0; } flag2 = false; } } return(num); }
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); }
private static int InternalGetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, ref int leftOver) { 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 = chars.Length; bool flag = (leftOver & 16777216) == 0; bool flag2 = (leftOver & 33554432) != 0; bool flag3 = (leftOver & 67108864) != 0; int num3 = leftOver >> 16 & 255; int num4 = leftOver & 65535; sbyte[] array = UTF7Encoding.base64Values; while (byteCount > 0) { int num5 = (int)bytes[byteIndex++]; byteCount--; if (flag) { if (num5 != 43) { if (num >= num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "chars"); } if (flag3) { throw new ArgumentException(Encoding._("Arg_InvalidUTF7"), "chars"); } chars[num++] = (char)num5; } else { flag = false; flag2 = true; } } else { int num6; if (num5 == 45) { if (flag2) { if (num >= num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "chars"); } if (flag3) { throw new ArgumentException(Encoding._("Arg_InvalidUTF7"), "chars"); } chars[num++] = '+'; } flag = true; num3 = 0; num4 = 0; } else if ((num6 = (int)array[num5]) != -1) { num4 = (num4 << 6 | num6); num3 += 6; if (num3 >= 16) { if (num >= num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "chars"); } num3 -= 16; char c = (char)(num4 >> num3); if ((c & 'ﰀ') == '\ud800') { flag3 = true; } else if ((c & 'ﰀ') == '\udc00') { if (!flag3) { throw new ArgumentException(Encoding._("Arg_InvalidUTF7"), "chars"); } flag3 = false; } chars[num++] = c; num4 &= (1 << num3) - 1; } } else { if (num >= num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace"), "chars"); } if (flag3) { throw new ArgumentException(Encoding._("Arg_InvalidUTF7"), "chars"); } chars[num++] = (char)num5; flag = true; num3 = 0; num4 = 0; } flag2 = false; } } leftOver = (num4 | num3 << 16 | ((!flag) ? 16777216 : 0) | ((!flag2) ? 0 : 33554432) | ((!flag3) ? 0 : 67108864)); return(num - charIndex); }
public unsafe 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 (byteCount == 0) { return(0); } int num = this.leftOverByte; int num2; if (num != -1) { num2 = (byteCount + 1) / 2; } else { num2 = byteCount / 2; } if (chars.Length - charIndex < num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } if (num != -1) { if (this.bigEndian) { chars[charIndex] = (char)(num << 8 | (int)bytes[byteIndex]); } else { chars[charIndex] = (char)((int)bytes[byteIndex] << 8 | num); } charIndex++; byteIndex++; byteCount--; } if ((byteCount & -2) != 0) { fixed(byte *ptr = ref (bytes != null && bytes.Length != 0)?ref bytes[0] : ref *null) { fixed(char *ptr2 = ref (chars != null && chars.Length != 0)?ref chars[0] : ref *null) { UnicodeEncoding.CopyChars(ptr + byteIndex, (byte *)(ptr2 + charIndex), byteCount, this.bigEndian); } } } if ((byteCount & 1) == 0) { this.leftOverByte = -1; } else { this.leftOverByte = (int)bytes[byteCount + byteIndex - 1]; } return(num2); }
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); }