-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make replace
with count=0 a no-op
#22325
Changes from 1 commit
7688517
5b99e0a
2f26043
d387b31
bd0079a
5d03ce1
06a8cfd
06a7706
d77b51a
4f60ef7
981e8da
4405d63
ff0b955
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,6 +360,7 @@ _replace(io, repl::Function, str, r, pattern) = | |
print(io, repl(SubString(str, first(r), last(r)))) | ||
|
||
function replace(str::String, pattern, repl, limit::Integer) | ||
limit == 0 && return str | ||
n = 1 | ||
e = endof(str) | ||
i = a = start(str) | ||
|
@@ -402,7 +403,7 @@ If `pat` is a regular expression and `r` is a `SubstitutionString`, then capture | |
references in `r` are replaced with the corresponding matched text. | ||
""" | ||
replace(s::AbstractString, pat, f, n::Integer) = replace(String(s), pat, f, n) | ||
replace(s::AbstractString, pat, r) = replace(s, pat, r, 0) | ||
replace(s::AbstractString, pat, r) = replace(s, pat, r, -1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably mention this in the docstring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok (Note that it's not mentioned in Python's docstring either) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is python relevant? The docstring above says "If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, that was not so relevant, only as a mature language which doesn't mention the behavior for negative inputs, which is same as here, i.e. replace all. Will add that. |
||
|
||
# hex <-> bytes conversion | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're at it, maybe rename the argument so that it's consistent with the docstring (or change the docstring)?