2004-10-14 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Thu, 14 Oct 2004 19:50:36 +0000 (19:50 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 14 Oct 2004 19:50:36 +0000 (19:50 -0000)
* TextInfo.cs: Fix ToTitleCase to do title case for each word on
the string per the spec.

svn path=/branches/mono-1-0/mcs/; revision=35009

mcs/class/corlib/System.Globalization/ChangeLog
mcs/class/corlib/System.Globalization/TextInfo.cs

index 95392d51e96fd6df3bd4774e6685345bfeee0fa6..576127cba912c09be19ad13dd491f7acb95a4a0d 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-14  Miguel de Icaza  <miguel@ximian.com>
+
+       * TextInfo.cs: Fix ToTitleCase to do title case for each word on
+       the string per the spec.
+
 2004-06-17  Atsushi Enomoto  <atsushi@ximian.com>
 
        * DateTimeFormatInfo.cs : check if pattern array is empty or not. Now
index 7e1d8cc7a1f6e868c3516e8adb838e195addc537..43b0da08610a30e6464cbec17f4c59019d30eaf2 100755 (executable)
@@ -137,11 +137,22 @@ namespace System.Globalization {
                                throw new ArgumentNullException("string is null");
                        
                        Text.StringBuilder s = new Text.StringBuilder ();
-
-                       s.Append (Char.ToUpper (str [0]));
-
-                       for (int i = 1; i < str.Length; i ++)
-                               s.Append (str [i]);
+                       bool space_seen = true;
+                               
+                       for (int i = 0; i < str.Length; i ++){
+                               char c = str [i];
+                               if (Char.IsLetter (c)){
+                                       if (space_seen)
+                                               s.Append (Char.ToUpper (c));
+                                       else
+                                               s.Append (Char.ToLower (c));
+                                       space_seen = false;
+                               } else {
+                                       s.Append (c);
+                                       if (Char.IsWhiteSpace (c))
+                                               space_seen = true;
+                               }
+                       }
 
                        return s.ToString ();
                }