Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee8d998

Browse files
committed
#12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
1 parent 388c945 commit ee8d998

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

Lib/test/string_tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,23 @@ def test_capitalize(self):
641641
self.checkequal('Aaaa', 'aaaa', 'capitalize')
642642
self.checkequal('Aaaa', 'AaAa', 'capitalize')
643643

644+
# check that titlecased chars are lowered correctly
645+
# \u1ffc is the titlecased char
646+
self.checkequal('\u1ffc\u1ff3\u1ff3\u1ff3',
647+
'\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize')
648+
# check with cased non-letter chars
649+
self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
650+
'\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize')
651+
self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
652+
'\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize')
653+
self.checkequal('\u2160\u2171\u2172',
654+
'\u2160\u2161\u2162', 'capitalize')
655+
self.checkequal('\u2160\u2171\u2172',
656+
'\u2170\u2171\u2172', 'capitalize')
657+
# check with Ll chars with no upper - nothing changes here
658+
self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7',
659+
'\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize')
660+
644661
self.checkraises(TypeError, 'hello', 'capitalize', 42)
645662

646663
def test_lower(self):

Misc/NEWS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
Python News
33
+++++++++++
44

5+
What's New in Python 3.2.3?
6+
===========================
7+
8+
*Release date: XX-XXX-2011*
9+
10+
Core and Builtins
11+
-----------------
12+
13+
- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
14+
titlecased and cased non-letter characters.
15+
16+
517
What's New in Python 3.2.2?
618
===========================
719

Objects/unicodeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6658,13 +6658,13 @@ int fixcapitalize(PyUnicodeObject *self)
66586658

66596659
if (len == 0)
66606660
return 0;
6661-
if (Py_UNICODE_ISLOWER(*s)) {
6661+
if (!Py_UNICODE_ISUPPER(*s)) {
66626662
*s = Py_UNICODE_TOUPPER(*s);
66636663
status = 1;
66646664
}
66656665
s++;
66666666
while (--len > 0) {
6667-
if (Py_UNICODE_ISUPPER(*s)) {
6667+
if (!Py_UNICODE_ISLOWER(*s)) {
66686668
*s = Py_UNICODE_TOLOWER(*s);
66696669
status = 1;
66706670
}

0 commit comments

Comments
 (0)