using System.Runtime.InteropServices;
using Mono.Globalization.Unicode;
+using System.Diagnostics.Contracts;
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))
}
// .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;
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]))
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;
}
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");
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)
}
}
-#if NET_4_0
[ComVisible(false)]
public static string Concat (IEnumerable<string> values)
{
}
public static bool IsNullOrWhiteSpace (string value)
-#else
- internal static bool IsNullOrWhiteSpace (string value)
-#endif
{
if ((value == null) || (value.Length == 0))
return true;
memcpy4 ((byte*)dest, (byte*)src, count * 2);
}
+ internal static unsafe void wstrcpy (char *dmem, char *smem, int charCount)
+ {
+ CharCopy (dmem, smem, charCount);
+ }
+
internal static unsafe void CharCopyReverse (char *dest, char *src, int count)
{
dest += count;
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);
[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
}
}