From 5b1e46c1f57b326ddc126f7d34ce44204c137251 Mon Sep 17 00:00:00 2001 From: ScottPJones Date: Mon, 30 Jan 2017 14:21:06 -0500 Subject: [PATCH] Fix up v0.6 checking --- src/cformat.jl | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/src/cformat.jl b/src/cformat.jl index 91d685b..de88eb5 100644 --- a/src/cformat.jl +++ b/src/cformat.jl @@ -1,9 +1,9 @@ formatters = Dict{ ASCIIStr, Function }() -if VERSION >= v"0.5.0" - cfmt( fmt::ASCIIStr, x ) = eval(Expr(:call, generate_formatter( fmt ), x)) -else +@static if VERSION < v"0.6-" cfmt( fmt::ASCIIStr, x ) = (generate_formatter( fmt ))(x) +else + cfmt( fmt::ASCIIStr, x ) = eval(Expr(:call, generate_formatter( fmt ), x)) end function checkfmt(fmt) @@ -254,17 +254,11 @@ function format{T<:Real}( x::T; den = tryden end fs = string( num, fractionsep, den) - if length(fs) < fractionwidth - fs = string(repeat( "0", fractionwidth - length(fs) ), fs) - end - s = rstrip(s) - if actualx != 0 - s = string(rstrip(s), mixedfractionsep, fs) - elseif !nonneg - s = string('-', fs) - else - s = fs - end + length(fs) < fractionwidth && + (fs = string(repeat( "0", fractionwidth - length(fs) ), fs)) + s = (actualx != 0 + ? string(rstrip(s), mixedfractionsep, fs) + : (nonneg ? fs : string('-', fs))) checkwidth = true elseif !mixedfraction s = replace( s, "//", fractionsep ) @@ -272,17 +266,9 @@ function format{T<:Real}( x::T; end elseif stripzeros && in( actualconv[1], "fFeEs" ) dpos = findfirst( s, '.') - if in( actualconv[1], "eEs" ) - if in( actualconv[1], "es" ) - epos = findfirst( s, 'e' ) - else - epos = findfirst( s, 'E' ) - end - if epos == 0 - rpos = length( s ) - else - rpos = epos-1 - end + if actualconv[1] in "eEs" + epos = findfirst(s, actualconv[1] == 'E' ? 'E' : 'e') + rpos = epos == 0 ? length( s ) : epos-1 else rpos = length(s) end @@ -311,12 +297,7 @@ function format{T<:Real}( x::T; if parens && !in( actualconv[1], "xX" ) # if zero or positive, we still need 1 white space on the right - if nonneg - s = string(' ', strip(s), ' ') - else - s = string('(', strip(s), ')') - end - + s = nonneg ? string(' ', strip(s), ' ') : string('(', strip(s), ')') checkwidth = true end