Skip to content

Commit

Permalink
Add pairs method for replace
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jan 3, 2018
1 parent f7e65c7 commit e450796
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Some{T}` wraps `T` to signify that a result of `T<:Void` is expected ([#23642]).

* `replace` accepts a pair of pattern and replacement, with the number of replacements as
a keyword argument ([#25165]).

## Renaming


Expand Down Expand Up @@ -423,4 +426,5 @@ includes this fix. Find the minimum version from there.
[#25057]: https://github.com/JuliaLang/julia/issues/25057
[#25102]: https://github.com/JuliaLang/julia/issues/25102
[#25162]: https://github.com/JuliaLang/julia/issues/25162
[#25165]: https://github.com/JuliaLang/julia/issues/25165
[#25168]: https://github.com/JuliaLang/julia/issues/25168
5 changes: 5 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,11 @@ end
export invpermute!
end

@static if VERSION < v"0.7.0-DEV.3172"
Base.replace(s::AbstractString, pat_rep::Pair; count::Integer=typemax(Int)) =
replace(s, first(pat_rep), last(pat_rep), count)
end

include("deprecated.jl")

end # module Compat
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,10 @@ end
# 0.7.0-DEV.3173
@test invpermute!(permute!([1, 2], 2:-1:1), 2:-1:1) == [1, 2]

# 0.7.0-DEV.3172
@test replace("abcb", "b"=>"c") == "accc"
@test replace("abcb", "b"=>"c", count=1) == "accb"

if VERSION < v"0.6.0"
include("deprecated.jl")
end
Expand Down

0 comments on commit e450796

Please sign in to comment.