Skip to content

Commit

Permalink
Add join, escape_string, and unescape_string (JuliaLang#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb authored and dpsanders committed Feb 1, 2017
1 parent d108fe4 commit 49a7a81
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `fieldoffsets` has been deprecated in favor of `fieldoffset`[#14777](https://github.com/JuliaLang/julia/pull/14777).

* `print_escaped` is now another method of `escape_string`, `print_unescaped` a method of `unescape_string`, and `print_joined` a method of `join`. [#16603](https://github.com/JuliaLang/julia/pull/16603)

## New macros

* `@static` has been added [#16219](https://github.com/JuliaLang/julia/pull/16219).
Expand Down
13 changes: 13 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1425,4 +1425,17 @@ else
import Base.promote_eltype_op
end

if VERSION < v"0.5.0-dev+4351"
Base.join(io::IO, items) =
print_joined(io, items)
Base.join(io::IO, items, delim) =
print_joined(io, items, delim)
Base.join(io::IO, items, delim, last) =
print_joined(io, items, delim, last)
Base.unescape_string(io, s::AbstractString) =
print_unescaped(io, s)
Base.escape_string(io, str::AbstractString, esc::AbstractString) =
print_escaped(io, str, esc)
end

end # module
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1337,3 +1337,10 @@ let
end
@test norm(normalize!(v) - w, Inf) < eps()
end

# JuliaLang/julia#16603
@test sprint(join, [1, 2, 3]) == "123"
@test sprint(join, [1, 2, 3], ',') == "1,2,3"
@test sprint(join, [1, 2, 3], ", ", ", and ") == "1, 2, and 3"
@test sprint(escape_string, "xyz\n", "z") == "xy\\z\\n"
@test sprint(unescape_string, "xyz\\n") == "xyz\n"

0 comments on commit 49a7a81

Please sign in to comment.