-
-
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 |
---|---|---|
|
@@ -1503,6 +1503,17 @@ function bkfact!(A::StridedMatrix, uplo::Symbol, symmetric::Bool = issymmetric(A | |
return bkfact!(symmetric ? Symmetric(A, uplo) : Hermitian(A, uplo), rook) | ||
end | ||
|
||
function replace(s::AbstractString, pat, f, n::Integer) | ||
if n <= 0 | ||
depwarn(string("`replace(s, pat, r, count)` with `count <= 0` is deprecated, use ", | ||
"`replace(s, pat, r, typemax(Int))` or replace(s, pat, r)` instead"), | ||
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. Missing opening backtick. |
||
:replace) | ||
Base.replace(s, pat, f) | ||
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.
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 removed. |
||
else | ||
Base.replace_new(String(s), pat, f, Int(n)) | ||
end | ||
end | ||
|
||
# END 0.7 deprecations | ||
|
||
# BEGIN 1.0 deprecations | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,9 +359,10 @@ _replace(io, repl, str, r, pattern) = print(io, repl) | |
_replace(io, repl::Function, str, r, pattern) = | ||
print(io, repl(SubString(str, first(r), last(r)))) | ||
|
||
function replace(str::String, pattern, repl, limit::Int) | ||
limit == 0 && return str | ||
limit < 0 && throw(DomainError()) | ||
function replace_new(str::String, pattern, repl, count::Int) | ||
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 restrict this to 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. It's what's done in other contexts too: accept 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. The problem is that once the deprecation is removed, the "API level" will be this function, and only 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. Ah I see. But this |
||
# rename to `replace` when `replace` is removed from deprecated.jl | ||
count == 0 && return str | ||
count < 0 && throw(DomainError()) | ||
n = 1 | ||
e = endof(str) | ||
i = a = start(str) | ||
|
@@ -386,26 +387,25 @@ function replace(str::String, pattern, repl, limit::Int) | |
end | ||
r = search(str,pattern,k) | ||
j, k = first(r), last(r) | ||
n == limit && break | ||
n == count && break | ||
n += 1 | ||
end | ||
write(out, SubString(str,i)) | ||
String(take!(out)) | ||
end | ||
|
||
""" | ||
replace(string::AbstractString, pat, r, [count::Integer]) | ||
replace(s::AbstractString, pat, r, [count::Integer]) | ||
|
||
Search for the given pattern `pat`, and replace each occurrence with `r`. | ||
Search for the given pattern `pat` in `s`, and replace each occurrence with `r`. | ||
If `count` is provided, replace at most `count` occurrences. | ||
As with search, the second argument may be a | ||
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. search would be good as a cross reference 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. Done. |
||
single character, a vector or a set of characters, a string, or a regular expression. If `r` | ||
is a function, each occurrence is replaced with `r(s)` where `s` is the matched substring. | ||
If `pat` is a regular expression and `r` is a `SubstitutionString`, then capture group | ||
references in `r` are replaced with the corresponding matched text. | ||
""" | ||
replace(s::AbstractString, pat, f, n::Integer=typemax(Int)) = | ||
replace(String(s), pat, f, Int(n)) | ||
replace(s::AbstractString, pat, f) = replace_new(String(s), pat, f, typemax(Int)) | ||
|
||
# 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.
Would be good to add a comment explaining that
replace_new
needs to be renamed toreplace
when removing this deprecation (and make sure tests will fail if that's not the case).