Skip to content

Commit 188de7a

Browse files
TotalVerbstevengj
authored andcommitted
Add join, escape_string, and unescape_string (#273)
1 parent e6e10de commit 188de7a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ Currently, the `@compat` macro supports the following syntaxes:
203203

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

206+
* `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)
207+
206208
## New macros
207209

208210
* `@static` has been added [#16219](https://github.com/JuliaLang/julia/pull/16219).

src/Compat.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,4 +1425,17 @@ else
14251425
import Base.promote_eltype_op
14261426
end
14271427

1428+
if VERSION < v"0.5.0-dev+4351"
1429+
Base.join(io::IO, items) =
1430+
print_joined(io, items)
1431+
Base.join(io::IO, items, delim) =
1432+
print_joined(io, items, delim)
1433+
Base.join(io::IO, items, delim, last) =
1434+
print_joined(io, items, delim, last)
1435+
Base.unescape_string(io, s::AbstractString) =
1436+
print_unescaped(io, s)
1437+
Base.escape_string(io, str::AbstractString, esc::AbstractString) =
1438+
print_escaped(io, str, esc)
1439+
end
1440+
14281441
end # module

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,3 +1337,10 @@ let
13371337
end
13381338
@test norm(normalize!(v) - w, Inf) < eps()
13391339
end
1340+
1341+
# JuliaLang/julia#16603
1342+
@test sprint(join, [1, 2, 3]) == "123"
1343+
@test sprint(join, [1, 2, 3], ',') == "1,2,3"
1344+
@test sprint(join, [1, 2, 3], ", ", ", and ") == "1, 2, and 3"
1345+
@test sprint(escape_string, "xyz\n", "z") == "xy\\z\\n"
1346+
@test sprint(unescape_string, "xyz\\n") == "xyz\n"

0 commit comments

Comments
 (0)