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

deprecate print_escaped, print_unescaped, and print_joined #16603

Merged
merged 1 commit into from
May 27, 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
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,10 @@ end

@deprecate blas_set_num_threads BLAS.set_num_threads

@deprecate print_escaped escape_string
@deprecate print_unescaped unescape_string
@deprecate print_joined join

# During the 0.5 development cycle, do not add any deprecations below this line
# To be deprecated in 0.6

Expand Down
25 changes: 12 additions & 13 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,12 @@ Equivalent to `stat(file).mode`
filemode

"""
print_joined(io, items, delim, [last])
join(io, items, delim, [last])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing square brackets around last or not? should be consistent between here and the rst docstring at https://github.com/JuliaLang/julia/pull/16603/files#diff-5024f6efcbbb7500d181c34103c2576a

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if the signature-matching supported that, since it doesn't allow the brackets on the line below specifying which method is documented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by "the line below" do you mean the part outside the docstring? that needs to be valid julia syntax

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I mean the part outside the docstring. Is it ok for the signature to have the brackets, but the part outside not to?

Copy link
Contributor

@tkelman tkelman May 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. The brackets are just for presentation (and rst genstdlib matching), the part outside controls which method this particular docstring gets attached to, AIUI. I think we may eventually want to move from the bracket convention to strictly using Julia syntax in docstrings, but that's a decision for another day.


Print elements of `items` to `io` with `delim` between them. If `last` is specified, it is
used as the final delimiter instead of `delim`.
"""
print_joined
join(io, items, delim, last)

"""
lfact(x)
Expand Down Expand Up @@ -5013,12 +5013,12 @@ process as a worker using TCP/IP sockets for transport.
init_worker

"""
print_escaped(io, str::AbstractString, esc::AbstractString)
escape_string(io, str::AbstractString, esc::AbstractString)

General escaping of traditional C and Unicode escape sequences, plus any characters in esc
are also escaped (with a backslash).
"""
print_escaped
escape_string(io, str, esc)

"""
typejoin(T, S)
Expand Down Expand Up @@ -6669,7 +6669,7 @@ two strings. For example

`strings` can be any iterable over elements `x` which are convertible to strings via `print(io::IOBuffer, x)`.
"""
join
join(strings, delim, last)

"""
linreg(x, y) -> a, b
Expand Down Expand Up @@ -7138,11 +7138,11 @@ implemented.) Use [`vecnorm`](:func:`vecnorm`) to compute the Frobenius norm.
norm

"""
print_unescaped(io, s::AbstractString)
unescape_string(io, s::AbstractString)

General unescaping of traditional C and Unicode escape sequences. Reverse of [`print_escaped`](:func:`print_escaped`).
General unescaping of traditional C and Unicode escape sequences. Reverse of [`escape_string`](:func:`escape_string`).
"""
print_unescaped
unescape_string(io, s)

"""
digits!(array, n, [base])
Expand Down Expand Up @@ -8678,10 +8678,9 @@ A_ldiv_Bc
"""
escape_string(str::AbstractString) -> AbstractString

General escaping of traditional C and Unicode escape sequences. See
[`print_escaped`](:func:`print_escaped`) for more general escaping.
General escaping of traditional C and Unicode escape sequences.
"""
escape_string
escape_string(str)

"""
significand(x)
Expand Down Expand Up @@ -9187,9 +9186,9 @@ map!(f,destination,collection...)
unescape_string(s::AbstractString) -> AbstractString

General unescaping of traditional C and Unicode escape sequences. Reverse of
[`escape_string`](:func:`escape_string`). See also [`print_unescaped`](:func:`print_unescaped`).
[`escape_string`](:func:`escape_string`). See also [`unescape_string`](:func:`unescape_string`).
"""
unescape_string
unescape_string(s)

"""
redirect_stdout()
Expand Down
2 changes: 1 addition & 1 deletion base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function print_joined_cols(io::IO, ss, delim = "", last = delim; cols = displays
total += length(ss[i])
total + max(i-2,0)*length(delim) + (i>1?1:0)*length(last) > cols && (i-=1; break)
end
print_joined(io, ss[1:i], delim, last)
join(io, ss[1:i], delim, last)
end

print_joined_cols(args...; cols = displaysize(STDOUT)[2]) = print_joined_cols(STDOUT, args...; cols=cols)
Expand Down
3 changes: 0 additions & 3 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,7 @@ export
oct,
prevind,
print,
print_escaped,
print_joined,
print_shortest,
print_unescaped,
print_with_color,
println,
randstring,
Expand Down
10 changes: 5 additions & 5 deletions base/markdown/GitHub/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ function plain(io::IO, md::Table)
padcells!(cells, md.align, len = length, min = 3)
for i = 1:length(cells) # fixme (iter): can we make indexing more general here?
print(io, "| ")
print_joined(io, cells[i], " | ")
join(io, cells[i], " | ")
println(io, " |")
if i == 1
print(io, "|")
print_joined(io, [_dash(length(cells[i][j]), md.align[j]) for j = 1:length(cells[1])], "|")
join(io, [_dash(length(cells[i][j]), md.align[j]) for j = 1:length(cells[1])], "|")
println(io, "|")
end
end
Expand All @@ -124,7 +124,7 @@ function rst(io::IO, md::Table)
double = ["="^length(c) for c in cells[1]]
function print_row(row, row_sep, col_sep)
print(io, col_sep, row_sep)
print_joined(io, row, string(row_sep, col_sep, row_sep))
join(io, row, string(row_sep, col_sep, row_sep))
println(io, row_sep, col_sep)
end
print_row(single, '-', '+')
Expand All @@ -139,10 +139,10 @@ function term(io::IO, md::Table, columns)
cells = mapmap(terminline, md.rows)
padcells!(cells, md.align, len = ansi_length)
for i = 1:length(cells)
print_joined(io, cells[i], " ")
join(io, cells[i], " ")
println(io)
if i == 1
print_joined(io, ["–"^ansi_length(cells[i][j]) for j = 1:length(cells[1])], " ")
join(io, ["–"^ansi_length(cells[i][j]) for j = 1:length(cells[1])], " ")
println(io)
end
end
Expand Down
8 changes: 4 additions & 4 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ function show(io::IO, m::Method; kwtype::Nullable{DataType}=Nullable{DataType}()
show_delim_array(io, tv, '{', ',', '}', false)
end
print(io, "(")
print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2] for d in decls[2:end]],
join(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2] for d in decls[2:end]],
", ", ", ")
if !isnull(kwtype)
kwargs = kwarg_decl(m.sig, get(kwtype))
if !isempty(kwargs)
print(io, "; ")
print_joined(io, kwargs, ", ", ", ")
join(io, kwargs, ", ", ", ")
end
end
print(io, ")")
Expand Down Expand Up @@ -227,13 +227,13 @@ function writemime(io::IO, ::MIME"text/html", m::Method; kwtype::Nullable{DataTy
print(io,"</i>")
end
print(io, "(")
print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::<b>"*d[2]*"</b>"
join(io, [isempty(d[2]) ? d[1] : d[1]*"::<b>"*d[2]*"</b>"
for d in decls[2:end]], ", ", ", ")
if !isnull(kwtype)
kwargs = kwarg_decl(m.sig, get(kwtype))
if !isempty(kwargs)
print(io, "; <i>")
print_joined(io, kwargs, ", ", ", ")
join(io, kwargs, ", ", ", ")
print(io, "</i>")
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function VersionSet(versions::Vector{VersionNumber})
end
VersionSet(versions::VersionNumber...) = VersionSet(VersionNumber[versions...])

show(io::IO, s::VersionSet) = print_joined(io, s.intervals, " ∪ ")
show(io::IO, s::VersionSet) = join(io, s.intervals, " ∪ ")
isempty(s::VersionSet) = all(i->isempty(i), s.intervals)
in(v::VersionNumber, s::VersionSet) = any(i->in(v,i), s.intervals)
function intersect(A::VersionSet, B::VersionSet)
Expand Down
12 changes: 6 additions & 6 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ precompile(Base.print, (IOBuffer, String))
precompile(Base.print, (IOBuffer, VersionNumber))
precompile(Base.print, (IOStream, Int32))
precompile(Base.print, (IOStream,String))
precompile(Base.print_joined, (IOBuffer, Tuple{String}, Char))
precompile(Base.print_joined, (IOBuffer, Tuple{Int}, Char))
precompile(Base.print_joined, (IOBuffer, Array{String,1}, Char))
precompile(Base.print_joined, (IOBuffer, Array{AbstractString,1}, String))
precompile(Base.print_joined, (IOBuffer, Array{SubString{String}, 1}, String))
precompile(Base.join, (IOBuffer, Tuple{String}, Char))
precompile(Base.join, (IOBuffer, Tuple{Int}, Char))
precompile(Base.join, (IOBuffer, Array{String,1}, Char))
precompile(Base.join, (IOBuffer, Array{AbstractString,1}, String))
precompile(Base.join, (IOBuffer, Array{SubString{String}, 1}, String))
precompile(Base.println, (Base.TTY,))
precompile(Base.println, (Base.Terminals.TTYTerminal,))
precompile(Base.promote_type, (Type{Base.LineEdit.Prompt}, Type{Base.LineEdit.HistoryPrompt{Base.REPL.REPLHistoryProvider}}))
Expand Down Expand Up @@ -452,7 +452,7 @@ precompile(==, (Base.RemoteChannel, WeakRef))
precompile(==, (Base.RemoteChannel, Base.RemoteChannel))
precompile(Base.send_del_client, (Base.RemoteChannel,))
precompile(!=, (Base.SubString{String}, String))
precompile(Base.print_joined, (Base.IOBuffer, Array{Base.SubString{String}, 1}, String))
precompile(Base.join, (Base.IOBuffer, Array{Base.SubString{String}, 1}, String))
precompile(Base.joinpath, (String, String, String, String))
precompile(Base.string, (String, String, Char))
precompile(Base.string, (String, String, Int))
Expand Down
2 changes: 1 addition & 1 deletion base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function showerror(io::IO, ex::BoundsError)
if isa(ex.i, Range)
print(io, ex.i)
else
print_joined(io, ex.i, ',')
join(io, ex.i, ',')
end
print(io, ']')
end
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
end
print(io, ")")
else
print_escaped(io, x, "\"\$")
escape_string(io, x, "\"\$")
end
end
print(io, '"')
Expand Down
18 changes: 9 additions & 9 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ IOBuffer(str::String) = IOBuffer(str.data)
IOBuffer(s::SubString{String}) = IOBuffer(sub(s.string.data, s.offset + 1 : s.offset + sizeof(s)))

# join is implemented using IO
function print_joined(io, strings, delim, last)
function join(io::IO, strings, delim, last)
i = start(strings)
if done(strings,i)
return
Expand All @@ -112,7 +112,7 @@ function print_joined(io, strings, delim, last)
end
end

function print_joined(io, strings, delim)
function join(io::IO, strings, delim)
i = start(strings)
is_done = done(strings,i)
while !is_done
Expand All @@ -124,16 +124,16 @@ function print_joined(io, strings, delim)
end
end
end
print_joined(io, strings) = print_joined(io, strings, "")
join(io::IO, strings) = join(io, strings, "")

join(args...) = sprint(print_joined, args...)
join(args...) = sprint(join, args...)

## string escaping & unescaping ##

escape_nul(s::AbstractString, i::Int) =
!done(s,i) && '0' <= next(s,i)[1] <= '7' ? "\\x00" : "\\0"

function print_escaped(io, s::AbstractString, esc::AbstractString)
function escape_string(io, s::AbstractString, esc::AbstractString)
i = start(s)
while !done(s,i)
c, j = next(s,i)
Expand All @@ -150,10 +150,10 @@ function print_escaped(io, s::AbstractString, esc::AbstractString)
end
end

escape_string(s::AbstractString) = sprint(endof(s), print_escaped, s, "\"")
escape_string(s::AbstractString) = sprint(endof(s), escape_string, s, "\"")
function print_quoted(io, s::AbstractString)
print(io, '"')
print_escaped(io, s, "\"\$") #"# work around syntax highlighting problem
escape_string(io, s, "\"\$") #"# work around syntax highlighting problem
print(io, '"')
end

Expand All @@ -178,7 +178,7 @@ unescape_chars(s::AbstractString, esc::AbstractString) =

# general unescaping of traditional C and Unicode escape sequences

function print_unescaped(io, s::AbstractString)
function unescape_string(io, s::AbstractString)
i = start(s)
while !done(s,i)
c, i = next(s,i)
Expand Down Expand Up @@ -231,7 +231,7 @@ function print_unescaped(io, s::AbstractString)
end
end

unescape_string(s::AbstractString) = sprint(endof(s), print_unescaped, s)
unescape_string(s::AbstractString) = sprint(endof(s), unescape_string, s)

macro b_str(s); :($(unescape_string(s)).data); end

Expand Down
4 changes: 2 additions & 2 deletions base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ function print(io::IO, v::VersionNumber)
print(io, v.patch)
if !isempty(v.prerelease)
print(io, '-')
print_joined(io, v.prerelease,'.')
join(io, v.prerelease,'.')
end
if !isempty(v.build)
print(io, '+')
print_joined(io, v.build,'.')
join(io, v.build,'.')
end
end
show(io::IO, v::VersionNumber) = print(io, "v\"", v, "\"")
Expand Down
8 changes: 4 additions & 4 deletions doc/stdlib/io-network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,19 @@ General I/O

Read a value written by ``serialize``\ . ``deserialize`` assumes the binary data read from ``stream`` is correct and has been serialized by a compatible implementation of ``serialize``\ . It has been designed with simplicity and performance as a goal and does not validate the data read. Malformed data can result in process termination. The caller has to ensure the integrity and correctness of data read from ``stream``\ .

.. function:: print_escaped(io, str::AbstractString, esc::AbstractString)
.. function:: escape_string(io, str::AbstractString, esc::AbstractString)

.. Docstring generated from Julia source

General escaping of traditional C and Unicode escape sequences, plus any characters in esc are also escaped (with a backslash).

.. function:: print_unescaped(io, s::AbstractString)
.. function:: unescape_string(io, s::AbstractString)

.. Docstring generated from Julia source

General unescaping of traditional C and Unicode escape sequences. Reverse of :func:`print_escaped`\ .
General unescaping of traditional C and Unicode escape sequences. Reverse of :func:`escape_string`\ .

.. function:: print_joined(io, items, delim, [last])
.. function:: join(io, items, delim, [last])

.. Docstring generated from Julia source

Expand Down
4 changes: 2 additions & 2 deletions doc/stdlib/strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,13 @@

.. Docstring generated from Julia source

General escaping of traditional C and Unicode escape sequences. See :func:`print_escaped` for more general escaping.
General escaping of traditional C and Unicode escape sequences.

.. function:: unescape_string(s::AbstractString) -> AbstractString

.. Docstring generated from Julia source

General unescaping of traditional C and Unicode escape sequences. Reverse of :func:`escape_string`\ . See also :func:`print_unescaped`\ .
General unescaping of traditional C and Unicode escape sequences. Reverse of :func:`escape_string`\ . See also :func:`unescape_string`\ .

.. function:: utf16(s)

Expand Down
8 changes: 4 additions & 4 deletions test/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ Base.next(jt::i9178, n) = (jt.nnext += 1 ; ("$(jt.nnext),$(jt.ndone)", n+1))
arr = ["a","b","c"]
@test "[$(join(arr, " - "))]" == "[a - b - c]"

# print_joined with empty input
# join with empty input
myio = IOBuffer()
print_joined(myio, "", "", 1)
join(myio, "", "", 1)
@test isempty(takebuf_array(myio))

# unescape_chars
@test Base.unescape_chars("\\t","t") == "t"
@test_throws ArgumentError print_unescaped(IOBuffer(), string('\\',"xZ"))
@test_throws ArgumentError print_unescaped(IOBuffer(), string('\\',"777"))
@test_throws ArgumentError unescape_string(IOBuffer(), string('\\',"xZ"))
@test_throws ArgumentError unescape_string(IOBuffer(), string('\\',"777"))

# 11659
# The indentation code was not correctly counting tab stops
Expand Down