diff options
author | James Ko <jamesqko@gmail.com> | 2016-07-04 12:45:52 -0400 |
---|---|---|
committer | James Ko <jamesqko@gmail.com> | 2016-07-04 15:23:51 -0400 |
commit | 7c771b8b8462d0b95130cabfe0de5efbf64278bc (patch) | |
tree | f8f9336d40a1716443e0fb93d44d132774c7e99c /src/mscorlib | |
parent | 088943185a0469d936a8c0b6e235bdc715e6fc25 (diff) | |
download | coreclr-7c771b8b8462d0b95130cabfe0de5efbf64278bc.tar.gz coreclr-7c771b8b8462d0b95130cabfe0de5efbf64278bc.tar.bz2 coreclr-7c771b8b8462d0b95130cabfe0de5efbf64278bc.zip |
Use EncodingForwarder for GetBytes(char*, int, byte*, int)
Diffstat (limited to 'src/mscorlib')
-rw-r--r-- | src/mscorlib/src/System/Text/ASCIIEncoding.cs | 12 | ||||
-rw-r--r-- | src/mscorlib/src/System/Text/EncodingForwarder.cs | 16 | ||||
-rw-r--r-- | src/mscorlib/src/System/Text/EncodingNLS.cs | 12 | ||||
-rw-r--r-- | src/mscorlib/src/System/Text/UTF32Encoding.cs | 12 | ||||
-rw-r--r-- | src/mscorlib/src/System/Text/UTF7Encoding.cs | 12 | ||||
-rw-r--r-- | src/mscorlib/src/System/Text/UTF8Encoding.cs | 12 | ||||
-rw-r--r-- | src/mscorlib/src/System/Text/UnicodeEncoding.cs | 12 |
7 files changed, 22 insertions, 66 deletions
diff --git a/src/mscorlib/src/System/Text/ASCIIEncoding.cs b/src/mscorlib/src/System/Text/ASCIIEncoding.cs index 6fd5a2d730..921a30a503 100644 --- a/src/mscorlib/src/System/Text/ASCIIEncoding.cs +++ b/src/mscorlib/src/System/Text/ASCIIEncoding.cs @@ -129,17 +129,7 @@ namespace System.Text [System.Runtime.InteropServices.ComVisible(false)] public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetBytes(chars, charCount, bytes, byteCount, null); + return EncodingForwarder.GetBytes(this, chars, charCount, bytes, byteCount); } // Returns the number of characters produced by decoding a range of bytes diff --git a/src/mscorlib/src/System/Text/EncodingForwarder.cs b/src/mscorlib/src/System/Text/EncodingForwarder.cs index 691113ee02..7d531df441 100644 --- a/src/mscorlib/src/System/Text/EncodingForwarder.cs +++ b/src/mscorlib/src/System/Text/EncodingForwarder.cs @@ -163,5 +163,21 @@ namespace System.Text return encoding.GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, encoder: null); } } + + public unsafe static int GetBytes(Encoding encoding, char* chars, int charCount, byte* bytes, int byteCount) + { + Contract.Assert(encoding != null); + if (bytes == null || chars == null) + { + throw new ArgumentNullException(bytes == null ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array")); + } + if (charCount < 0 || byteCount < 0) + { + throw new ArgumentOutOfRangeException(charCount < 0 ? "charCount" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + } + Contract.EndContractBlock(); + + return encoding.GetBytes(chars, charCount, bytes, byteCount, encoder: null); + } } } diff --git a/src/mscorlib/src/System/Text/EncodingNLS.cs b/src/mscorlib/src/System/Text/EncodingNLS.cs index 60da8b4975..81b488ad8f 100644 --- a/src/mscorlib/src/System/Text/EncodingNLS.cs +++ b/src/mscorlib/src/System/Text/EncodingNLS.cs @@ -103,17 +103,7 @@ namespace System.Text [System.Security.SecurityCritical] // auto-generated public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetBytes(chars, charCount, bytes, byteCount, null); + return EncodingForwarder.GetBytes(this, chars, charCount, bytes, byteCount); } // Returns the number of characters produced by decoding a range of bytes diff --git a/src/mscorlib/src/System/Text/UTF32Encoding.cs b/src/mscorlib/src/System/Text/UTF32Encoding.cs index bfaf744ccb..173f34272f 100644 --- a/src/mscorlib/src/System/Text/UTF32Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF32Encoding.cs @@ -163,17 +163,7 @@ namespace System.Text [CLSCompliant(false)] public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetBytes(chars, charCount, bytes, byteCount, null); + return EncodingForwarder.GetBytes(this, chars, charCount, bytes, byteCount); } // Returns the number of characters produced by decoding a range of bytes diff --git a/src/mscorlib/src/System/Text/UTF7Encoding.cs b/src/mscorlib/src/System/Text/UTF7Encoding.cs index 34d69cbebf..5762472c02 100644 --- a/src/mscorlib/src/System/Text/UTF7Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF7Encoding.cs @@ -233,17 +233,7 @@ namespace System.Text [System.Runtime.InteropServices.ComVisible(false)] public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetBytes(chars, charCount, bytes, byteCount, null); + return EncodingForwarder.GetBytes(this, chars, charCount, bytes, byteCount); } // Returns the number of characters produced by decoding a range of bytes diff --git a/src/mscorlib/src/System/Text/UTF8Encoding.cs b/src/mscorlib/src/System/Text/UTF8Encoding.cs index f4e7525aef..42d84c7202 100644 --- a/src/mscorlib/src/System/Text/UTF8Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF8Encoding.cs @@ -191,17 +191,7 @@ namespace System.Text [System.Runtime.InteropServices.ComVisible(false)] public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetBytes(chars, charCount, bytes, byteCount, null); + return EncodingForwarder.GetBytes(this, chars, charCount, bytes, byteCount); } // Returns the number of characters produced by decoding a range of bytes diff --git a/src/mscorlib/src/System/Text/UnicodeEncoding.cs b/src/mscorlib/src/System/Text/UnicodeEncoding.cs index 4d7ef877de..94e485ea45 100644 --- a/src/mscorlib/src/System/Text/UnicodeEncoding.cs +++ b/src/mscorlib/src/System/Text/UnicodeEncoding.cs @@ -163,17 +163,7 @@ namespace System.Text [System.Runtime.InteropServices.ComVisible(false)] public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetBytes(chars, charCount, bytes, byteCount, null); + return EncodingForwarder.GetBytes(this, chars, charCount, bytes, byteCount); } // Returns the number of characters produced by decoding a range of bytes |