Skip to content

Commit

Permalink
fix docstring for alignment (#28409)
Browse files Browse the repository at this point in the history
  • Loading branch information
goropikari authored Apr 30, 2020
1 parent 1475273 commit 5819223
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion base/arrayshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ end
const undef_ref_alignment = (3,3)

"""
`alignment(X, rows, cols, cols_if_complete, cols_otherwise, sep)` returns the
`alignment(io, X, rows, cols, cols_if_complete, cols_otherwise, sep)` returns the
alignment for specified parts of array `X`, returning the (left,right) info.
It will look in X's `rows`, `cols` (both lists of indices)
and figure out what's needed to be fully aligned, for example looking all
Expand Down
8 changes: 4 additions & 4 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2052,20 +2052,20 @@ end


"""
`alignment(X)` returns a tuple (left,right) showing how many characters are
`alignment(io, X)` returns a tuple (left,right) showing how many characters are
needed on either side of an alignment feature such as a decimal point.
"""
alignment(io::IO, x::Any) = (0, length(sprint(show, x, context=io, sizehint=0)))
alignment(io::IO, x::Number) = (length(sprint(show, x, context=io, sizehint=0)), 0)
"`alignment(42)` yields (2,0)"
"`alignment(stdout, 42)` yields (2, 0)"
alignment(io::IO, x::Integer) = (length(sprint(show, x, context=io, sizehint=0)), 0)
"`alignment(4.23)` yields (1,3) for `4` and `.23`"
"`alignment(stdout, 4.23)` yields (1, 3) for `4` and `.23`"
function alignment(io::IO, x::Real)
m = match(r"^(.*?)((?:[\.eEfF].*)?)$", sprint(show, x, context=io, sizehint=0))
m === nothing ? (length(sprint(show, x, context=io, sizehint=0)), 0) :
(length(m.captures[1]), length(m.captures[2]))
end
"`alignment(1 + 10im)` yields (3,5) for `1 +` and `_10im` (plus sign on left, space on right)"
"`alignment(stdout, 1 + 10im)` yields (3, 5) for `1 +` and `_10im` (plus sign on left, space on right)"
function alignment(io::IO, x::Complex)
m = match(r"^(.*[^ef][\+\-])(.*)$", sprint(show, x, context=io, sizehint=0))
m === nothing ? (length(sprint(show, x, context=io, sizehint=0)), 0) :
Expand Down

0 comments on commit 5819223

Please sign in to comment.