[Mono-list] whitespace handling in Enum::Parse()

Varga Zoltan vargaz@freemail.hu
Tue, 29 Oct 2002 13:52:19 +0100 (CET)


--0-1804289383-1035895939=:43383
Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-2


                       Hi,

  The current version of Enum:Parse() can't parse an input
string with whitespace in it, like "foo, bar". According to
the MSDN docs, it should. The attached patch fixes this and
also adds some tests for this behavior. Can I check it in?

                  bye

                         Zoltan


--0-1804289383-1035895939=:43383
Content-Type: APPLICATION/octet-stream; name="parse.patch"
Content-Disposition: attachment; filename="parse.patch"

? mcs/class/corlib/library-deps.stamp
? mcs/class/corlib/uj
? mcs/class/corlib/Test/.gdb_history
? mcs/class/corlib/Test/library-deps.stamp
? mcs/class/corlib/Test/run_test
Index: mcs/class/corlib//System/ChangeLog
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System/ChangeLog,v
retrieving revision 1.418
diff -u -3 -p -u -r1.418 ChangeLog
--- mcs/class/corlib//System/ChangeLog	24 Oct 2002 11:42:40 -0000	1.418
+++ mcs/class/corlib//System/ChangeLog	29 Oct 2002 12:21:52 -0000
@@ -1,3 +1,7 @@
+2002-10-29  Zoltan Varga  <vargaz@freemail.hu>
+
+	* Enum.cs: Added support for whitespaces in Enum:Parse().
+
 2002-10-24  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
 	* Environment.cs: fixed StackTrace property.
Index: mcs/class/corlib//System/Enum.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System/Enum.cs,v
retrieving revision 1.34
diff -u -3 -p -u -r1.34 Enum.cs
--- mcs/class/corlib//System/Enum.cs	15 Oct 2002 15:52:44 -0000	1.34
+++ mcs/class/corlib//System/Enum.cs	29 Oct 2002 12:21:56 -0000
@@ -241,6 +241,8 @@ namespace System {
 
 			long retVal = 0;
 			string[] names = value.Split(new char[] {','});
+			for (i = 0; i < names.Length; ++i)
+				names [i] = names [i].Trim ();
 			TypeCode typeCode = ((Enum) info.values.GetValue (0)).GetTypeCode ();
 			foreach (string name in names) {
 				bool found = false;
Index: mcs/class/corlib//Test/System/ChangeLog
===================================================================
RCS file: /cvs/public/mcs/class/corlib/Test/System/ChangeLog,v
retrieving revision 1.115
diff -u -3 -p -u -r1.115 ChangeLog
--- mcs/class/corlib//Test/System/ChangeLog	15 Oct 2002 15:23:13 -0000	1.115
+++ mcs/class/corlib//Test/System/ChangeLog	29 Oct 2002 12:22:20 -0000
@@ -1,3 +1,7 @@
+2002-10-29  Zoltan Varga  <vargaz@freemail.hu>
+
+	* EnumTest.cs: Added tests for whitespaces in Enum:Parse().
+
 2002-10-16  Nick Drochak  <ndrochak@gol.com>
 
 	* EnumTest.cs: Find out which Assert is causing the error on mono.
Index: mcs/class/corlib//Test/System/EnumTest.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/Test/System/EnumTest.cs,v
retrieving revision 1.10
diff -u -3 -p -u -r1.10 EnumTest.cs
--- mcs/class/corlib//Test/System/EnumTest.cs	15 Oct 2002 15:23:13 -0000	1.10
+++ mcs/class/corlib//Test/System/EnumTest.cs	29 Oct 2002 12:22:29 -0000
@@ -541,6 +541,10 @@ public class EnumTest : TestCase
 				     TestingEnum.Test, 
 				     Enum.Parse(t1.GetType(), "Test"));
 
+			AssertEquals("parse last enum with whitespace",
+				     TestingEnum.Test, 
+				     Enum.Parse(t1.GetType(), "    \n\nTest\t"));
+
 			AssertEquals("parse bitwise-or enum",
 				     TestingEnum.Is, 
 				     Enum.Parse(t1.GetType(), "This,Is"));
@@ -550,6 +554,10 @@ public class EnumTest : TestCase
 			AssertEquals("parse bitwise-or enum",
 				     TestingEnum.Test, 
 				     Enum.Parse(t1.GetType(), "This,Is,A"));
+
+			AssertEquals("parse bitwise-or enum with whitespace",
+				     TestingEnum.Test, 
+				     Enum.Parse(t1.GetType(), "   \n\tThis \t\n,    Is,A \n"));
 		}
 	}
 	public void TestParse2() {
@@ -649,6 +657,10 @@ public class EnumTest : TestCase
 				     TestingEnum.Test, 
 				     Enum.Parse(t1.GetType(), "test", true));
 
+			AssertEquals("parse last enum with whitespace",
+				     TestingEnum.Test, 
+				     Enum.Parse(t1.GetType(), "    \n\ntest\t", true));
+
 			AssertEquals("parse bitwise-or enum",
 				     TestingEnum.Is, 
 				     Enum.Parse(t1.GetType(), "This,is", true));
@@ -658,6 +670,11 @@ public class EnumTest : TestCase
 			AssertEquals("parse bitwise-or enum",
 				     TestingEnum.Test, 
 				     Enum.Parse(t1.GetType(), "This,is,A", true));
+
+			AssertEquals("parse bitwise-or enum with whitespace",
+				     TestingEnum.Test, 
+					 Enum.Parse(t1.GetType(), "   \n\tThis \t\n,    is,a \n",
+						        true));
 		}
 	}
 

--0-1804289383-1035895939=:43383--