Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b015fc86
Commit
b015fc86
authored
Apr 12, 2019
by
Kingsley M
Committed by
Steve Dower
Apr 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36549: str.capitalize now titlecases the first character instead of uppercasing it (GH-12804)
parent
f13c5c8b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
5 deletions
+10
-5
Doc/library/stdtypes.rst
Doc/library/stdtypes.rst
+5
-2
Lib/test/string_tests.py
Lib/test/string_tests.py
+1
-1
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+1
-1
Misc/NEWS.d/next/Core and Builtins/2019-04-11-12-41-31.bpo-36549.QSp8of.rst
...ore and Builtins/2019-04-11-12-41-31.bpo-36549.QSp8of.rst
+2
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+1
-1
No files found.
Doc/library/stdtypes.rst
View file @
b015fc86
...
...
@@ -1509,6 +1509,10 @@ expression support in the :mod:`re` module).
Return a copy of the string with its first character capitalized and the
rest lowercased.
.. versionchanged:: 3.8
The first character is now put into titlecase rather than uppercase.
This means that characters like digraphs will only have their first
letter capitalized, instead of the full character.
.. method:: str.casefold()
...
...
@@ -2052,8 +2056,7 @@ expression support in the :mod:`re` module).
>>> import re
>>> def titlecase(s):
... return re.sub(r"[A-Za-z]+('[A-Za-z]+)?",
... lambda mo: mo.group(0)[0].upper() +
... mo.group(0)[1:].lower(),
... lambda mo: mo.group(0).capitalize(),
... s)
...
>>> titlecase("they're bill's friends.")
...
...
Lib/test/string_tests.py
View file @
b015fc86
...
...
@@ -977,7 +977,7 @@ class CommonTest(BaseTest):
def
test_capitalize_nonascii
(
self
):
# check that titlecased chars are lowered correctly
# \u1ffc is the titlecased char
self
.
checkequal
(
'
\
u
03a9
\
u0399
\
u1ff3
\
u1ff3
\
u1ff3
'
,
self
.
checkequal
(
'
\
u
1ffc
\
u1ff3
\
u1ff3
\
u1ff3
'
,
'
\
u1ff3
\
u1ff3
\
u1ffc
\
u1ffc
'
,
'capitalize'
)
# check with cased non-letter chars
self
.
checkequal
(
'
\
u24c5
\
u24e8
\
u24e3
\
u24d7
\
u24de
\
u24dd
'
,
...
...
Lib/test/test_unicode.py
View file @
b015fc86
...
...
@@ -811,7 +811,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertEqual
(
'h
\
u0130
'
.
capitalize
(),
'H
\
u0069
\
u0307
'
)
exp
=
'
\
u0399
\
u0308
\
u0300
\
u0069
\
u0307
'
self
.
assertEqual
(
'
\
u1fd2
\
u0130
'
.
capitalize
(),
exp
)
self
.
assertEqual
(
'finnish'
.
capitalize
(),
'F
I
nnish'
)
self
.
assertEqual
(
'finnish'
.
capitalize
(),
'F
i
nnish'
)
self
.
assertEqual
(
'A
\
u0345
\
u03a3
'
.
capitalize
(),
'A
\
u0345
\
u03c2
'
)
def
test_title
(
self
):
...
...
Misc/NEWS.d/next/Core and Builtins/2019-04-11-12-41-31.bpo-36549.QSp8of.rst
0 → 100644
View file @
b015fc86
Change str.capitalize to use titlecase for the first character instead of
uppercase.
Objects/unicodeobject.c
View file @
b015fc86
...
...
@@ -9675,7 +9675,7 @@ do_capitalize(int kind, void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *ma
Py_UCS4
c
,
mapped
[
3
];
c
=
PyUnicode_READ
(
kind
,
data
,
0
);
n_res
=
_PyUnicode_To
Upper
Full
(
c
,
mapped
);
n_res
=
_PyUnicode_To
Title
Full
(
c
,
mapped
);
for
(
j
=
0
;
j
<
n_res
;
j
++
)
{
*
maxchar
=
Py_MAX
(
*
maxchar
,
mapped
[
j
]);
res
[
k
++
]
=
mapped
[
j
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment