diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
commit | db20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch) | |
tree | e5435159cd1bf0519276363a6fe1663d1721bed3 /src/mscorlib/src/System/Text/UnicodeEncoding.cs | |
parent | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff) | |
download | coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2 coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip |
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/mscorlib/src/System/Text/UnicodeEncoding.cs')
-rw-r--r-- | src/mscorlib/src/System/Text/UnicodeEncoding.cs | 92 |
1 files changed, 42 insertions, 50 deletions
diff --git a/src/mscorlib/src/System/Text/UnicodeEncoding.cs b/src/mscorlib/src/System/Text/UnicodeEncoding.cs index 41d4f3b5ea..25255c3230 100644 --- a/src/mscorlib/src/System/Text/UnicodeEncoding.cs +++ b/src/mscorlib/src/System/Text/UnicodeEncoding.cs @@ -12,6 +12,7 @@ namespace System.Text using System.Globalization; using System.Runtime.Serialization; using System.Security.Permissions; + using System.Diagnostics; using System.Diagnostics.Contracts; @@ -109,7 +110,6 @@ namespace System.Text return EncodingForwarder.GetByteCount(this, s); } - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public override unsafe int GetByteCount(char* chars, int count) @@ -138,7 +138,6 @@ namespace System.Text return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex); } - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) @@ -154,7 +153,6 @@ namespace System.Text return EncodingForwarder.GetCharCount(this, bytes, index, count); } - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public override unsafe int GetCharCount(byte* bytes, int count) @@ -168,7 +166,6 @@ namespace System.Text return EncodingForwarder.GetChars(this, bytes, byteIndex, byteCount, chars, charIndex); } - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) @@ -187,11 +184,10 @@ namespace System.Text // End of overridden methods which use EncodingForwarder - [System.Security.SecurityCritical] // auto-generated internal override unsafe int GetByteCount(char* chars, int count, EncoderNLS encoder) { - Contract.Assert(chars!=null, "[UnicodeEncoding.GetByteCount]chars!=null"); - Contract.Assert(count >= 0, "[UnicodeEncoding.GetByteCount]count >=0"); + Debug.Assert(chars!=null, "[UnicodeEncoding.GetByteCount]chars!=null"); + Debug.Assert(count >= 0, "[UnicodeEncoding.GetByteCount]count >=0"); // Start by assuming each char gets 2 bytes int byteCount = count << 1; @@ -200,7 +196,7 @@ namespace System.Text // (If they were all invalid chars, this would actually be wrong, // but that's a ridiculously large # so we're not concerned about that case) if (byteCount < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); char* charStart = chars; char* charEnd = chars + count; @@ -340,7 +336,7 @@ namespace System.Text // Unwind the current character, this should be safe because we // don't have leftover data in the fallback, so chars must have // advanced already. - Contract.Assert(chars > charStart, + Debug.Assert(chars > charStart, "[UnicodeEncoding.GetByteCount]Expected chars to have advanced in unexpected high surrogate"); chars--; @@ -407,7 +403,7 @@ namespace System.Text // Rewind the current character, fallback previous character. // this should be safe because we don't have leftover data in the // fallback, so chars must have advanced already. - Contract.Assert(chars > charStart, + Debug.Assert(chars > charStart, "[UnicodeEncoding.GetByteCount]Expected chars to have advanced when expected low surrogate"); chars--; @@ -448,7 +444,7 @@ namespace System.Text // Throw it, using our complete character throw new ArgumentException( Environment.GetResourceString("Argument_RecursiveFallback", - charLeftOver), "chars"); + charLeftOver), nameof(chars)); } else { @@ -473,21 +469,20 @@ namespace System.Text // Shouldn't have anything in fallback buffer for GetByteCount // (don't have to check m_throwOnOverflow for count) - Contract.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0, + Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0, "[UnicodeEncoding.GetByteCount]Expected empty fallback buffer at end"); // Don't remember fallbackBuffer.encoder for counting return byteCount; } - [System.Security.SecurityCritical] // auto-generated internal override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, EncoderNLS encoder) { - Contract.Assert(chars!=null, "[UnicodeEncoding.GetBytes]chars!=null"); - Contract.Assert(byteCount >=0, "[UnicodeEncoding.GetBytes]byteCount >=0"); - Contract.Assert(charCount >=0, "[UnicodeEncoding.GetBytes]charCount >=0"); - Contract.Assert(bytes!=null, "[UnicodeEncoding.GetBytes]bytes!=null"); + Debug.Assert(chars!=null, "[UnicodeEncoding.GetBytes]chars!=null"); + Debug.Assert(byteCount >=0, "[UnicodeEncoding.GetBytes]byteCount >=0"); + Debug.Assert(charCount >=0, "[UnicodeEncoding.GetBytes]charCount >=0"); + Debug.Assert(bytes!=null, "[UnicodeEncoding.GetBytes]bytes!=null"); char charLeftOver = (char)0; char ch; @@ -691,7 +686,7 @@ namespace System.Text // Unwind the current character, this should be safe because we // don't have leftover data in the fallback, so chars must have // advanced already. - Contract.Assert(chars > charStart, + Debug.Assert(chars > charStart, "[UnicodeEncoding.GetBytes]Expected chars to have advanced in unexpected high surrogate"); chars--; @@ -757,7 +752,7 @@ namespace System.Text { // If we don't have enough room, then either we should've advanced a while // or we should have bytes==byteStart and throw below - Contract.Assert(chars > charStart + 1 || bytes == byteStart, + Debug.Assert(chars > charStart + 1 || bytes == byteStart, "[UnicodeEncoding.GetBytes]Expected chars to have when no room to add surrogate pair"); chars-=2; // Didn't use either surrogate } @@ -786,7 +781,7 @@ namespace System.Text // Rewind the current character, fallback previous character. // this should be safe because we don't have leftover data in the // fallback, so chars must have advanced already. - Contract.Assert(chars > charStart, + Debug.Assert(chars > charStart, "[UnicodeEncoding.GetBytes]Expected chars to have advanced after expecting low surrogate"); chars--; @@ -820,7 +815,7 @@ namespace System.Text { // Lonely charLeftOver (from previous call) would've been caught up above, // so this must be a case where we've already read an input char. - Contract.Assert(chars > charStart, + Debug.Assert(chars > charStart, "[UnicodeEncoding.GetBytes]Expected chars to have advanced for failed fallback"); chars--; // Not using this char } @@ -851,7 +846,7 @@ namespace System.Text // Throw it, using our complete character throw new ArgumentException( Environment.GetResourceString("Argument_RecursiveFallback", - charLeftOver), "chars"); + charLeftOver), nameof(chars)); } else { @@ -888,10 +883,10 @@ namespace System.Text // Remember charLeftOver if we must, or clear it if we're flushing // (charLeftOver should be 0 if we're flushing) - Contract.Assert((encoder != null && !encoder.MustFlush) || charLeftOver == (char)0, + Debug.Assert((encoder != null && !encoder.MustFlush) || charLeftOver == (char)0, "[UnicodeEncoding.GetBytes] Expected no left over characters if flushing"); - Contract.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0 || + Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0 || encoder == null || !encoder.m_throwOnOverflow, "[UnicodeEncoding.GetBytes]Expected empty fallback buffer if not converting"); @@ -901,11 +896,10 @@ namespace System.Text return (int)(bytes - byteStart); } - [System.Security.SecurityCritical] // auto-generated internal override unsafe int GetCharCount(byte* bytes, int count, DecoderNLS baseDecoder) { - Contract.Assert(bytes!=null, "[UnicodeEncoding.GetCharCount]bytes!=null"); - Contract.Assert(count >= 0, "[UnicodeEncoding.GetCharCount]count >=0"); + Debug.Assert(bytes!=null, "[UnicodeEncoding.GetCharCount]bytes!=null"); + Debug.Assert(count >= 0, "[UnicodeEncoding.GetCharCount]count >=0"); UnicodeEncoding.Decoder decoder = (UnicodeEncoding.Decoder)baseDecoder; @@ -944,7 +938,7 @@ namespace System.Text // Shouldn't have anything in fallback buffer for GetCharCount // (don't have to check m_throwOnOverflow for count) - Contract.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0, + Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0, "[UnicodeEncoding.GetCharCount]Expected empty fallback buffer at start"); } @@ -1234,20 +1228,19 @@ namespace System.Text // Shouldn't have anything in fallback buffer for GetCharCount // (don't have to check m_throwOnOverflow for count) - Contract.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0, + Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0, "[UnicodeEncoding.GetCharCount]Expected empty fallback buffer at end"); return charCount; } - [System.Security.SecurityCritical] // auto-generated internal override unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount, DecoderNLS baseDecoder ) { - Contract.Assert(chars!=null, "[UnicodeEncoding.GetChars]chars!=null"); - Contract.Assert(byteCount >=0, "[UnicodeEncoding.GetChars]byteCount >=0"); - Contract.Assert(charCount >=0, "[UnicodeEncoding.GetChars]charCount >=0"); - Contract.Assert(bytes!=null, "[UnicodeEncoding.GetChars]bytes!=null"); + Debug.Assert(chars!=null, "[UnicodeEncoding.GetChars]chars!=null"); + Debug.Assert(byteCount >=0, "[UnicodeEncoding.GetChars]byteCount >=0"); + Debug.Assert(charCount >=0, "[UnicodeEncoding.GetChars]charCount >=0"); + Debug.Assert(bytes!=null, "[UnicodeEncoding.GetChars]bytes!=null"); UnicodeEncoding.Decoder decoder = (UnicodeEncoding.Decoder)baseDecoder; @@ -1263,7 +1256,7 @@ namespace System.Text // Shouldn't have anything in fallback buffer for GetChars // (don't have to check m_throwOnOverflow for chars) - Contract.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0, + Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0, "[UnicodeEncoding.GetChars]Expected empty fallback buffer at start"); } @@ -1421,7 +1414,7 @@ namespace System.Text { // couldn't fall back lonely surrogate // We either advanced bytes or chars should == charStart and throw below - Contract.Assert(bytes >= byteStart + 2 || chars == charStart, + Debug.Assert(bytes >= byteStart + 2 || chars == charStart, "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (bad surrogate)"); bytes-=2; // didn't use these 2 bytes fallbackBuffer.InternalReset(); @@ -1470,7 +1463,7 @@ namespace System.Text { // couldn't fall back lonely surrogate // We either advanced bytes or chars should == charStart and throw below - Contract.Assert(bytes >= byteStart + 2 || chars == charStart, + Debug.Assert(bytes >= byteStart + 2 || chars == charStart, "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (lonely surrogate)"); bytes-=2; // didn't use these 2 bytes fallbackBuffer.InternalReset(); @@ -1487,7 +1480,7 @@ namespace System.Text { // couldn't find room for this surrogate pair // We either advanced bytes or chars should == charStart and throw below - Contract.Assert(bytes >= byteStart + 2 || chars == charStart, + Debug.Assert(bytes >= byteStart + 2 || chars == charStart, "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (surrogate pair)"); bytes-=2; // didn't use these 2 bytes ThrowCharsOverflow(decoder, chars == charStart);// Might throw, if no chars output @@ -1529,7 +1522,7 @@ namespace System.Text { // couldn't fall back high surrogate, or char that would be next // We either advanced bytes or chars should == charStart and throw below - Contract.Assert(bytes >= byteStart + 2 || chars == charStart, + Debug.Assert(bytes >= byteStart + 2 || chars == charStart, "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (no low surrogate)"); bytes-=2; // didn't use these 2 bytes fallbackBuffer.InternalReset(); @@ -1546,7 +1539,7 @@ namespace System.Text { // 2 bytes couldn't fall back // We either advanced bytes or chars should == charStart and throw below - Contract.Assert(bytes >= byteStart + 2 || chars == charStart, + Debug.Assert(bytes >= byteStart + 2 || chars == charStart, "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (normal)"); bytes-=2; // didn't use these bytes ThrowCharsOverflow(decoder, chars == charStart);// Might throw, if no chars output @@ -1591,7 +1584,7 @@ namespace System.Text { // 2 bytes couldn't fall back // We either advanced bytes or chars should == charStart and throw below - Contract.Assert(bytes >= byteStart + 2 || chars == charStart, + Debug.Assert(bytes >= byteStart + 2 || chars == charStart, "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (decoder)"); bytes-=2; // didn't use these bytes if (lastByte >= 0) @@ -1644,7 +1637,7 @@ namespace System.Text // Remember our decoder if we must if (decoder != null) { - Contract.Assert((decoder.MustFlush == false) || ((lastChar == (char)0) && (lastByte == -1)), + Debug.Assert((decoder.MustFlush == false) || ((lastChar == (char)0) && (lastByte == -1)), "[UnicodeEncoding.GetChars] Expected no left over chars or bytes if flushing" // + " " + ((int)lastChar).ToString("X4") + " " + lastByte.ToString("X2") ); @@ -1659,7 +1652,7 @@ namespace System.Text // Shouldn't have anything in fallback buffer for GetChars // (don't have to check m_throwOnOverflow for count or chars) - Contract.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0, + Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0, "[UnicodeEncoding.GetChars]Expected empty fallback buffer at end"); return (int)(chars - charStart); @@ -1697,7 +1690,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1711,7 +1704,7 @@ namespace System.Text byteCount <<= 1; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -1720,7 +1713,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1735,7 +1728,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } @@ -1781,7 +1774,7 @@ namespace System.Text internal Decoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Get Common Info @@ -1803,11 +1796,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(); // Save Whidbey data |