Skip to content
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

Add join, escape_string, and unescape_string #273

Merged
merged 1 commit into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"