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
3f3bac9c
Commit
3f3bac9c
authored
Jun 11, 1996
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add third arg to split(). Add capwords() -- which uses that.
parent
95f9d51b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
Lib/regsub.py
Lib/regsub.py
+15
-1
No files found.
Lib/regsub.py
View file @
3f3bac9c
...
...
@@ -50,8 +50,10 @@ def gsub(pat, repl, str):
# Split string str in fields separated by delimiters matching pattern
# pat. Only non-empty matches for the pattern are considered, so e.g.
# split('abc', '') returns ['abc'].
# When the optional 3rd argument is true, the separators are also
# inserted to the list.
def
split
(
str
,
pat
):
def
split
(
str
,
pat
,
retain
=
0
):
prog
=
compile
(
pat
)
res
=
[]
start
=
next
=
0
...
...
@@ -64,11 +66,23 @@ def split(str, pat):
break
else
:
res
.
append
(
str
[
start
:
a
])
if
retain
:
res
.
append
(
str
[
a
:
b
])
start
=
next
=
b
res
.
append
(
str
[
start
:])
return
res
# Capitalize words split using a pattern
def
capwords
(
str
,
pat
):
import
string
words
=
split
(
str
,
pat
,
1
)
for
i
in
range
(
0
,
len
(
words
),
2
):
words
[
i
]
=
string
.
capitalize
(
words
[
i
])
return
string
.
joinfields
(
words
,
""
)
# Internal subroutines:
# compile(pat): compile a pattern, caching already compiled patterns
# expand(repl, regs, str): expand \digit escapes in replacement string
...
...
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