[Mono-devel-list] please review proposed fix for Regex.Split() bug

eric lindvall eric at 5stops.com
Mon Jun 16 17:35:09 EDT 2003


this is a proposed fix for:
http://bugzilla.ximian.com/show_bug.cgi?id=44830

i've noticed there are no testcases for anything other than Regex.Match()
-- is someone going to make any?

thanks.

e.


-------------- next part --------------
Index: regex.cs
===================================================================
RCS file: /mono/mcs/class/System/System.Text.RegularExpressions/regex.cs,v
retrieving revision 1.13
diff -u -p -u -r1.13 regex.cs
--- regex.cs	20 Dec 2002 08:22:50 -0000	1.13
+++ regex.cs	16 Jun 2003 21:29:06 -0000
@@ -321,7 +321,7 @@ namespace System.Text.RegularExpressions
 				count = Int32.MaxValue;
 
 			int ptr = startat;
-			while (count -- > 0) {
+			while (--count > 0) {
 				Match m = Match (input, ptr);
 				if (!m.Success)
 					break;
@@ -330,12 +330,12 @@ namespace System.Text.RegularExpressions
 				ptr = m.Index + m.Length;
 			}
 
-			if (count > 0)
-				splits.Add (input.Substring (ptr));
+                        if (ptr < input.Length)
+                        {
+                            splits.Add (input.Substring (ptr));
+                        }
 
-			string[] result = new string[splits.Count];
-			splits.CopyTo (result);
-			return result;
+			return ((string[]) splits.ToArray (typeof (string)));
 		}
 
 		// object methods


More information about the Mono-devel-list mailing list