Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@ -51,6 +51,7 @@ using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using Mono.Globalization.Unicode;
using System.Diagnostics.Contracts;
namespace System
{
@ -66,6 +67,12 @@ namespace System
internal static readonly int LOS_limit = GetLOSLimit ();
internal static bool LegacyMode {
get {
return false;
}
}
public static unsafe bool Equals (string a, string b)
{
if ((a as object) == (b as object))
@ -312,22 +319,9 @@ namespace System
}
// .NET 2.0 compatibility only
#if !NET_4_0 && !MOBILE
static readonly char[] WhiteChars = {
(char) 0x9, (char) 0xA, (char) 0xB, (char) 0xC, (char) 0xD,
(char) 0x85, (char) 0x1680, (char) 0x2028, (char) 0x2029,
(char) 0x20, (char) 0xA0, (char) 0x2000, (char) 0x2001, (char) 0x2002, (char) 0x2003, (char) 0x2004,
(char) 0x2005, (char) 0x2006, (char) 0x2007, (char) 0x2008, (char) 0x2009, (char) 0x200A, (char) 0x200B,
(char) 0x3000, (char) 0xFEFF
};
#endif
unsafe string[] SplitByCharacters (char[] sep, int count, bool removeEmpty)
{
#if !NET_4_0 && !MOBILE
if (sep == null || sep.Length == 0)
sep = WhiteChars;
#endif
int[] split_points = null;
int total_points = 0;
@ -539,7 +533,6 @@ namespace System
unsafe int FindNotWhiteSpace (int pos, int target, int change)
{
#if NET_4_0
fixed (char* src = this) {
while (pos != target) {
if (!char.IsWhiteSpace (src[pos]))
@ -548,25 +541,6 @@ namespace System
pos += change;
}
}
#else
while (pos != target) {
char c = this[pos];
if (c < 0x85) {
if (c != 0x20) {
if (c < 0x9 || c > 0xD)
return pos;
}
}
else {
if (c != 0xA0 && c != 0xFEFF && c != 0x3000) {
if (c != 0x85 && c != 0x1680 && c != 0x2028 && c != 0x2029)
if (c < 0x2000 || c > 0x200B)
return pos;
}
}
pos += change;
}
#endif
return pos;
}
@ -2405,11 +2379,7 @@ namespace System
return InternalIsInterned (str);
}
#if NET_4_0
public static string Join (string separator, params string [] value)
#else
public static string Join (string separator, string [] value)
#endif
{
if (value == null)
throw new ArgumentNullException ("value");
@ -2543,11 +2513,9 @@ namespace System
return Convert.ToSingle (this, provider);
}
object IConvertible.ToType (Type targetType, IFormatProvider provider)
object IConvertible.ToType (Type type, IFormatProvider provider)
{
if (targetType == null)
throw new ArgumentNullException ("type");
return Convert.ToType (this, targetType, provider, false);
return Convert.DefaultToType ((IConvertible)this, type, provider);
}
ushort IConvertible.ToUInt16 (IFormatProvider provider)
@ -2710,7 +2678,6 @@ namespace System
}
}
#if NET_4_0
[ComVisible(false)]
public static string Concat (IEnumerable<string> values)
{
@ -2798,9 +2765,6 @@ namespace System
}
public static bool IsNullOrWhiteSpace (string value)
#else
internal static bool IsNullOrWhiteSpace (string value)
#endif
{
if ((value == null) || (value.Length == 0))
return true;
@ -3219,6 +3183,11 @@ namespace System
CharCopyReverse (dest + targetIndex, src + sourceIndex, count);
}
internal static String FastAllocateString (int length)
{
return InternalAllocateStr (length);
}
[CLSCompliant (false), MethodImplAttribute (MethodImplOptions.InternalCall)]
unsafe public extern String (char *value);
@ -3254,5 +3223,51 @@ namespace System
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static int GetLOSLimit ();
#region "from referencesource" // and actually we replaced some parts.
// Helper for encodings so they can talk to our buffer directly
// stringLength must be the exact size we'll expect
[System.Security.SecurityCritical] // auto-generated
unsafe static internal String CreateStringFromEncoding(
byte* bytes, int byteLength, Encoding encoding)
{
Contract.Requires(bytes != null);
Contract.Requires(byteLength >= 0);
// Get our string length
int stringLength = encoding.GetCharCount(bytes, byteLength, null);
Contract.Assert(stringLength >= 0, "stringLength >= 0");
// They gave us an empty string if they needed one
// 0 bytelength might be possible if there's something in an encoder
if (stringLength == 0)
return String.Empty;
String s = FastAllocateString(stringLength);
fixed(char* pTempChars = &s.start_char)
{
int doubleCheck = encoding.GetChars(bytes, byteLength, pTempChars, stringLength, null);
Contract.Assert(stringLength == doubleCheck,
"Expected encoding.GetChars to return same length as encoding.GetCharCount");
}
return s;
}
// our own implementation for CLR icall.
unsafe internal static int nativeCompareOrdinalIgnoreCaseWC (string name, sbyte *strBBytes)
{
for (int i = 0; i < name.Length; i++) {
sbyte b = *(strBBytes + i);
if (b < 0)
throw new ArgumentException ();
int ret = char.ToUpper ((char) b) - char.ToUpper (name [i]);
if (ret != 0)
return ret;
}
return 0;
}
#endregion
}
}