Skip to content

Commit d8b4bd1

Browse files
committed
Merge pull request #4 from Keno/pull-request/bbff9efd
Fix deprecation/whitespace warnings
2 parents 9998f00 + bbff9ef commit d8b4bd1

File tree

6 files changed

+33
-31
lines changed

6 files changed

+33
-31
lines changed

src/Formatting.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Formatting
77
printfmt, printfmtln, fmt, format,
88
sprintf1, generate_formatter
99

10+
using Compat
1011

1112
include("cformat.jl" )
1213
include("fmtspec.jl")

src/cformat.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ function sprintf1( fmt::ASCIIString, x )
66
f( x )
77
end
88

9+
if VERSION < v"0.4-"
10+
const base64encode = base64
11+
end
12+
913
function generate_formatter( fmt::ASCIIString )
1014
global formatters
1115
if haskey( formatters, fmt )
1216
return formatters[fmt]
1317
end
14-
func = symbol( "sprintf_" * replace( base64( fmt ), "=", "!" ) )
18+
func = symbol( "sprintf_" * replace( base64encode( fmt ), "=", "!" ) )
1519

1620
if !contains( fmt, "'" )
1721
test = Base.Printf.parse( fmt )
@@ -245,7 +249,7 @@ function format{T<:Real}( x::T;
245249
fractional = 0
246250
if T <: Rational && mixedfraction
247251
actualconv = "d"
248-
actualx = int( trunc( x ) )
252+
actualx = trunc( Int, x )
249253
fractional = abs(x) - abs(actualx)
250254
else
251255
if parens && !in( actualconv[1], "xX" )

src/fmtcore.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ _ipre(::Union(_Hex, _HEX)) = "0x"
5757
_ipre(::_Oct) = "0o"
5858
_ipre(::_Bin) = "0b"
5959

60-
_digitchar(x::Integer, ::_Bin) = char(x == 0 ? '0' : '1')
61-
_digitchar(x::Integer, ::_Dec) = char('0' + x)
62-
_digitchar(x::Integer, ::_Oct) = char('0' + x)
63-
_digitchar(x::Integer, ::_Hex) = char(x < 10 ? '0' + x : 'a' + (x - 10))
64-
_digitchar(x::Integer, ::_HEX) = char(x < 10 ? '0' + x : 'A' + (x - 10))
60+
_digitchar(x::Integer, ::_Bin) = @compat Char(x == 0 ? '0' : '1')
61+
_digitchar(x::Integer, ::_Dec) = @compat Char('0' + x)
62+
_digitchar(x::Integer, ::_Oct) = @compat Char('0' + x)
63+
_digitchar(x::Integer, ::_Hex) = @compat Char(x < 10 ? '0' + x : 'a' + (x - 10))
64+
_digitchar(x::Integer, ::_HEX) = @compat Char(x < 10 ? '0' + x : 'A' + (x - 10))
6565

6666
_signchar(x::Number, s::Char) = x < 0 ? '-' :
6767
s == '+' ? '+' :
@@ -158,7 +158,7 @@ function _pfmt_float(out::IO, sch::Char, zs::Integer, intv::Real, decv::Real, pr
158158
write(out, '.')
159159
# print decimal part
160160
if prec > 0
161-
idecv = iround(decv * exp10(prec))
161+
idecv = round(Integer, decv * exp10(prec))
162162
nd = _ndigits(idecv, _Dec())
163163
if nd < prec
164164
_repwrite(out, '0', prec - nd)
@@ -171,14 +171,14 @@ function _pfmt_f(out::IO, fs::FormatSpec, x::FloatingPoint)
171171
# separate sign, integer, and decimal part
172172
ax = abs(x)
173173
sch = _signchar(x, fs.sign)
174-
intv = itrunc(ax)
174+
intv = trunc(Integer, ax)
175175
decv = ax - intv
176176

177177
# calculate length
178178
xlen = _ndigits(intv, _Dec()) + 1 + fs.prec
179179
if sch != '\0'
180180
xlen += 1
181-
end
181+
end
182182

183183
# print
184184
wid = fs.width
@@ -199,7 +199,7 @@ function _pfmt_f(out::IO, fs::FormatSpec, x::FloatingPoint)
199199
end
200200

201201
function _pfmt_floate(out::IO, sch::Char, zs::Integer, u::Real, prec::Int, e::Int, ec::Char)
202-
intv = itrunc(u)
202+
intv = trunc(Integer,u)
203203
decv = u - intv
204204
_pfmt_float(out, sch, zs, intv, decv, prec)
205205
write(out, ec)
@@ -210,8 +210,8 @@ function _pfmt_floate(out::IO, sch::Char, zs::Integer, u::Real, prec::Int, e::In
210210
e = -e
211211
end
212212
(e1, e2) = divrem(e, 10)
213-
write(out, char('0' + e1))
214-
write(out, char('0' + e2))
213+
write(out, @compat Char('0' + e1))
214+
write(out, @compat Char('0' + e2))
215215
end
216216

217217

@@ -223,7 +223,7 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::FloatingPoint)
223223
e = 0
224224
u = zero(x)
225225
else
226-
e = ifloor(log10(ax)) # exponent
226+
e = floor(Integer,log10(ax)) # exponent
227227
u = ax / exp10(e) # significand
228228
end
229229

src/fmtspec.jl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
## FormatSpec type
1919

20-
const _numtypchars = Set('b', 'd', 'e', 'E', 'f', 'F', 'g', 'G', 'n', 'o', 'x', 'X')
20+
const _numtypchars = Set(['b', 'd', 'e', 'E', 'f', 'F', 'g', 'G', 'n', 'o', 'x', 'X'])
2121

22-
_tycls(c::Char) =
22+
_tycls(c::Char) =
2323
(c == 'd' || c == 'n' || c == 'b' || c == 'o' || c == 'x') ? 'i' :
2424
(c == 'e' || c == 'f' || c == 'g') ? 'f' :
2525
(c == 'c') ? 'c' :
@@ -29,7 +29,7 @@ _tycls(c::Char) =
2929
immutable FormatSpec
3030
cls::Char # category: 'i' | 'f' | 'c' | 's'
3131
typ::Char
32-
fill::Char
32+
fill::Char
3333
align::Char
3434
sign::Char
3535
width::Int
@@ -121,10 +121,10 @@ function FormatSpec(s::String)
121121
if a4[1] == '0'
122122
_zpad = true
123123
if length(a4) > 1
124-
_width = int(a4[2:end])
124+
_width = parseint(Int,a4[2:end])
125125
end
126126
else
127-
_width = int(a4)
127+
_width = parseint(Int,a4)
128128
end
129129
end
130130

@@ -135,7 +135,7 @@ function FormatSpec(s::String)
135135

136136
# a6 [.prec]
137137
if a6 != nothing
138-
_prec = int(a6[2:end])
138+
_prec = parseint(Int,a6[2:end])
139139
end
140140

141141
# a7: [type]
@@ -145,7 +145,7 @@ function FormatSpec(s::String)
145145
end
146146

147147
return FormatSpec(_typ;
148-
fill=_fill,
148+
fill=_fill,
149149
align=_align,
150150
sign=_sign,
151151
width=_width,
@@ -172,12 +172,12 @@ function printfmt(io::IO, fs::FormatSpec, x)
172172
cls = fs.cls
173173
ty = fs.typ
174174
if cls == 'i'
175-
ix = integer(x)
175+
ix = @compat Integer(x)
176176
ty == 'd' || ty == 'n' ? _pfmt_i(io, fs, ix, _Dec()) :
177177
ty == 'x' ? _pfmt_i(io, fs, ix, _Hex()) :
178178
ty == 'X' ? _pfmt_i(io, fs, ix, _HEX()) :
179179
ty == 'o' ? _pfmt_i(io, fs, ix, _Oct()) :
180-
_pfmt_i(io, fs, ix, _Bin())
180+
_pfmt_i(io, fs, ix, _Bin())
181181
elseif cls == 'f'
182182
fx = float(x)
183183
if isfinite(fx)
@@ -190,14 +190,11 @@ function printfmt(io::IO, fs::FormatSpec, x)
190190
elseif cls == 's'
191191
_pfmt_s(io, fs, _srepr(x))
192192
else # cls == 'c'
193-
_pfmt_s(io, fs, char(x))
193+
_pfmt_s(io, fs, @compat Char(x))
194194
end
195195
end
196196

197197
printfmt(fs::FormatSpec, x) = printfmt(STDOUT, fs, x)
198198

199199
fmt(fs::FormatSpec, x) = (buf = IOBuffer(); printfmt(buf, fs, x); bytestring(buf))
200200
fmt(spec::String, x) = fmt(FormatSpec(spec), x)
201-
202-
203-

src/formatexpr.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ function make_argspec(s::String, pos::Int)
2828
if !isempty(s)
2929
ifil = searchindex(s, "|>")
3030
if ifil == 0
31-
iarg = int(s)
31+
iarg = parseint(Int,s)
3232
else
33-
iarg = ifil > 1 ? int(s[1:ifil-1]) : -1
33+
iarg = ifil > 1 ? parseint(Int,s[1:ifil-1]) : -1
3434
hasfil = true
3535
ff = eval(symbol(s[ifil+2:end]))
36-
end
36+
end
3737
end
3838

3939
if pos > 0

test/cformat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function test_equality()
2323
l.args[2].args[2] = Expr( :macrocall, symbol( "@sprintf" ), fmt, :x )
2424
mfmtr = eval( l )
2525
for i in 1:10000
26-
j = int( erfinv( rand() * 1.99 - 1.99/2.0 ) * 100000 )
26+
j = round(Int, erfinv( rand() * 1.99 - 1.99/2.0 ) * 100000 )
2727
expect = mfmtr( j )
2828
actual = sprintf1( fmt, j )
2929
@test expect == actual

0 commit comments

Comments
 (0)