]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased...
authorEzio Melotti <ezio.melotti@gmail.com>
Mon, 15 Aug 2011 06:09:57 +0000 (09:09 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Mon, 15 Aug 2011 06:09:57 +0000 (09:09 +0300)
Lib/test/string_tests.py
Misc/NEWS
Objects/unicodeobject.c

index fca38c3ea06292b0a009994b5abb85df826f46bd..d7925290206c2bf01e5232d8a00be036faea2cf4 100644 (file)
@@ -641,6 +641,23 @@ class CommonTest(BaseTest):
         self.checkequal('Aaaa', 'aaaa', 'capitalize')
         self.checkequal('Aaaa', 'AaAa', 'capitalize')
 
+        # check that titlecased chars are lowered correctly
+        # \u1ffc is the titlecased char
+        self.checkequal('\u1ffc\u1ff3\u1ff3\u1ff3',
+                        '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize')
+        # check with cased non-letter chars
+        self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
+                        '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize')
+        self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
+                        '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize')
+        self.checkequal('\u2160\u2171\u2172',
+                        '\u2160\u2161\u2162', 'capitalize')
+        self.checkequal('\u2160\u2171\u2172',
+                        '\u2170\u2171\u2172', 'capitalize')
+        # check with Ll chars with no upper - nothing changes here
+        self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7',
+                        '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize')
+
         self.checkraises(TypeError, 'hello', 'capitalize', 42)
 
     def test_lower(self):
index 328ec61c1eacde036f8f78e52dfae1dc8e4640c6..cbede912fc65d5266758cd076938bde603a64081 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2,6 +2,18 @@
 Python News
 +++++++++++
 
+What's New in Python 3.2.3?
+===========================
+
+*Release date: XX-XXX-2011*
+
+Core and Builtins
+-----------------
+
+- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
+  titlecased and cased non-letter characters.
+
+
 What's New in Python 3.2.2?
 ===========================
 
index a48b8b41b1348d419b60d39ab93af79cf348a5ab..77f8dd5a810ea049b19871fbbe372adf6d7044aa 100644 (file)
@@ -6658,13 +6658,13 @@ int fixcapitalize(PyUnicodeObject *self)
 
     if (len == 0)
         return 0;
-    if (Py_UNICODE_ISLOWER(*s)) {
+    if (!Py_UNICODE_ISUPPER(*s)) {
         *s = Py_UNICODE_TOUPPER(*s);
         status = 1;
     }
     s++;
     while (--len > 0) {
-        if (Py_UNICODE_ISUPPER(*s)) {
+        if (!Py_UNICODE_ISLOWER(*s)) {
             *s = Py_UNICODE_TOLOWER(*s);
             status = 1;
         }