Skip to content

Commit

Permalink
removed base methods on base types in show.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
dysonance committed Apr 3, 2017
1 parent e1c7227 commit 6157bad
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ const DECIMALS = 4 # the maximum number of decimals to show
const PADDING = 2 # number of spaces minimum between fields
const SHOWINT = false # whether to format integer columns without decimals

import Base: isinteger, strwidth, rpad, summary
rpad(s::Symbol, n::Int)::String = rpad(string(s), n)
isinteger(::String)::Bool = false
isinteger(::Symbol)::Bool = false
isinteger(::Char)::Bool = false
isinteger(::Date)::Bool = false
isinteger(::DateTime)::Bool = false
isinteger(::Function)::Bool = false
strwidth(s::Symbol)::Int = strwidth(string(s))
strwidth(n::Number)::Int = strwidth(string(n))
strwidth(f::Function)::Int = strwidth(string(f))
strwidth(b::Bool)::Int = b ? 4 : 5
strwidth(c::Char)::Int = 1
# rpad(s::Symbol, n::Int)::String = rpad(string(s), n)
# isinteger(::String)::Bool = false
# isinteger(::Symbol)::Bool = false
# isinteger(::Char)::Bool = false
# isinteger(::Date)::Bool = false
# isinteger(::DateTime)::Bool = false
# isinteger(::Function)::Bool = false
# strwidth(s::Symbol)::Int = strwidth(string(s))
# strwidth(n::Number)::Int = strwidth(string(n))
# strwidth(f::Function)::Int = strwidth(string(f))
# strwidth(b::Bool)::Int = b ? 4 : 5
# strwidth(c::Char)::Int = 1

str_width(s::AbstractString)::Int = strwidth(string(s))
str_width(s::Symbol)::Int = strwidth(string(s))
str_width(n::Number)::Int = strwidth(string(s))
str_width(f::Function)::Int = strwidth(string(s))
str_width(b::Bool)::Int = b ? 4 : 5
str_width(c::Char)::Int = 1

function print_summary{V,T}(io::IO, x::TS{V,T})::Int
if isempty(x)
Expand All @@ -39,16 +45,16 @@ function getshowrows{V,T}(io::IO, x::TS{V,T})::Tuple{Vector{Int},Vector{Int}}
end

function getwidths{V,T}(io::IO, x::TS{V,T})::Vector{Int}
widths = [T==Date?10:19; strwidth.(x.fields)]
widths = [T==Date?10:19; str_width.(x.fields)]
toprows, botrows = getshowrows(io, x)
vals = [x.values[toprows,:]; x.values[botrows,:]]
if V <: Number
@inbounds for j in 1:size(x,2)
widths[j+1] = max(widths[j+1], maximum(strwidth.(round.(vals[:,j],DECIMALS))))
widths[j+1] = max(widths[j+1], maximum(str_width.(round.(vals[:,j],DECIMALS))))
end
else
@inbounds for j in 1:size(x,2)
widths[j+1] = max(widths[j+1], maximum(strwidth.(vals[:,j])))
widths[j+1] = max(widths[j+1], maximum(str_width.(vals[:,j])))
end
end
return widths
Expand All @@ -62,7 +68,7 @@ function getnegs(io::IO, x::TS)::Vector{Bool}
return [hasnegs(x.values[:,j]) for j in 1:size(x,2)]
end

print_header(x::TS, widths::Vector{Int}, negs::Vector{Bool})::String = prod(rpad.(["Index"; lpad.(string.(x.fields), strwidth.(x.fields).+negs)], widths))
print_header(x::TS, widths::Vector{Int}, negs::Vector{Bool})::String = prod(rpad.(["Index"; lpad.(string.(x.fields), str_width.(x.fields).+negs)], widths))

function print_row{V,T}(x::TS{V,T}, row::Int, widths::Vector{Int}, negs::Vector{Bool})::String
if V <: Number
Expand Down

0 comments on commit 6157bad

Please sign in to comment.