Imported Upstream version 4.3.2.467

Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
Xamarin Public Jenkins
2016-02-22 11:00:01 -05:00
parent f302175246
commit f3e3aab35a
4097 changed files with 122406 additions and 82300 deletions

View File

@@ -84,18 +84,12 @@ namespace System.Text
// Maximum number of characters that this instance of this fallback could return
public override int MaxCharCount
{
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get
{
return strDefault.Length;
}
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public override bool Equals(Object value)
{
EncoderReplacementFallback that = value as EncoderReplacementFallback;

View File

@@ -219,19 +219,32 @@ namespace System.Text
this.SetDefaultFallbacks();
}
// This constructor is needed to allow any sub-classing implementation to provide encoder/decoder fallback objects
// because the encoding object is always created as read-only object and dont allow setting encoder/decoder fallback
// after the creation is done.
protected Encoding(int codePage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
// Validate code page
if (codePage < 0)
{
throw new ArgumentOutOfRangeException("codePage");
}
Contract.EndContractBlock();
// Remember code page
m_codePage = codePage;
this.encoderFallback = encoderFallback ?? new InternalEncoderBestFitFallback(this);
this.decoderFallback = decoderFallback ?? new InternalDecoderBestFitFallback(this);
}
// Default fallback that we'll use.
internal virtual void SetDefaultFallbacks()
{
#if FEATURE_CORECLR
// For coreclr we only have Unicode, so we don't have best fit fallbacks
this.encoderFallback = new EncoderReplacementFallback("\xFFFD");
this.decoderFallback = new DecoderReplacementFallback("\xFFFD");
#else // !FEATURE_CORECLR
// For UTF-X encodings, we use a replacement fallback with an "\xFFFD" string,
// For ASCII we use "?" replacement fallback, etc.
this.encoderFallback = new InternalEncoderBestFitFallback(this);
this.decoderFallback = new InternalDecoderBestFitFallback(this);
#endif // FEATURE_CORECLR
}
@@ -389,12 +402,25 @@ namespace System.Text
}
}
#if !FEATURE_CORECLR
[System.Security.SecurityCritical]
#endif
public static void RegisterProvider(EncodingProvider provider)
{
// Parameters validated inside EncodingProvider
EncodingProvider.AddProvider(provider);
}
[Pure]
#if !FEATURE_CORECLR
[System.Security.SecuritySafeCritical] // auto-generated
#endif
public static Encoding GetEncoding(int codepage)
{
Encoding result = EncodingProvider.GetEncodingFromProvider(codepage);
if (result != null)
return result;
//
// NOTE: If you add a new encoding that can be get by codepage, be sure to
// add the corresponding item in EncodingTable.
@@ -410,7 +436,6 @@ namespace System.Text
Contract.EndContractBlock();
// Our Encoding
Encoding result = null;
// See if we have a hash table with our encoding in it already.
if (encodings != null) {
@@ -460,7 +485,16 @@ namespace System.Text
break;
#endif
#endif
#if FEATURE_UTF32
case CodePageUTF32: // 12000
result = UTF32;
break;
case CodePageUTF32BE: // 12001
result = new UTF32Encoding(true, true);
break;
#endif
#endif
case CodePageUTF8: // 65001, UTF8
result = UTF8;
break;
@@ -538,8 +572,13 @@ namespace System.Text
public static Encoding GetEncoding(int codepage,
EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
Encoding baseEncoding = EncodingProvider.GetEncodingFromProvider(codepage, encoderFallback, decoderFallback);
if (baseEncoding != null)
return baseEncoding;
// Get the default encoding (which is cached and read only)
Encoding baseEncoding = GetEncoding(codepage);
baseEncoding = GetEncoding(codepage);
// Clone it and set the fallback
Encoding fallbackEncoding = (Encoding)baseEncoding.Clone();
@@ -644,6 +683,10 @@ namespace System.Text
[Pure]
public static Encoding GetEncoding(String name)
{
Encoding baseEncoding = EncodingProvider.GetEncodingFromProvider(name);
if (baseEncoding != null)
return baseEncoding;
//
// NOTE: If you add a new encoding that can be requested by name, be sure to
// add the corresponding item in EncodingTable.
@@ -659,6 +702,10 @@ namespace System.Text
public static Encoding GetEncoding(String name,
EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
Encoding baseEncoding = EncodingProvider.GetEncodingFromProvider(name, encoderFallback, decoderFallback);
if (baseEncoding != null)
return baseEncoding;
//
// NOTE: If you add a new encoding that can be requested by name, be sure to
// add the corresponding item in EncodingTable.
@@ -738,9 +785,6 @@ namespace System.Text
public virtual String WebName
{
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get
{
if (dataItem==null) {
@@ -894,9 +938,6 @@ namespace System.Text
public static Encoding ASCII
{
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get
{
if (asciiEncoding == null) asciiEncoding = new ASCIIEncoding();
@@ -1013,9 +1054,6 @@ namespace System.Text
// of characters in a character array.
//
[Pure]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public virtual byte[] GetBytes(char[] chars, int index, int count)
{
byte[] result = new byte[GetByteCount(chars, index, count)];
@@ -1305,6 +1343,22 @@ namespace System.Text
return GetChars(bytes, byteCount, chars, charCount);
}
[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"));
if (byteCount < 0)
throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
Contract.EndContractBlock();
return String.CreateStringFromEncoding(bytes, byteCount, this);
}
// Returns the code page identifier of this encoding. The returned value is
// an integer between 0 and 65535 if the encoding has a code page
// identifier, or -1 if the encoding does not represent a code page.
@@ -1401,9 +1455,6 @@ namespace System.Text
public static Encoding Default {
[System.Security.SecuritySafeCritical] // auto-generated
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get {
if (defaultEncoding == null) {
defaultEncoding = CreateDefaultEncoding();
@@ -1489,9 +1540,6 @@ namespace System.Text
//
public static Encoding Unicode {
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get {
if (unicodeEncoding == null) unicodeEncoding = new UnicodeEncoding(false, true);
return unicodeEncoding;
@@ -1528,9 +1576,6 @@ namespace System.Text
//
public static Encoding UTF8 {
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get {
if (utf8Encoding == null) utf8Encoding = new UTF8Encoding(true);
return utf8Encoding;

View File

@@ -0,0 +1,138 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Text
{
using System;
using System.Collections;
using System.Collections.Generic;
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class EncodingProvider
{
public EncodingProvider() { }
public abstract Encoding GetEncoding(string name);
public abstract Encoding GetEncoding(int codepage);
// GetEncoding should return either valid encoding or null. shouldn't throw any exception except on null name
public virtual Encoding GetEncoding(string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
Encoding enc = GetEncoding(name);
if (enc != null)
{
enc = (Encoding)GetEncoding(name).Clone();
enc.EncoderFallback = encoderFallback;
enc.DecoderFallback = decoderFallback;
}
return enc;
}
public virtual Encoding GetEncoding(int codepage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
Encoding enc = GetEncoding(codepage);
if (enc != null)
{
enc = (Encoding)GetEncoding(codepage).Clone();
enc.EncoderFallback = encoderFallback;
enc.DecoderFallback = decoderFallback;
}
return enc;
}
internal static void AddProvider(EncodingProvider provider)
{
if (provider == null)
throw new ArgumentNullException("provider");
lock (s_InternalSyncObject)
{
if (s_providers == null)
{
s_providers = new EncodingProvider[1] { provider };
return;
}
if (Array.IndexOf(s_providers, provider) >= 0)
{
return;
}
var providers = new EncodingProvider[s_providers.Length + 1];
Array.Copy(s_providers, providers, s_providers.Length);
providers[providers.Length - 1] = provider;
s_providers = providers;
}
}
internal static Encoding GetEncodingFromProvider(int codepage)
{
if (s_providers == null)
return null;
var providers = s_providers;
foreach (EncodingProvider provider in providers)
{
Encoding enc = provider.GetEncoding(codepage);
if (enc != null)
return enc;
}
return null;
}
internal static Encoding GetEncodingFromProvider(string encodingName)
{
if (s_providers == null)
return null;
var providers = s_providers;
foreach (EncodingProvider provider in providers)
{
Encoding enc = provider.GetEncoding(encodingName);
if (enc != null)
return enc;
}
return null;
}
internal static Encoding GetEncodingFromProvider(int codepage, EncoderFallback enc, DecoderFallback dec)
{
if (s_providers == null)
return null;
var providers = s_providers;
foreach (EncodingProvider provider in providers)
{
Encoding encing = provider.GetEncoding(codepage, enc, dec);
if (encing != null)
return encing;
}
return null;
}
internal static Encoding GetEncodingFromProvider(string encodingName, EncoderFallback enc, DecoderFallback dec)
{
if (s_providers == null)
return null;
var providers = s_providers;
foreach (EncodingProvider provider in providers)
{
Encoding encoding = provider.GetEncoding(encodingName, enc, dec);
if (encoding != null)
return encoding;
}
return null;
}
private static Object s_InternalSyncObject = new Object();
private static volatile EncodingProvider[] s_providers;
}
}

View File

@@ -214,7 +214,7 @@ namespace System.Text
Environment.GetResourceString("Arg_OutOfMemoryException"));
default:
throw new InvalidOperationException(
Environment.GetRuntimeResourceString("UnknownError_Num", iError));
Environment.GetResourceString("UnknownError_Num", iError));
}
return result;
@@ -249,7 +249,7 @@ namespace System.Text
// Who knows what happened? Not us!
throw new InvalidOperationException(
Environment.GetRuntimeResourceString("UnknownError_Num", iError));
Environment.GetResourceString("UnknownError_Num", iError));
}
// Don't break for empty strings (only possible for D & KD and not really possible at that)
@@ -295,7 +295,7 @@ namespace System.Text
default:
// We shouldn't get here...
throw new InvalidOperationException(
Environment.GetRuntimeResourceString("UnknownError_Num", iError));
Environment.GetResourceString("UnknownError_Num", iError));
}
}

View File

@@ -85,18 +85,12 @@ namespace System.Text {
// Creates a new empty string builder (i.e., it represents String.Empty)
// with the default capacity (16 characters).
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public StringBuilder()
: this(DefaultCapacity) {
}
// Create a new empty string builder (i.e., it represents String.Empty)
// with the specified capacity.
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public StringBuilder(int capacity)
: this(String.Empty, capacity) {
}
@@ -116,9 +110,6 @@ namespace System.Text {
// (i.e., it will also represent String.NullString).
// The maximum number of characters this string may contain is set by capacity.
//
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public StringBuilder(String value, int capacity)
: this(value, 0, ((value != null) ? value.Length : 0), capacity) {
}
@@ -295,9 +286,6 @@ namespace System.Text {
}
public int Capacity {
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get { return m_ChunkChars.Length + m_ChunkOffset; }
set {
if (value < 0) {
@@ -468,9 +456,6 @@ namespace System.Text {
// instance, nulls are appended. The capacity is adjusted to be the same as the length.
public int Length {
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get {
Contract.Ensures(Contract.Result<int>() >= 0);
return m_ChunkOffset + m_ChunkLength;
@@ -687,9 +672,6 @@ namespace System.Text {
// We put this fixed in its own helper to avoid the cost zero initing valueChars in the
// case we don't actually use it.
[System.Security.SecuritySafeCritical] // auto-generated
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
private void AppendHelper(string value) {
unsafe {
fixed (char* valueChars = value)
@@ -700,17 +682,11 @@ namespace System.Text {
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[SecurityCritical]
#if !FEATURE_CORECLR
[System.Runtime.ForceTokenStabilization]
#endif //!FEATURE_CORECLR
internal unsafe extern void ReplaceBufferInternal(char* newBuffer, int newLength);
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[SecurityCritical]
#if !FEATURE_CORECLR
[System.Runtime.ForceTokenStabilization]
#endif //!FEATURE_CORECLR
internal unsafe extern void ReplaceBufferAnsiInternal(sbyte* newBuffer, int newLength);
#endif
// Appends a copy of the characters in value from startIndex to startIndex +
@@ -968,9 +944,6 @@ namespace System.Text {
// Appends an int to this string builder.
// The capacity is adjusted as needed.
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public StringBuilder Append(int value) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
return Append(value.ToString(CultureInfo.CurrentCulture));
@@ -1028,9 +1001,6 @@ namespace System.Text {
// Appends an Object to this string builder.
// The capacity is adjusted as needed.
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public StringBuilder Append(Object value) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
@@ -1291,36 +1261,69 @@ namespace System.Text {
return Insert(index, value.ToString(), 1);
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public StringBuilder AppendFormat(String format, Object arg0) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
return AppendFormat(null, format, new Object[] { arg0 });
return AppendFormatHelper(null, format, new ParamsArray(arg0));
}
public StringBuilder AppendFormat(String format, Object arg0, Object arg1) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
return AppendFormat(null, format, new Object[] { arg0, arg1 });
return AppendFormatHelper(null, format, new ParamsArray(arg0, arg1));
}
public StringBuilder AppendFormat(String format, Object arg0, Object arg1, Object arg2) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
return AppendFormat(null, format, new Object[] { arg0, arg1, arg2 });
return AppendFormatHelper(null, format, new ParamsArray(arg0, arg1, arg2));
}
public StringBuilder AppendFormat(String format, params Object[] args) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
return AppendFormat(null, format, args);
if (args == null)
{
// To preserve the original exception behavior, throw an exception about format if both
// args and format are null. The actual null check for format is in AppendFormatHelper.
throw new ArgumentNullException((format == null) ? "format" : "args");
}
Contract.Ensures(Contract.Result<String>() != null);
Contract.EndContractBlock();
return AppendFormatHelper(null, format, new ParamsArray(args));
}
public StringBuilder AppendFormat(IFormatProvider provider, String format, Object arg0) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
return AppendFormatHelper(provider, format, new ParamsArray(arg0));
}
public StringBuilder AppendFormat(IFormatProvider provider, String format, Object arg0, Object arg1) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
return AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1));
}
public StringBuilder AppendFormat(IFormatProvider provider, String format, Object arg0, Object arg1, Object arg2) {
Contract.Ensures(Contract.Result<StringBuilder>() != null);
return AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1, arg2));
}
public StringBuilder AppendFormat(IFormatProvider provider, String format, params Object[] args) {
if (args == null)
{
// To preserve the original exception behavior, throw an exception about format if both
// args and format are null. The actual null check for format is in AppendFormatHelper.
throw new ArgumentNullException((format == null) ? "format" : "args");
}
Contract.Ensures(Contract.Result<String>() != null);
Contract.EndContractBlock();
return AppendFormatHelper(provider, format, new ParamsArray(args));
}
private static void FormatError() {
throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
}
public StringBuilder AppendFormat(IFormatProvider provider, String format, params Object[] args) {
if (format == null || args == null) {
throw new ArgumentNullException((format == null) ? "format" : "args");
internal StringBuilder AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) {
if (format == null) {
throw new ArgumentNullException("format");
}
Contract.Ensures(Contract.Result<StringBuilder>() != null);
Contract.EndContractBlock();
@@ -1659,10 +1662,14 @@ namespace System.Text {
/// Appends 'value' of length 'count' to the stringBuilder.
/// </summary>
[SecurityCritical]
internal unsafe StringBuilder Append(char* value, int valueCount)
[System.CLSCompliantAttribute(false)]
public unsafe StringBuilder Append(char* value, int valueCount)
{
Contract.Assert(value != null, "Value can't be null");
Contract.Assert(valueCount >= 0, "Count can't be negative");
// We don't check null value as this case will throw null reference exception anyway
if (valueCount < 0)
{
throw new ArgumentOutOfRangeException("valueCount", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
}
// This case is so common we want to optimize for it heavily.
int newIndex = valueCount + m_ChunkLength;
@@ -1876,9 +1883,6 @@ namespace System.Text {
}
#if !MONO
// Copies the source StringBuilder to the destination IntPtr memory allocated with len bytes.
#if !FEATURE_CORECLR
[System.Runtime.ForceTokenStabilization]
#endif //!FEATURE_CORECLR
[System.Security.SecurityCritical] // auto-generated
internal unsafe void InternalCopy(IntPtr dest, int len) {
if(len ==0)