diff options
Diffstat (limited to 'src/mscorlib/src/System/Text/Encoding.cs')
-rw-r--r-- | src/mscorlib/src/System/Text/Encoding.cs | 222 |
1 files changed, 112 insertions, 110 deletions
diff --git a/src/mscorlib/src/System/Text/Encoding.cs b/src/mscorlib/src/System/Text/Encoding.cs index 8533016293..658bdbb133 100644 --- a/src/mscorlib/src/System/Text/Encoding.cs +++ b/src/mscorlib/src/System/Text/Encoding.cs @@ -15,6 +15,7 @@ namespace System.Text using System.Security.Permissions; using System.Threading; using System.Text; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using Win32Native = Microsoft.Win32.Win32Native; @@ -189,7 +190,7 @@ namespace System.Text // Validate code page if (codePage < 0) { - throw new ArgumentOutOfRangeException("codePage"); + throw new ArgumentOutOfRangeException(nameof(codePage)); } Contract.EndContractBlock(); @@ -208,7 +209,7 @@ namespace System.Text // Validate code page if (codePage < 0) { - throw new ArgumentOutOfRangeException("codePage"); + throw new ArgumentOutOfRangeException(nameof(codePage)); } Contract.EndContractBlock(); @@ -275,7 +276,7 @@ namespace System.Text internal void DeserializeEncoding(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All versions have a code page @@ -314,7 +315,7 @@ namespace System.Text internal void SerializeEncoding(SerializationInfo info, StreamingContext context) { // Any Info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // These are new V2.0 Whidbey stuff @@ -344,7 +345,7 @@ namespace System.Text public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes) { if (bytes==null) - throw new ArgumentNullException("bytes"); + throw new ArgumentNullException(nameof(bytes)); Contract.Ensures(Contract.Result<byte[]>() != null); return Convert(srcEncoding, dstEncoding, bytes, 0, bytes.Length); @@ -359,11 +360,11 @@ namespace System.Text public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes, int index, int count) { if (srcEncoding == null || dstEncoding == null) { - throw new ArgumentNullException((srcEncoding == null ? "srcEncoding" : "dstEncoding"), + throw new ArgumentNullException((srcEncoding == null ? nameof(srcEncoding) : nameof(dstEncoding)), Environment.GetResourceString("ArgumentNull_Array")); } if (bytes == null) { - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } Contract.Ensures(Contract.Result<byte[]>() != null); @@ -389,9 +390,6 @@ namespace System.Text private static volatile Hashtable encodings; #endif -#if !FEATURE_CORECLR - [System.Security.SecurityCritical] -#endif public static void RegisterProvider(EncodingProvider provider) { // Parameters validated inside EncodingProvider @@ -399,9 +397,6 @@ namespace System.Text } [Pure] -#if !FEATURE_CORECLR - [System.Security.SecuritySafeCritical] // auto-generated -#endif public static Encoding GetEncoding(int codepage) { Encoding result = EncodingProvider.GetEncodingFromProvider(codepage); @@ -416,7 +411,7 @@ namespace System.Text // if (codepage < 0 || codepage > 65535) { throw new ArgumentOutOfRangeException( - "codepage", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(codepage), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, 65535)); } @@ -443,7 +438,7 @@ namespace System.Text case CodePageNoThread: // 3 CP_THREAD_ACP case CodePageNoSymbol: // 42 CP_SYMBOL throw new ArgumentException(Environment.GetResourceString( - "Argument_CodepageNotSupported", codepage), "codepage"); + "Argument_CodepageNotSupported", codepage), nameof(codepage)); } #if FEATURE_CODEPAGES_FILE @@ -478,7 +473,7 @@ namespace System.Text result = GetEncodingCodePage(codepage) ?? GetEncodingRare(codepage); } - Contract.Assert(result != null, "result != null"); + Debug.Assert(result != null, "result != null"); encodings.Add(key, result); } @@ -516,10 +511,9 @@ namespace System.Text return fallbackEncoding; } #if FEATURE_CODEPAGES_FILE - [System.Security.SecurityCritical] // auto-generated private static Encoding GetEncodingRare(int codepage) { - Contract.Assert(codepage != 0 && codepage != 1200 && codepage != 1201 && codepage != 65001, + Debug.Assert(codepage != 0 && codepage != 1200 && codepage != 1201 && codepage != 65001, "[Encoding.GetEncodingRare]This code page (" + codepage + ") isn't supported by GetEncodingRare!"); Encoding result; switch (codepage) @@ -585,7 +579,6 @@ namespace System.Text return result; } - [System.Security.SecurityCritical] // auto-generated private static Encoding GetEncodingCodePage(int CodePage) { // Single Byte or Double Byte Code Page? (0 if not found) @@ -795,7 +788,7 @@ namespace System.Text throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); encoderFallback = value; @@ -817,7 +810,7 @@ namespace System.Text throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); decoderFallback = value; @@ -865,7 +858,7 @@ namespace System.Text { if (chars == null) { - throw new ArgumentNullException("chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } Contract.EndContractBlock(); @@ -876,8 +869,8 @@ namespace System.Text [Pure] public virtual int GetByteCount(String s) { - if (s==null) - throw new ArgumentNullException("s"); + if (s == null) + throw new ArgumentNullException(nameof(s)); Contract.EndContractBlock(); char[] chars = s.ToCharArray(); @@ -891,23 +884,50 @@ namespace System.Text [Pure] public abstract int GetByteCount(char[] chars, int index, int count); + // Returns the number of bytes required to encode a string range. + // + [Pure] + public int GetByteCount(string s, int index, int count) + { + if (s == null) + throw new ArgumentNullException(nameof(s), + Environment.GetResourceString("ArgumentNull_String")); + if (index < 0) + throw new ArgumentOutOfRangeException(nameof(index), + Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + if (count < 0) + throw new ArgumentOutOfRangeException(nameof(count), + Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + if (index > s.Length - count) + throw new ArgumentOutOfRangeException(nameof(index), + Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); + Contract.EndContractBlock(); + + unsafe + { + fixed (char* pChar = s) + { + return GetByteCount(pChar + index, count); + } + } + } + // We expect this to be the workhorse for NLS encodings // unfortunately for existing overrides, it has to call the [] version, // which is really slow, so this method should be avoided if you're calling // a 3rd party encoding. [Pure] - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public virtual unsafe int GetByteCount(char* chars, int count) { // Validate input parameters if (chars == null) - throw new ArgumentNullException("chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -922,7 +942,6 @@ namespace System.Text // For NLS Encodings, workhorse takes an encoder (may be null) // Always validate parameters before calling internal version, which will only assert. - [System.Security.SecurityCritical] // auto-generated internal virtual unsafe int GetByteCount(char* chars, int count, EncoderNLS encoder) { Contract.Requires(chars != null); @@ -939,7 +958,7 @@ namespace System.Text { if (chars == null) { - throw new ArgumentNullException("chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } Contract.EndContractBlock(); @@ -976,29 +995,67 @@ namespace System.Text public virtual byte[] GetBytes(String s) { if (s == null) - throw new ArgumentNullException("s", + throw new ArgumentNullException(nameof(s), Environment.GetResourceString("ArgumentNull_String")); Contract.EndContractBlock(); int byteCount = GetByteCount(s); byte[] bytes = new byte[byteCount]; int bytesReceived = GetBytes(s, 0, s.Length, bytes, 0); - Contract.Assert(byteCount == bytesReceived); + Debug.Assert(byteCount == bytesReceived); return bytes; } + // Returns a byte array containing the encoded representation of the given + // string range. + // + [Pure] + public byte[] GetBytes(string s, int index, int count) + { + if (s == null) + throw new ArgumentNullException(nameof(s), + Environment.GetResourceString("ArgumentNull_String")); + if (index < 0) + throw new ArgumentOutOfRangeException(nameof(index), + Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + if (count < 0) + throw new ArgumentOutOfRangeException(nameof(count), + Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + if (index > s.Length - count) + throw new ArgumentOutOfRangeException(nameof(index), + Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); + Contract.EndContractBlock(); + + unsafe + { + fixed (char* pChar = s) + { + int byteCount = GetByteCount(pChar + index, count); + if (byteCount == 0) + return Array.Empty<byte>(); + + byte[] bytes = new byte[byteCount]; + fixed (byte* pBytes = &bytes[0]) + { + int bytesReceived = GetBytes(pChar + index, count, pBytes, byteCount); + Debug.Assert(byteCount == bytesReceived); + } + return bytes; + } + } + } + public virtual int GetBytes(String s, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if (s==null) - throw new ArgumentNullException("s"); + if (s == null) + throw new ArgumentNullException(nameof(s)); Contract.EndContractBlock(); return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex); } // This is our internal workhorse // Always validate parameters before calling internal version, which will only assert. - [System.Security.SecurityCritical] // auto-generated internal virtual unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, EncoderNLS encoder) { @@ -1022,7 +1079,6 @@ namespace System.Text // could easily overflow our output buffer. Therefore we do an extra test // when we copy the buffer so that we don't overflow byteCount either. - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public virtual unsafe int GetBytes(char* chars, int charCount, @@ -1030,11 +1086,11 @@ namespace System.Text { // Validate input parameters if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), + throw new ArgumentOutOfRangeException((charCount<0 ? nameof(charCount) : nameof(byteCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1051,7 +1107,7 @@ namespace System.Text // Do the work int result = GetBytes(arrChar, 0, charCount, arrByte, 0); - Contract.Assert(result <= byteCount, "[Encoding.GetBytes]Returned more bytes than we have space for"); + Debug.Assert(result <= byteCount, "[Encoding.GetBytes]Returned more bytes than we have space for"); // Copy the byte array // WARNING: We MUST make sure that we don't copy too many bytes. We can't @@ -1076,7 +1132,7 @@ namespace System.Text { if (bytes == null) { - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } Contract.EndContractBlock(); @@ -1092,18 +1148,17 @@ namespace System.Text // We expect this to be the workhorse for NLS Encodings, but for existing // ones we need a working (if slow) default implimentation) [Pure] - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public virtual unsafe int GetCharCount(byte* bytes, int count) { // Validate input parameters if (bytes == null) - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1118,7 +1173,6 @@ namespace System.Text // This is our internal workhorse // Always validate parameters before calling internal version, which will only assert. - [System.Security.SecurityCritical] // auto-generated internal virtual unsafe int GetCharCount(byte* bytes, int count, DecoderNLS decoder) { return GetCharCount(bytes, count); @@ -1132,7 +1186,7 @@ namespace System.Text { if (bytes == null) { - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } Contract.EndContractBlock(); @@ -1181,7 +1235,6 @@ namespace System.Text // could easily overflow our output buffer. Therefore we do an extra test // when we copy the buffer so that we don't overflow charCount either. - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public virtual unsafe int GetChars(byte* bytes, int byteCount, @@ -1189,11 +1242,11 @@ namespace System.Text { // Validate input parameters if (chars == null || bytes == null) - throw new ArgumentNullException(chars == null ? "chars" : "bytes", + throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0 || charCount < 0) - throw new ArgumentOutOfRangeException((byteCount<0 ? "byteCount" : "charCount"), + throw new ArgumentOutOfRangeException((byteCount<0 ? nameof(byteCount) : nameof(charCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1210,7 +1263,7 @@ namespace System.Text // Do the work int result = GetChars(arrByte, 0, byteCount, arrChar, 0); - Contract.Assert(result <= charCount, "[Encoding.GetChars]Returned more chars than we have space for"); + Debug.Assert(result <= charCount, "[Encoding.GetChars]Returned more chars than we have space for"); // Copy the char array // WARNING: We MUST make sure that we don't copy too many chars. We can't @@ -1230,7 +1283,6 @@ namespace System.Text // This is our internal workhorse // Always validate parameters before calling internal version, which will only assert. - [System.Security.SecurityCritical] // auto-generated internal virtual unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount, DecoderNLS decoder) { @@ -1238,16 +1290,15 @@ namespace System.Text } - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public unsafe string GetString(byte* bytes, int byteCount) { if (bytes == null) - throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); return String.CreateStringFromEncoding(bytes, byteCount, this); @@ -1306,7 +1357,6 @@ namespace System.Text return new DefaultDecoder(this); } - [System.Security.SecuritySafeCritical] private static Encoding CreateDefaultEncoding() { // defaultEncoding should be null if we get here, but we can't @@ -1391,7 +1441,7 @@ namespace System.Text public virtual String GetString(byte[] bytes) { if (bytes == null) - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); Contract.EndContractBlock(); @@ -1482,7 +1532,6 @@ namespace System.Text EncodingName, EncoderFallback.GetType()), "bytes"); } - [System.Security.SecurityCritical] // auto-generated internal void ThrowBytesOverflow(EncoderNLS encoder, bool nothingEncoded) { if (encoder == null || encoder.m_throwOnOverflow || nothingEncoded) @@ -1507,7 +1556,6 @@ namespace System.Text EncodingName, DecoderFallback.GetType()), "chars"); } - [System.Security.SecurityCritical] // auto-generated internal void ThrowCharsOverflow(DecoderNLS decoder, bool nothingDecoded) { if (decoder == null || decoder.m_throwOnOverflow || nothingDecoded) @@ -1541,7 +1589,7 @@ namespace System.Text // Constructor called by serialization, have to handle deserializing from Everett internal DefaultEncoder(SerializationInfo info, StreamingContext context) { - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All we have is our encoding @@ -1558,7 +1606,6 @@ namespace System.Text } // Just get it from GetEncoding - [System.Security.SecurityCritical] // auto-generated public Object GetRealObject(StreamingContext context) { // upon deserialization since the DefaultEncoder implement IObjectReference the @@ -1584,11 +1631,10 @@ namespace System.Text } // ISerializable implementation, get data for this object - [System.Security.SecurityCritical] // auto-generated_required void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All we have is our encoding @@ -1608,7 +1654,6 @@ namespace System.Text return m_encoding.GetByteCount(chars, index, count); } - [System.Security.SecurityCritical] // auto-generated [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. public unsafe override int GetByteCount(char* chars, int count, bool flush) { @@ -1641,7 +1686,6 @@ namespace System.Text return m_encoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex); } - [System.Security.SecurityCritical] // auto-generated [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, bool flush) @@ -1667,7 +1711,7 @@ namespace System.Text internal DefaultDecoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All we have is our encoding @@ -1684,7 +1728,6 @@ namespace System.Text } // Just get it from GetEncoding - [System.Security.SecurityCritical] // auto-generated public Object GetRealObject(StreamingContext context) { // upon deserialization since the DefaultEncoder implement IObjectReference the @@ -1705,11 +1748,10 @@ namespace System.Text } // ISerializable implementation, get data for this object - [System.Security.SecurityCritical] // auto-generated_required void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All we have is our encoding @@ -1733,7 +1775,6 @@ namespace System.Text return m_encoding.GetCharCount(bytes, index, count); } - [System.Security.SecurityCritical] // auto-generated [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. public unsafe override int GetCharCount(byte* bytes, int count, bool flush) { @@ -1770,7 +1811,6 @@ namespace System.Text return m_encoding.GetChars(bytes, byteIndex, byteCount, chars, charIndex); } - [System.Security.SecurityCritical] // auto-generated [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount, bool flush) @@ -1782,24 +1822,17 @@ namespace System.Text internal class EncodingCharBuffer { - [SecurityCritical] unsafe char* chars; - [SecurityCritical] unsafe char* charStart; - [SecurityCritical] unsafe char* charEnd; int charCountResult = 0; Encoding enc; DecoderNLS decoder; - [SecurityCritical] unsafe byte* byteStart; - [SecurityCritical] unsafe byte* byteEnd; - [SecurityCritical] unsafe byte* bytes; DecoderFallbackBuffer fallbackBuffer; - [System.Security.SecurityCritical] // auto-generated internal unsafe EncodingCharBuffer(Encoding enc, DecoderNLS decoder, char* charStart, int charCount, byte* byteStart, int byteCount) { @@ -1821,12 +1854,11 @@ namespace System.Text // If we're getting chars or getting char count we don't expect to have // to remember fallbacks between calls (so it should be empty) - Contract.Assert(fallbackBuffer.Remaining == 0, + Debug.Assert(fallbackBuffer.Remaining == 0, "[Encoding.EncodingCharBuffer.EncodingCharBuffer]Expected empty fallback buffer for getchars/charcount"); fallbackBuffer.InternalInitialize(bytes, charEnd); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddChar(char ch, int numBytes) { if (chars != null) @@ -1845,14 +1877,12 @@ namespace System.Text return true; } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddChar(char ch) { return AddChar(ch,1); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddChar(char ch1, char ch2, int numBytes) { // Need room for 2 chars @@ -1866,7 +1896,6 @@ namespace System.Text return AddChar(ch1, numBytes) && AddChar(ch2, numBytes); } - [System.Security.SecurityCritical] // auto-generated internal unsafe void AdjustBytes(int count) { bytes += count; @@ -1874,7 +1903,6 @@ namespace System.Text internal unsafe bool MoreData { - [System.Security.SecurityCritical] // auto-generated get { return bytes < byteEnd; @@ -1882,7 +1910,6 @@ namespace System.Text } // Do we have count more bytes? - [System.Security.SecurityCritical] // auto-generated internal unsafe bool EvenMoreData(int count) { return (bytes <= byteEnd - count); @@ -1890,10 +1917,9 @@ namespace System.Text // GetNextByte shouldn't be called unless the caller's already checked more data or even more data, // but we'll double check just to make sure. - [System.Security.SecurityCritical] // auto-generated internal unsafe byte GetNextByte() { - Contract.Assert(bytes < byteEnd, "[EncodingCharBuffer.GetNextByte]Expected more date"); + Debug.Assert(bytes < byteEnd, "[EncodingCharBuffer.GetNextByte]Expected more date"); if (bytes >= byteEnd) return 0; return *(bytes++); @@ -1901,14 +1927,12 @@ namespace System.Text internal unsafe int BytesUsed { - [System.Security.SecurityCritical] // auto-generated get { return (int)(bytes - byteStart); } } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool Fallback(byte fallbackByte) { // Build our buffer @@ -1918,7 +1942,6 @@ namespace System.Text return Fallback(byteBuffer); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool Fallback(byte byte1, byte byte2) { // Build our buffer @@ -1928,7 +1951,6 @@ namespace System.Text return Fallback(byteBuffer); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool Fallback(byte byte1, byte byte2, byte byte3, byte byte4) { // Build our buffer @@ -1938,7 +1960,6 @@ namespace System.Text return Fallback(byteBuffer); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool Fallback(byte[] byteBuffer) { // Do the fallback and add the data. @@ -1974,24 +1995,17 @@ namespace System.Text internal class EncodingByteBuffer { - [SecurityCritical] unsafe byte* bytes; - [SecurityCritical] unsafe byte* byteStart; - [SecurityCritical] unsafe byte* byteEnd; - [SecurityCritical] unsafe char* chars; - [SecurityCritical] unsafe char* charStart; - [SecurityCritical] unsafe char* charEnd; int byteCountResult = 0; Encoding enc; EncoderNLS encoder; internal EncoderFallbackBuffer fallbackBuffer; - [System.Security.SecurityCritical] // auto-generated internal unsafe EncodingByteBuffer(Encoding inEncoding, EncoderNLS inEncoder, byte* inByteStart, int inByteCount, char* inCharStart, int inCharCount) { @@ -2020,10 +2034,9 @@ namespace System.Text fallbackBuffer.InternalInitialize(chars, charEnd, encoder, bytes != null); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddByte(byte b, int moreBytesExpected) { - Contract.Assert(moreBytesExpected >= 0, "[EncodingByteBuffer.AddByte]expected non-negative moreBytesExpected"); + Debug.Assert(moreBytesExpected >= 0, "[EncodingByteBuffer.AddByte]expected non-negative moreBytesExpected"); if (bytes != null) { if (bytes >= byteEnd - moreBytesExpected) @@ -2039,31 +2052,26 @@ namespace System.Text return true; } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddByte(byte b1) { return (AddByte(b1, 0)); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddByte(byte b1, byte b2) { return (AddByte(b1, b2, 0)); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddByte(byte b1, byte b2, int moreBytesExpected) { return (AddByte(b1, 1 + moreBytesExpected) && AddByte(b2, moreBytesExpected)); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddByte(byte b1, byte b2, byte b3) { return AddByte(b1, b2, b3, (int)0); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddByte(byte b1, byte b2, byte b3, int moreBytesExpected) { return (AddByte(b1, 2 + moreBytesExpected) && @@ -2071,7 +2079,6 @@ namespace System.Text AddByte(b3, moreBytesExpected)); } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool AddByte(byte b1, byte b2, byte b3, byte b4) { return (AddByte(b1, 3) && @@ -2080,14 +2087,13 @@ namespace System.Text AddByte(b4, 0)); } - [System.Security.SecurityCritical] // auto-generated internal unsafe void MovePrevious(bool bThrow) { if (fallbackBuffer.bFallingBack) fallbackBuffer.MovePrevious(); // don't use last fallback else { - Contract.Assert(chars > charStart || + Debug.Assert(chars > charStart || ((bThrow == true) && (bytes == byteStart)), "[EncodingByteBuffer.MovePrevious]expected previous data or throw"); if (chars > charStart) @@ -2098,7 +2104,6 @@ namespace System.Text enc.ThrowBytesOverflow(encoder, bytes == byteStart); // Throw? (and reset fallback if not converting) } - [System.Security.SecurityCritical] // auto-generated internal unsafe bool Fallback(char charFallback) { // Do the fallback @@ -2107,7 +2112,6 @@ namespace System.Text internal unsafe bool MoreData { - [System.Security.SecurityCritical] // auto-generated get { // See if fallbackBuffer is not empty or if there's data left in chars buffer. @@ -2115,7 +2119,6 @@ namespace System.Text } } - [System.Security.SecurityCritical] // auto-generated internal unsafe char GetNextChar() { // See if there's something in our fallback buffer @@ -2133,7 +2136,6 @@ namespace System.Text internal unsafe int CharsUsed { - [System.Security.SecurityCritical] // auto-generated get { return (int)(chars - charStart); |