Author: lupus
Date: 2007-10-12 02:07:23 -0400 (Fri, 12 Oct 2007)
New Revision: 87370
Modified:
trunk/mcs/class/corlib/System/ChangeLog
trunk/mcs/class/corlib/System/String.cs
trunk/mcs/class/corlib/Test/System/StringTest.cs
Log:
Fri Oct 12 08:11:50 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
* String.cs: reverted unapproved patch that breaks the build.
Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog 2007-10-12 06:07:20 UTC (rev
87369)
+++ trunk/mcs/class/corlib/System/ChangeLog 2007-10-12 06:07:23 UTC (rev
87370)
@@ -1,3 +1,8 @@
+
+Fri Oct 12 08:11:50 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
+
+ * String.cs: reverted unapproved patch that breaks the build.
+
2007-10-11 Joel Reed <[EMAIL PROTECTED]>
* String.cs: fix String.Split(char[],int,StringSplitOptions)
Modified: trunk/mcs/class/corlib/System/String.cs
===================================================================
--- trunk/mcs/class/corlib/System/String.cs 2007-10-12 06:07:20 UTC (rev
87369)
+++ trunk/mcs/class/corlib/System/String.cs 2007-10-12 06:07:23 UTC (rev
87370)
@@ -216,11 +216,12 @@
if (count == 1)
return new String[1] { ToString() };
- return InternalSplit (separator, count, 0);
+ return InternalSplit (separator, count);
}
#if NET_2_0
[ComVisible (false)]
+ [MonoDocumentationNote ("optimization")]
public String[] Split (char[] separator, int count,
StringSplitOptions options)
{
if (separator == null || separator.Length == 0)
@@ -231,9 +232,28 @@
if ((options != StringSplitOptions.None) && (options !=
StringSplitOptions.RemoveEmptyEntries))
throw new ArgumentException ("options must be
one of the values in the StringSplitOptions enumeration", "options");
- if (count==0) return new String[0];
+ bool removeEmpty = (options &
StringSplitOptions.RemoveEmptyEntries) == StringSplitOptions.RemoveEmptyEntries;
- return InternalSplit (separator, count, (int) (options
& StringSplitOptions.RemoveEmptyEntries) );
+ 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;
+ }
}
[ComVisible (false)]
@@ -2441,7 +2461,7 @@
private extern void InternalCopyTo (int sIndex, char[] dest,
int destIndex, int count);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern String[] InternalSplit (char[] separator, int
count, int options);
+ private extern String[] InternalSplit (char[] separator, int
count);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern String InternalTrim (char[] chars, int typ);
Modified: trunk/mcs/class/corlib/Test/System/StringTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/StringTest.cs 2007-10-12 06:07:20 UTC
(rev 87369)
+++ trunk/mcs/class/corlib/Test/System/StringTest.cs 2007-10-12 06:07:23 UTC
(rev 87370)
@@ -1898,68 +1898,6 @@
AssertEquals ("B", res [1]);
AssertEquals ("C", res [2]);
}
-
- [Test]
- public void SplitStringChars()
- {
- String[] res;
-
- // count == 0
- res = "..A..B..".Split (new Char[] { '.' }, 0,
StringSplitOptions.None);
- AssertEquals ("#01-01", 0, res.Length);
-
- // count == 1
- res = "..A..B..".Split (new Char[] { '.' }, 1,
StringSplitOptions.None);
- AssertEquals ("#02-01", 1, res.Length);
- AssertEquals ("#02-02", "..A..B..", res[0]);
-
- // count == 1 + RemoveEmpty
- res = "..A..B..".Split (new Char[] { '.' }, 1,
StringSplitOptions.RemoveEmptyEntries);
- AssertEquals ("#03-01", 1, res.Length);
- AssertEquals ("#03-02", "..A..B..", res[0]);
-
- // Keeping Empties and multipe split chars
- res = "..A;.B.;".Split (new Char[] { '.', ';' },
StringSplitOptions.None);
- AssertEquals ("#04-01", 7, res.Length);
- AssertEquals ("#04-02", "", res[0]);
- AssertEquals ("#04-03", "", res[1]);
- AssertEquals ("#04-04", "A", res[2]);
- AssertEquals ("#04-05", "", res[3]);
- AssertEquals ("#04-06", "B", res[4]);
- AssertEquals ("#04-07", "", res[5]);
- AssertEquals ("#04-08", "", res[6]);
-
- // Trimming (3 tests)
- res = "..A".Split (new Char[] { '.' }, 2,
StringSplitOptions.RemoveEmptyEntries);
- AssertEquals ("#05-01", 1, res.Length);
- AssertEquals ("#05-02", "A", res[0]);
-
- res = "A..".Split (new Char[] { '.' }, 2,
StringSplitOptions.RemoveEmptyEntries);
- AssertEquals ("#06-01", 1, res.Length);
- AssertEquals ("#06-02", "A", res[0]);
-
- res = "..A..".Split (new Char[] { '.' }, 2,
StringSplitOptions.RemoveEmptyEntries);
- AssertEquals ("#07-01", 1, res.Length);
- AssertEquals ("#07-02", "A", res[0]);
-
- // Lingering Tail
- res = "..A..B..".Split (new Char[] { '.' }, 2,
StringSplitOptions.RemoveEmptyEntries);
- AssertEquals ("#08-01", 2, res.Length);
- AssertEquals ("#08-02", "A", res[0]);
- AssertEquals ("#08-03", "B..", res[1]);
-
- // Whitespace and Long split chain (removing empty chars)
- res = " A\tBC\n\rDEF GHI ".Split ((Char[])null,
StringSplitOptions.RemoveEmptyEntries);
- AssertEquals ("#09-01", 4, res.Length);
- AssertEquals ("#09-02", "A", res[0]);
- AssertEquals ("#09-03", "BC", res[1]);
- AssertEquals ("#09-04", "DEF", res[2]);
- AssertEquals ("#09-05", "GHI", res[3]);
-
- // Nothing but separators
- res = "..,.;.,".Split (new
Char[]{'.',',',';'},2,StringSplitOptions.RemoveEmptyEntries);
- AssertEquals ("#10-01", 0, res.Length);
- }
#endif
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches