Skip to content

Commit 6e17cb2

Browse files
committed
deprecate replace(s::String, pat, r, n) to replace(s, pat=>r, count=n)
1 parent 6c94bd8 commit 6e17cb2

File tree

29 files changed

+160
-157
lines changed

29 files changed

+160
-157
lines changed

NEWS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,9 @@ Deprecated or removed
632632

633633
* `?` can no longer be used as an identifier name ([#22712])
634634

635-
* The method `replace(s::AbstractString, pat, r, count)` with `count <= 0` is deprecated
636-
in favor of `replace(s::AbstractString, pat, r, typemax(Int))` ([#22325]).
635+
* The method `replace(s::AbstractString, pat, r, [count])` is deprecated
636+
in favor of `replace(s::AbstractString, pat => r; [count])` ([#25165]).
637+
Moreover, `count` cannot be negative anymore (use `typemax(Int)` instead ([#22325]).
637638

638639
* `read(io, type, dims)` is deprecated to `read!(io, Array{type}(dims))` ([#21450]).
639640

base/deprecated.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,14 +1346,19 @@ end
13461346
function replace(s::AbstractString, pat, f, n::Integer)
13471347
if n <= 0
13481348
depwarn(string("`replace(s, pat, r, count)` with `count <= 0` is deprecated, use ",
1349-
"`replace(s, pat, r, typemax(Int))` or `replace(s, pat, r)` instead"),
1349+
"`replace(s, pat=>r, count=typemax(Int))` or `replace(s, pat=>r)` instead"),
13501350
:replace)
1351-
replace(s, pat, f)
1351+
replace(s, pat=>f)
13521352
else
1353-
replace_new(String(s), pat, f, n)
1353+
depwarn(string("`replace(s, pat, r, count)` is deprecated, use ",
1354+
"`replace(s, pat=>r, count=count)`"),
1355+
:replace)
1356+
replace(String(s), pat=>f, count=n)
13541357
end
13551358
end
13561359

1360+
@deprecate replace(s::AbstractString, pat, f) replace(s, pat=>f)
1361+
13571362
# PR #22475
13581363
@deprecate ntuple(f, ::Type{Val{N}}) where {N} ntuple(f, Val(N))
13591364
@deprecate fill_to_length(t, val, ::Type{Val{N}}) where {N} fill_to_length(t, val, Val(N)) false

base/libgit2/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Standardise the path string `path` to use POSIX separators.
8383
"""
8484
function posixpath end
8585
if Sys.iswindows()
86-
posixpath(path) = replace(path,'\\','/')
86+
posixpath(path) = replace(path,'\\' => '/')
8787
elseif Sys.isunix()
8888
posixpath(path) = path
8989
end

base/markdown/GitHub/table.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function parserow(stream::IO)
1111
row = split(line, r"(?<!\\)\|")
1212
length(row) == 1 && return
1313
isempty(row[1]) && popfirst!(row)
14-
map!(x -> strip(replace(x, "\\|", "|")), row, row)
14+
map!(x -> strip(replace(x, "\\|" => "|")), row, row)
1515
isempty(row[end]) && pop!(row)
1616
return row
1717
end
@@ -104,7 +104,7 @@ _dash(width, align) =
104104

105105
function plain(io::IO, md::Table)
106106
cells = mapmap(md.rows) do each
107-
replace(plaininline(each), "|", "\\|")
107+
replace(plaininline(each), "|" => "\\|")
108108
end
109109
padcells!(cells, md.align, len = length, min = 3)
110110
for i = axes(cells,1)

base/markdown/render/html.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ for ch in "'`!\$%()=+{}[]"
3131
end
3232

3333
function htmlesc(io::IO, s::AbstractString)
34-
# s1 = replace(s, r"&(?!(\w+|\#\d+);)", "&amp;")
34+
# s1 = replace(s, r"&(?!(\w+|\#\d+);)" => "&amp;")
3535
for ch in s
3636
print(io, get(_htmlescape_chars, ch, ch))
3737
end

base/markdown/render/rst.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ end
124124

125125
rstinline(io::IO, f::Footnote) = print(io, "[", f.id, "]_")
126126

127-
rstescape(s) = replace(s, "\\", "\\\\")
127+
rstescape(s) = replace(s, "\\" => "\\\\")
128128

129129
rstinline(io::IO, s::AbstractString) = print(io, rstescape(s))
130130

base/markdown/render/terminal/formatting.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ end
5151
# Wrapping
5252

5353
function ansi_length(s)
54-
replace(s, r"\e\[[0-9]+m", "") |> length
54+
replace(s, r"\e\[[0-9]+m" => "") |> length
5555
end
5656

5757
words(s) = split(s, " ")

base/markdown/render/terminal/render.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function terminline(io::IO, content::Vector)
114114
end
115115

116116
function terminline(io::IO, md::AbstractString)
117-
print(io, replace(md, r"[\s\t\n]+", " "))
117+
print(io, replace(md, r"[\s\t\n]+" => " "))
118118
end
119119

120120
function terminline(io::IO, md::Bold)

base/methodshow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function url(m::Method)
203203
file = string(m.file)
204204
line = m.line
205205
line <= 0 || ismatch(r"In\[[0-9]+\]", file) && return ""
206-
Sys.iswindows() && (file = replace(file, '\\', '/'))
206+
Sys.iswindows() && (file = replace(file, '\\' => '/'))
207207
if inbase(M)
208208
if isempty(Base.GIT_VERSION_INFO.commit)
209209
# this url will only work if we're on a tagged release

base/pkg/reqs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Requirement <: Line
1919
system::Vector{AbstractString}
2020

2121
function Requirement(content::AbstractString)
22-
fields = split(replace(content, r"#.*$", ""))
22+
fields = split(replace(content, r"#.*$" => ""))
2323
system = AbstractString[]
2424
while !isempty(fields) && fields[1][1] == '@'
2525
push!(system,popfirst!(fields)[2:end])

0 commit comments

Comments
 (0)