10 [__DynamicallyInvokable]
18 internal int bitCount;
20 internal bool firstByte;
22 internal override bool HasState => bitCount != -1;
35 bits = (int)info.GetValue(
"bits", typeof(
int));
36 bitCount = (int)info.GetValue(
"bitCount", typeof(
int));
37 firstByte = (bool)info.GetValue(
"firstByte", typeof(
bool));
48 info.AddValue(
"encoding", m_encoding);
49 info.AddValue(
"bits", bits);
50 info.AddValue(
"bitCount", bitCount);
51 info.AddValue(
"firstByte", firstByte);
54 public override void Reset()
59 if (m_fallbackBuffer !=
null)
61 m_fallbackBuffer.Reset();
71 internal int bitCount;
73 internal override bool HasState
79 return bitCount != -1;
96 bits = (int)info.GetValue(
"bits", typeof(
int));
97 bitCount = (int)info.GetValue(
"bitCount", typeof(
int));
108 info.AddValue(
"encoding", m_encoding);
109 info.AddValue(
"bits", bits);
110 info.AddValue(
"bitCount", bitCount);
113 public override void Reset()
117 if (m_fallbackBuffer !=
null)
119 m_fallbackBuffer.Reset();
127 public override int MaxCharCount => 1;
131 return new DecoderUTF7FallbackBuffer(
this);
134 public override bool Equals(
object value)
136 DecoderUTF7Fallback decoderUTF7Fallback = value as DecoderUTF7Fallback;
137 if (decoderUTF7Fallback !=
null)
152 private char cFallback;
154 private int iCount = -1;
158 public override int Remaining
170 public DecoderUTF7FallbackBuffer(DecoderUTF7Fallback fallback)
174 public override bool Fallback(
byte[] bytesUnknown,
int index)
176 cFallback = (char)bytesUnknown[0];
177 if (cFallback ==
'\0')
181 iCount = (iSize = 1);
185 public override char GetNextChar()
194 public override bool MovePrevious()
202 return iCount <= iSize;
207 [SecuritySafeCritical]
208 public unsafe
override void Reset()
215 internal unsafe
override int InternalFallback(
byte[] bytes,
byte* pBytes)
217 if (bytes.Length != 1)
229 private const string base64Chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
231 private const string directChars =
"\t\n\r '(),-./0123456789:?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
233 private const string optionalChars =
"!\"#$%&*;<=>@[]^_`{|}";
235 private byte[] base64Bytes;
237 private sbyte[] base64Values;
239 private bool[] directEncode;
241 [OptionalField(VersionAdded = 2)]
242 private bool m_allowOptionals;
244 private const int UTF7_CODEPAGE = 65000;
247 [__DynamicallyInvokable]
249 : this(allowOptionals: false)
256 [__DynamicallyInvokable]
260 m_allowOptionals = allowOptionals;
264 private void MakeTables()
266 base64Bytes =
new byte[64];
267 for (
int i = 0; i < 64; i++)
269 base64Bytes[i] = (byte)
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i];
271 base64Values =
new sbyte[128];
272 for (
int j = 0; j < 128; j++)
274 base64Values[j] = -1;
276 for (
int k = 0; k < 64; k++)
278 base64Values[base64Bytes[k]] = (sbyte)k;
280 directEncode =
new bool[128];
281 int length =
"\t\n\r '(),-./0123456789:?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".Length;
282 for (
int l = 0; l < length; l++)
284 directEncode[
"\t\n\r '(),-./0123456789:?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"[l]] =
true;
286 if (m_allowOptionals)
288 length =
"!\"#$%&*;<=>@[]^_`{|}".Length;
289 for (
int m = 0; m < length; m++)
291 directEncode[
"!\"#$%&*;<=>@[]^_`{|}"[m]] =
true;
296 internal override void SetDefaultFallbacks()
298 encoderFallback =
new EncoderReplacementFallback(
string.Empty);
299 decoderFallback =
new DecoderUTF7Fallback();
312 if (m_deserializedFromEverett)
314 m_allowOptionals = directEncode[
"!\"#$%&*;<=>@[]^_`{|}"[0]];
324 [__DynamicallyInvokable]
325 public override bool Equals(
object value)
328 if (uTF7Encoding !=
null)
330 if (m_allowOptionals == uTF7Encoding.m_allowOptionals && base.EncoderFallback.Equals(uTF7Encoding.
EncoderFallback))
342 [__DynamicallyInvokable]
345 return CodePage + base.EncoderFallback.GetHashCode() + base.DecoderFallback.GetHashCode();
360 [SecuritySafeCritical]
361 [__DynamicallyInvokable]
362 public unsafe
override int GetByteCount(
char[] chars,
int index,
int count)
368 if (index < 0 || count < 0)
372 if (chars.Length - index < count)
376 if (chars.Length == 0)
380 fixed (
char* ptr = chars)
394 [SecuritySafeCritical]
396 [__DynamicallyInvokable]
403 fixed (
char* chars = s)
420 [CLSCompliant(
false)]
453 [SecuritySafeCritical]
455 [__DynamicallyInvokable]
456 public unsafe
override int GetBytes(
string s,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex)
458 if (s ==
null || bytes ==
null)
462 if (charIndex < 0 || charCount < 0)
466 if (s.Length - charIndex < charCount)
470 if (byteIndex < 0 || byteIndex > bytes.Length)
474 int byteCount = bytes.Length - byteIndex;
475 if (bytes.Length == 0)
479 fixed (
char* ptr = s)
481 byte[] array = bytes;
482 fixed (
byte* ptr2 = array)
484 return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount,
null);
507 [SecuritySafeCritical]
508 [__DynamicallyInvokable]
509 public unsafe
override int GetBytes(
char[] chars,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex)
511 if (chars ==
null || bytes ==
null)
515 if (charIndex < 0 || charCount < 0)
519 if (chars.Length - charIndex < charCount)
523 if (byteIndex < 0 || byteIndex > bytes.Length)
527 if (chars.Length == 0)
531 int byteCount = bytes.Length - byteIndex;
532 if (bytes.Length == 0)
536 fixed (
char* ptr = chars)
538 byte[] array = bytes;
539 fixed (
byte* ptr2 = array)
541 return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount,
null);
562 [CLSCompliant(
false)]
564 public unsafe
override int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount)
566 if (bytes ==
null || chars ==
null)
570 if (charCount < 0 || byteCount < 0)
574 return GetBytes(chars, charCount, bytes, byteCount,
null);
589 [SecuritySafeCritical]
590 [__DynamicallyInvokable]
591 public unsafe
override int GetCharCount(
byte[] bytes,
int index,
int count)
597 if (index < 0 || count < 0)
601 if (bytes.Length - index < count)
605 if (bytes.Length == 0)
609 fixed (
byte* ptr = bytes)
626 [CLSCompliant(
false)]
659 [SecuritySafeCritical]
660 [__DynamicallyInvokable]
661 public unsafe
override int GetChars(
byte[] bytes,
int byteIndex,
int byteCount,
char[] chars,
int charIndex)
663 if (bytes ==
null || chars ==
null)
667 if (byteIndex < 0 || byteCount < 0)
671 if (bytes.Length - byteIndex < byteCount)
675 if (charIndex < 0 || charIndex > chars.Length)
679 if (bytes.Length == 0)
683 int charCount = chars.Length - charIndex;
684 if (chars.Length == 0)
688 fixed (
byte* ptr = bytes)
690 char[] array = chars;
691 fixed (
char* ptr2 = array)
693 return GetChars(ptr + byteIndex, byteCount, ptr2 + charIndex, charCount,
null);
714 [CLSCompliant(
false)]
716 public unsafe
override int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount)
718 if (bytes ==
null || chars ==
null)
722 if (charCount < 0 || byteCount < 0)
726 return GetChars(bytes, byteCount, chars, charCount,
null);
741 [SecuritySafeCritical]
743 [__DynamicallyInvokable]
744 public unsafe
override string GetString(
byte[] bytes,
int index,
int count)
750 if (index < 0 || count < 0)
754 if (bytes.Length - index < count)
758 if (bytes.Length == 0)
762 fixed (
byte* ptr = bytes)
764 return string.CreateStringFromEncoding(ptr + index, count,
this);
769 internal unsafe
override int GetByteCount(
char* chars,
int count, EncoderNLS baseEncoder)
771 return GetBytes(chars, count,
null, 0, baseEncoder);
775 internal unsafe
override int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount, EncoderNLS baseEncoder)
777 Encoder encoder = (Encoder)baseEncoder;
780 EncodingByteBuffer encodingByteBuffer =
new EncodingByteBuffer(
this, encoder, bytes, byteCount, chars, charCount);
784 num2 = encoder.bitCount;
788 if (!encodingByteBuffer.AddByte(base64Bytes[(num >> num2) & 0x3F]))
790 ThrowBytesOverflow(encoder, encodingByteBuffer.Count == 0);
794 while (encodingByteBuffer.MoreData)
796 char nextChar = encodingByteBuffer.GetNextChar();
797 if (nextChar <
'\u0080' && directEncode[nextChar])
803 if (!encodingByteBuffer.AddByte(base64Bytes[(num << 6 - num2) & 0x3F]))
809 if (!encodingByteBuffer.AddByte(45))
815 if (!encodingByteBuffer.AddByte((
byte)nextChar))
821 if (num2 < 0 && nextChar ==
'+')
823 if (!encodingByteBuffer.AddByte((
byte)43, (
byte)45))
831 if (!encodingByteBuffer.AddByte(43))
837 num = ((num << 16) | nextChar);
842 if (!encodingByteBuffer.AddByte(base64Bytes[(num >> num2) & 0x3F]))
845 nextChar = encodingByteBuffer.GetNextChar();
854 if (num2 >= 0 && (encoder ==
null || encoder.MustFlush))
856 if (num2 > 0 && encodingByteBuffer.AddByte(base64Bytes[(num << 6 - num2) & 0x3F]))
860 if (encodingByteBuffer.AddByte(45))
867 encodingByteBuffer.GetNextChar();
870 if (bytes !=
null && encoder !=
null)
873 encoder.bitCount = num2;
874 encoder.m_charsUsed = encodingByteBuffer.CharsUsed;
876 return encodingByteBuffer.Count;
880 internal unsafe
override int GetCharCount(
byte* bytes,
int count, DecoderNLS baseDecoder)
882 return GetChars(bytes, count,
null, 0, baseDecoder);
886 internal unsafe
override int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount, DecoderNLS baseDecoder)
888 Decoder decoder = (Decoder)baseDecoder;
889 EncodingCharBuffer encodingCharBuffer =
new EncodingCharBuffer(
this, decoder, chars, charCount, bytes, byteCount);
896 num2 = decoder.bitCount;
897 flag = decoder.firstByte;
901 if (!encodingCharBuffer.AddChar((
char)((num >> num2 - 16) & 0xFFFF)))
903 ThrowCharsOverflow(decoder, nothingDecoded:
true);
907 while (encodingCharBuffer.MoreData)
909 byte nextByte = encodingCharBuffer.GetNextByte();
914 if (nextByte < 128 && (b = base64Values[nextByte]) >= 0)
917 num = ((num << 6) | (
byte)b);
923 num3 = ((num >> num2 - 16) & 0xFFFF);
931 if (!encodingCharBuffer.Fallback(nextByte))
954 if (!encodingCharBuffer.Fallback(nextByte))
962 if (num3 >= 0 && !encodingCharBuffer.AddChar((
char)num3))
966 encodingCharBuffer.AdjustBytes(1);
972 if (chars !=
null && decoder !=
null)
974 if (decoder.MustFlush)
977 decoder.bitCount = -1;
978 decoder.firstByte =
false;
983 decoder.bitCount = num2;
984 decoder.firstByte = flag;
986 decoder.m_bytesUsed = encodingCharBuffer.BytesUsed;
988 return encodingCharBuffer.Count;
993 [__DynamicallyInvokable]
996 return new Decoder(
this);
1001 [__DynamicallyInvokable]
1004 return new Encoder(
this);
1014 [__DynamicallyInvokable]
1021 long num = (long)charCount * 3
L + 2;
1022 if (num >
int.MaxValue)
1036 [__DynamicallyInvokable]
1043 int num = byteCount;
Represents a character encoding.To browse the .NET Framework source code for this type,...
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 ...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
unsafe override string GetString(byte[] bytes, int index, int count)
Decodes a range of bytes from a byte array into a string.
Converts a set of characters into a sequence of bytes.
override bool Equals(object value)
Gets a value indicating whether the specified object is equal to the current T:System....
The exception that is thrown when the value of an argument is outside the allowable range of values a...
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...
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 ...
DecoderFallback DecoderFallback
Gets or sets the T:System.Text.DecoderFallback object for the current T:System.Text....
override int GetMaxCharCount(int byteCount)
Calculates the maximum number of characters produced by decoding the specified number of bytes.
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-...
Provides information about, and means to manipulate, the current environment and platform....
unsafe override int GetCharCount(byte *bytes, int count)
Calculates the number of characters produced by decoding a sequence of bytes starting at the specifie...
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.
Provides a buffer that allows a fallback handler to return an alternate string to a decoder when it c...
virtual int CodePage
When overridden in a derived class, gets the code page identifier of the current T:System....
override int GetMaxByteCount(int charCount)
Calculates the maximum number of bytes produced by encoding the specified number of characters.
Converts a sequence of encoded bytes into a set of characters.
Represents a UTF-7 encoding of Unicode characters.
Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that can...
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 ...
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
UTF7Encoding()
Initializes a new instance of the T:System.Text.UTF7Encoding class.
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.
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.
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.
unsafe override int GetByteCount(string s)
Calculates the number of bytes produced by encoding the characters in the specified T:System....
override int GetHashCode()
Returns the hash code for the current T:System.Text.UTF7Encoding object.
Specifies that the class can be serialized.
UTF7Encoding(bool allowOptionals)
Initializes a new instance of the T:System.Text.UTF7Encoding class. A parameter specifies whether to ...
Encoding()
Initializes a new instance of the T:System.Text.Encoding class.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
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 System.Text.Encoder GetEncoder()
Obtains an encoder that converts a sequence of Unicode characters into a UTF-7 encoded sequence of by...
override System.Text.Decoder GetDecoder()
Obtains a decoder that converts a UTF-7 encoded sequence of bytes into a sequence of Unicode characte...