dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnetlib ChangeLog runtime/System/String.cs samp...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnetlib ChangeLog runtime/System/String.cs samp...
Date: Sun, 19 Apr 2009 09:44:19 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnetlib
Changes by:     Klaus Treichel <ktreichel>      09/04/19 09:44:19

Modified files:
        .              : ChangeLog 
        runtime/System : String.cs 
        samples/developers: MainForm.cs 
        tests/runtime/System: TestString.cs 

Log message:
        Fix String.ToCharArray where length == 0 and add testcases for this bug.
        Fix the assembly version attribute in the developers sample.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnetlib/ChangeLog?cvsroot=dotgnu-pnet&r1=1.2581&r2=1.2582
http://cvs.savannah.gnu.org/viewcvs/pnetlib/runtime/System/String.cs?cvsroot=dotgnu-pnet&r1=1.46&r2=1.47
http://cvs.savannah.gnu.org/viewcvs/pnetlib/samples/developers/MainForm.cs?cvsroot=dotgnu-pnet&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/pnetlib/tests/runtime/System/TestString.cs?cvsroot=dotgnu-pnet&r1=1.14&r2=1.15

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/ChangeLog,v
retrieving revision 1.2581
retrieving revision 1.2582
diff -u -b -r1.2581 -r1.2582
--- ChangeLog   19 Apr 2009 07:16:34 -0000      1.2581
+++ ChangeLog   19 Apr 2009 09:44:18 -0000      1.2582
@@ -6,11 +6,19 @@
        getters and setters where they belong to instead of the property or
        indexer.
 
+       * runtime/System/String.cs (ToCharArray): Handle empty strings and the
+       case where the passed lenght is 0 correctly.
+       This fixes bug #26225 too. (thanks Thomas Uxiou)
+
        * runtime/System/Reflection/AssemblyFlagsAttribute.cs: Add the new
        2.0 constructor using AssemblyNameFlags as argument.
 
+       * samples/developers/MainForm.cs: Fix the assembly version.
+
        * System.Windows.Forms/RichTextBox.cs (Rtf): Fix the 
DefaulValueAttribute.
 
+       * tests/runtime/System/TestString.cs: Add tests for ToCharArray.
+
 2009-04-18  Thomas Uxiou  <address@hidden>
 
        * runtime/System/TimeSpan.cs: Fix incorrect result for

Index: runtime/System/String.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/String.cs,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- runtime/System/String.cs    18 Apr 2009 10:25:04 -0000      1.46
+++ runtime/System/String.cs    19 Apr 2009 09:44:19 -0000      1.47
@@ -45,6 +45,9 @@
 
        // Private constants
        private static readonly char[] curlyBraces = { '{', '}' };
+       // Arrays with a length of 0 are immutable so we can use the same one
+       // whenever an empty chararray has to be returned.
+       private static readonly char[] emptyCharArray = new char[0];
 
        // Public constants.
        public static readonly String Empty = "";
@@ -1500,12 +1503,26 @@
        // Convert this string into a character array.
        public char[] ToCharArray()
                        {
-                               return ToCharArray(0, length);
+                               if(length > 0)
+                               {
+                                       char[] result;
+                                       result = new char [length];
+                                       CopyToChecked(0, result, 0, length);
+                                       return result;
+                               }
+                               else
+                               {
+                                       return emptyCharArray;
+                               }
                        }
        public char[] ToCharArray(int startIndex, int ilength)
                        {
-                               char[] result;
-                               if(startIndex < 0 || startIndex > length)
+                               if(ilength == 0)
+                               {
+                                       ilength = length;
+                                       startIndex = 0;
+                               }
+                               else if(startIndex < 0 || startIndex >= length)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("startIndex", 
_("ArgRange_StringIndex"));
@@ -1515,10 +1532,18 @@
                                        throw new ArgumentOutOfRangeException
                                                ("length", 
_("ArgRange_StringRange"));
                                }
+                               if(ilength > 0)
+                               {
+                                       char[] result;
                                result = new char [ilength];
                                CopyToChecked(startIndex, result, 0, ilength);
                                return result;
                        }
+                               else
+                               {
+                                       return emptyCharArray;
+                               }
+                       }
 
        // Convert a string into lower case.
        public String ToLower()

Index: samples/developers/MainForm.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/samples/developers/MainForm.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- samples/developers/MainForm.cs      7 Oct 2004 17:16:49 -0000       1.5
+++ samples/developers/MainForm.cs      19 Apr 2009 09:44:19 -0000      1.6
@@ -12,7 +12,7 @@
 using System.Windows.Forms;
 using System.Text.RegularExpressions;
 
-[assembly:AssemblyVersion("0.0.1")]
+[assembly:AssemblyVersion("0.0.0.1")]
 
 namespace ThreadsDemo
 {

Index: tests/runtime/System/TestString.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/TestString.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- tests/runtime/System/TestString.cs  18 Apr 2009 10:25:04 -0000      1.14
+++ tests/runtime/System/TestString.cs  19 Apr 2009 09:44:19 -0000      1.15
@@ -1346,5 +1346,15 @@
                AssertEquals("\"Foo Bar\".Length","Foo Bar".Length,7);
                AssertEquals("\"\".Length","".Length,0);
        }
-
+       public void TestStringToCharArray()
+       {
+               char[] foo;
+               String bar;
+               foo = String.Empty.ToCharArray();
+               /* If length is 0 the startindex has to be ignored */
+               foo = String.Empty.ToCharArray(10, 0);
+               bar = "abc";
+               foo = bar.ToCharArray(2, 0);
+               AssertEquals("\"abc\".ToCharArray(2, 0)",foo.Length, 3);
+       }
 }; // class TestString




reply via email to

[Prev in Thread] Current Thread [Next in Thread]