Skip to content

Commit 9998f00

Browse files
committed
Merge pull request #3 from tonyhffong/master
make width type stable, and all kwargs typed
2 parents a59a762 + cda6cc8 commit 9998f00

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/cformat.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ function addcommas( s::ASCIIString )
9797
end
9898

9999
function generate_format_string(;
100-
width=nothing,
101-
precision= -1,
102-
leftjustified=false,
103-
zeropadding=false,
104-
commas=false,
105-
signed=false,
106-
positivespace=false,
107-
alternative=false,
108-
conversion="f" #aAdecEfFiosxX
100+
width::Int=-1,
101+
precision::Int= -1,
102+
leftjustified::Bool=false,
103+
zeropadding::Bool=false,
104+
commas::Bool=false,
105+
signed::Bool=false,
106+
positivespace::Bool=false,
107+
alternative::Bool=false,
108+
conversion::ASCIIString="f" #aAdecEfFiosxX
109109
)
110110
s = "%"
111111
if commas
@@ -114,7 +114,7 @@ function generate_format_string(;
114114
if alternative && in( conversion[1], "aAeEfFoxX" )
115115
s *= "#"
116116
end
117-
if zeropadding && !leftjustified && width != nothing
117+
if zeropadding && !leftjustified && width != -1
118118
s *= "0"
119119
end
120120

@@ -124,7 +124,7 @@ function generate_format_string(;
124124
s *= " "
125125
end
126126

127-
if width != nothing
127+
if width != -1
128128
if leftjustified
129129
s *= "-" * string( width )
130130
else
@@ -138,8 +138,8 @@ function generate_format_string(;
138138
end
139139

140140
function format{T<:Real}( x::T;
141-
width=nothing,
142-
precision= -1,
141+
width::Int=-1,
142+
precision::Int= -1,
143143
leftjustified::Bool=false,
144144
zeropadding::Bool=false, # when right-justified, use 0 instead of space to fill
145145
commas::Bool=false,
@@ -149,12 +149,12 @@ function format{T<:Real}( x::T;
149149
parens::Bool=false, # use (1.00) instead of -1.00. Used in finance
150150
alternative::Bool=false, # usually for hex
151151
mixedfraction::Bool=false,
152-
mixedfractionsep="_",
153-
fractionsep="/", # num / den
152+
mixedfractionsep::String="_",
153+
fractionsep::String="/", # num / den
154154
fractionwidth::Int = 0,
155-
tryden = 0, # if 2 or higher, try to use this denominator, without losing precision
156-
suffix="", # useful for units/%
157-
autoscale=:none, # :metric, :binary or :finance
155+
tryden::Int = 0, # if 2 or higher, try to use this denominator, without losing precision
156+
suffix::String="", # useful for units/%
157+
autoscale::Symbol=:none, # :metric, :binary or :finance
158158
conversion::ASCIIString=""
159159
)
160160
checkwidth = commas
@@ -342,7 +342,7 @@ function format{T<:Real}( x::T;
342342
checkwidth = true
343343
end
344344

345-
if checkwidth && width != nothing
345+
if checkwidth && width != -1
346346
if length(s) > width
347347
s = replace( s, " ", "", length(s)-width )
348348
if length(s) > width && endswith( s, " " )

0 commit comments

Comments
 (0)