diff Objects/unicodeobject.c @ 16332:bacbb45fe844 legacy-trunk

Fixed .capitalize() method of Unicode objects to work like the corresponding string method. Added tests for this too. Patch written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
author Marc-André Lemburg <mal@egenix.com>
date Mon, 29 Jan 2001 11:14:16 +0000
parents c7c404b35f33
children 725238293869
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Mon Jan 29 09:39:14 2001 +0000
+++ b/Objects/unicodeobject.c	Mon Jan 29 11:14:16 2001 +0000
@@ -2631,11 +2631,25 @@
 static 
 int fixcapitalize(PyUnicodeObject *self)
 {
-    if (self->length > 0 && Py_UNICODE_ISLOWER(self->str[0])) {
-	self->str[0] = Py_UNICODE_TOUPPER(self->str[0]);
-	return 1;
+    int len = self->length;
+    Py_UNICODE *s = self->str;
+    int status = 0;
+    
+    if (len == 0)
+	return 0;
+    if (Py_UNICODE_ISLOWER(*s)) {
+	*s = Py_UNICODE_TOUPPER(*s);
+	status = 1;
     }
-    return 0;
+    s++;
+    while (--len > 0) {
+        if (Py_UNICODE_ISUPPER(*s)) {
+            *s = Py_UNICODE_TOLOWER(*s);
+            status = 1;
+        }
+        s++;
+    }
+    return status;
 }
 
 static