if (count == 1)
return new String[1] { ToString() };
- return InternalSplit (separator, count);
+ return InternalSplit (separator, count, 0);
}
#if NET_2_0
[ComVisible (false)]
- [MonoTODO]
+ [MonoDocumentationNote ("code should be moved to managed")]
public String[] Split (char[] separator, int count, StringSplitOptions options)
{
if (separator == null || separator.Length == 0)
if ((options != StringSplitOptions.None) && (options != StringSplitOptions.RemoveEmptyEntries))
throw new ArgumentException ("options must be one of the values in the StringSplitOptions enumeration", "options");
- bool removeEmpty = (options & StringSplitOptions.RemoveEmptyEntries) == StringSplitOptions.RemoveEmptyEntries;
+ if (count == 0)
+ return new string [0];
- if (!removeEmpty)
- return Split (separator, count);
- else {
- /* FIXME: Optimize this */
- String[] res = Split (separator, count);
- int n = 0;
- for (int i = 0; i < res.Length; ++i)
- if (res [i] == String.Empty)
- n ++;
- if (n > 0) {
- String[] arr = new String [res.Length - n];
- int pos = 0;
- for (int i = 0; i < res.Length; ++i)
- if (res [i] != String.Empty)
- arr [pos ++] = res [i];
- return arr;
- }
- else
- return res;
- }
+ return InternalSplit (separator, count, (int)options);
}
[ComVisible (false)]
return Compare (this, strB, false);
}
- public static int CompareOrdinal (String strA, String strB)
+ public static unsafe int CompareOrdinal (String strA, String strB)
{
- return CompareOrdinal (strA, strB, CompareOptions.Ordinal);
+ if (strA == null) {
+ if (strB == null)
+ return 0;
+ else
+ return -1;
+ } else if (strB == null) {
+ return 1;
+ }
+ fixed (char* aptr = strA, bptr = strB) {
+ char* ap = aptr;
+ char* end = ap + Math.Min (strA.Length, strB.Length);
+ char* bp = bptr;
+ while (ap < end) {
+ if (*ap != *bp)
+ return *ap - *bp;
+ ap++;
+ bp++;
+ }
+ return strA.Length - strB.Length;
+ }
}
internal static int CompareOrdinal (String strA, String strB, CompareOptions options)
return 0;
else
return -1;
- }
- else if (strB == null) {
+ } else if (strB == null) {
return 1;
}
}
#if NET_2_0
+ [ComVisible (false)]
public bool StartsWith (string value, StringComparison comparisonType)
{
switch (comparisonType) {
}
}
+ [ComVisible (false)]
public bool EndsWith (string value, StringComparison comparisonType)
{
switch (comparisonType) {
return enc.GetString (bytes);
}
+ unsafe string CreateString (char *value)
+ {
+ if (value == null)
+ return string.Empty;
+ char *p = value;
+ int i = 0;
+ while (*p != 0) {
+ ++i;
+ ++p;
+ }
+ string result = InternalAllocateStr (i);
+
+ if (i != 0) {
+ fixed (char *dest = result) {
+ memcpy ((byte*)dest, (byte*)value, i * 2);
+ }
+ }
+ return result;
+ }
+
+ unsafe string CreateString (char *value, int startIndex, int length)
+ {
+ if (length == 0)
+ return string.Empty;
+ if (value == null)
+ throw new ArgumentNullException ("value");
+ if (startIndex < 0)
+ throw new ArgumentOutOfRangeException ("startIndex");
+ if (length < 0)
+ throw new ArgumentOutOfRangeException ("length");
+
+ string result = InternalAllocateStr (length);
+
+ fixed (char *dest = result) {
+ memcpy ((byte*)dest, (byte*)(value + startIndex), length * 2);
+ }
+ return result;
+ }
+
+ unsafe string CreateString (char [] val, int startIndex, int length)
+ {
+ if (val == null)
+ throw new ArgumentNullException ("val");
+ if (startIndex < 0)
+ throw new ArgumentOutOfRangeException ("startIndex");
+ if (length < 0)
+ throw new ArgumentOutOfRangeException ("length");
+ if (startIndex > val.Length - length)
+ throw new ArgumentOutOfRangeException ("Out of range");
+ if (length == 0)
+ return string.Empty;
+
+ string result = InternalAllocateStr (length);
+
+ fixed (char *dest = result, src = val) {
+ memcpy ((byte*)dest, (byte*)(src + startIndex), length * 2);
+ }
+ return result;
+ }
+
+ unsafe string CreateString (char [] val)
+ {
+ if (val == null)
+ return string.Empty;
+ if (val.Length == 0)
+ return string.Empty;
+ string result = InternalAllocateStr (val.Length);
+
+ fixed (char *dest = result, src = val) {
+ memcpy ((byte*)dest, (byte*)src, val.Length * 2);
+ }
+ return result;
+ }
+
+ unsafe string CreateString (char c, int count)
+ {
+ if (count < 0)
+ throw new ArgumentOutOfRangeException ("count");
+ if (count == 0)
+ return string.Empty;
+ string result = InternalAllocateStr (count);
+ fixed (char *dest = result) {
+ char *p = dest;
+ char *end = p + count;
+ while (p < end) {
+ *p = c;
+ p++;
+ }
+ }
+ return result;
+ }
+
/* helpers used by the runtime as well as above or eslewhere in corlib */
internal static unsafe void memset (byte *dest, int val, int len)
{
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static string InternalJoin (string separator, string[] value, int sIndex, int count);
- //[MethodImplAttribute (MethodImplOptions.InternalCall)]
- //private extern String InternalReplace (char oldChar, char newChar, int startIndex);
-
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern String InternalReplace (String oldValue, string newValue, CompareInfo comp);
private extern void InternalCopyTo (int sIndex, char[] dest, int destIndex, int count);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern String[] InternalSplit (char[] separator, int count);
+ private extern String[] InternalSplit (char[] separator, int count, int options);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern String InternalTrim (char[] chars, int typ);
- //[MethodImplAttribute (MethodImplOptions.InternalCall)]
- //private extern int InternalIndexOfAny (char [] arr, int sIndex, int count);
-
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern int InternalLastIndexOfAny (char [] anyOf, int sIndex, int count);