Skip to content

Commit 024233b

Browse files
committed
Merge pull request #13 from JuliaLang/yyc/0.4-binding
Fix 0.4 deprecated bindings
2 parents 2a95dd3 + b5e0da9 commit 024233b

File tree

6 files changed

+38
-50
lines changed

6 files changed

+38
-50
lines changed

.travis.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
language: cpp
2-
compiler:
3-
- clang
1+
language: julia
2+
os:
3+
- linux
4+
- osx
5+
julia:
6+
- 0.3
7+
- 0.4
8+
- nightly
49
notifications:
510
email: false
6-
env:
7-
matrix:
8-
- JULIAVERSION="juliareleases"
9-
- JULIAVERSION="julianightlies"
10-
before_install:
11-
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
12-
- sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y
13-
- sudo apt-get update -qq -y
14-
- sudo apt-get install libpcre3-dev julia -y
15-
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
16-
script:
17-
- julia -e 'versioninfo(); Pkg.init(); Pkg.clone(pwd()); Pkg.test("Formatting")'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ One can use ``printfmt`` and ``printfmtln`` for formatted printing:
8989
printfmt(FormatExpr("{1:d}", 10)) # OK
9090
```
9191

92-
92+
9393
- **printfmtln**(io, fe, args...)
9494

9595
- **printfmtln**(fe, args...)
@@ -103,7 +103,7 @@ One can use ``fmt`` to format a single value into a string, or ``format`` to for
103103
- **fmt**(fspec, a)
104104

105105
Format a single value using a format specification given by ``fspec``, where ``fspec`` can be either a string or an instance of ``FormatSpec``.
106-
106+
107107
- **format**(fe, args...)
108108

109109
Format arguments using a format expression given by ``fe``, where ``fe`` can be either a string or an instance of ``FormatSpec``.

src/cformat.jl

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

9-
if VERSION < v"0.4-"
10-
const base64encode = base64
11-
end
12-
139
function generate_formatter( fmt::ASCIIString )
1410
global formatters
1511
if haskey( formatters, fmt )
@@ -153,17 +149,17 @@ function format{T<:Real}( x::T;
153149
parens::Bool=false, # use (1.00) instead of -1.00. Used in finance
154150
alternative::Bool=false, # usually for hex
155151
mixedfraction::Bool=false,
156-
mixedfractionsep::String="_",
157-
fractionsep::String="/", # num / den
152+
mixedfractionsep::AbstractString="_",
153+
fractionsep::AbstractString="/", # num / den
158154
fractionwidth::Int = 0,
159155
tryden::Int = 0, # if 2 or higher, try to use this denominator, without losing precision
160-
suffix::String="", # useful for units/%
156+
suffix::AbstractString="", # useful for units/%
161157
autoscale::Symbol=:none, # :metric, :binary or :finance
162158
conversion::ASCIIString=""
163159
)
164160
checkwidth = commas
165161
if conversion == ""
166-
if T <: FloatingPoint || T <: Rational && precision != -1
162+
if T <: AbstractFloat || T <: Rational && precision != -1
167163
actualconv = "f"
168164
elseif T <: Unsigned
169165
actualconv = "x"
@@ -182,7 +178,7 @@ function format{T<:Real}( x::T;
182178
if T <: Rational && conversion == "s"
183179
stripzeros = false
184180
end
185-
if ( T <: FloatingPoint && actualconv == "f" || T <: Integer ) && autoscale != :none
181+
if ( T <: AbstractFloat && actualconv == "f" || T <: Integer ) && autoscale != :none
186182
actualconv = "f"
187183
if autoscale == :metric
188184
scales = [
@@ -202,7 +198,7 @@ function format{T<:Real}( x::T;
202198
break
203199
end
204200
end
205-
elseif T <: FloatingPoint
201+
elseif T <: AbstractFloat
206202
smallscales = [
207203
( 1e-12, "p" ),
208204
( 1e-9, "n" ),

src/fmtcore.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ end
1212

1313
### print string or char
1414

15-
function _pfmt_s(out::IO, fs::FormatSpec, s::Union(String,Char))
15+
@compat function _pfmt_s(out::IO, fs::FormatSpec, s::Union{AbstractString,Char})
1616
wid = fs.width
1717
slen = length(s)
1818
if wid <= slen
@@ -35,12 +35,12 @@ end
3535
_mul(x::Integer, ::_Dec) = x * 10
3636
_mul(x::Integer, ::_Bin) = x << 1
3737
_mul(x::Integer, ::_Oct) = x << 3
38-
_mul(x::Integer, ::Union(_Hex, _HEX)) = x << 4
38+
@compat _mul(x::Integer, ::Union{_Hex, _HEX}) = x << 4
3939

4040
_div(x::Integer, ::_Dec) = div(x, 10)
4141
_div(x::Integer, ::_Bin) = x >> 1
4242
_div(x::Integer, ::_Oct) = x >> 3
43-
_div(x::Integer, ::Union(_Hex, _HEX)) = x >> 4
43+
@compat _div(x::Integer, ::Union{_Hex, _HEX}) = x >> 4
4444

4545
function _ndigits(x::Integer, op) # suppose x is non-negative
4646
m = 1
@@ -53,7 +53,7 @@ function _ndigits(x::Integer, op) # suppose x is non-negative
5353
end
5454

5555
_ipre(op) = ""
56-
_ipre(::Union(_Hex, _HEX)) = "0x"
56+
@compat _ipre(::Union{_Hex, _HEX}) = "0x"
5757
_ipre(::_Oct) = "0o"
5858
_ipre(::_Bin) = "0b"
5959

@@ -171,7 +171,7 @@ function _pfmt_float(out::IO, sch::Char, zs::Integer, intv::Real, decv::Real, pr
171171
end
172172
end
173173

174-
function _pfmt_f(out::IO, fs::FormatSpec, x::FloatingPoint)
174+
function _pfmt_f(out::IO, fs::FormatSpec, x::AbstractFloat)
175175
# separate sign, integer, and decimal part
176176
ax = abs(x)
177177
sch = _signchar(x, fs.sign)
@@ -227,7 +227,7 @@ function _pfmt_floate(out::IO, sch::Char, zs::Integer, u::Real, prec::Int, e::In
227227
end
228228

229229

230-
function _pfmt_e(out::IO, fs::FormatSpec, x::FloatingPoint)
230+
function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
231231
# extract sign, significand, and exponent
232232
ax = abs(x)
233233
sch = _signchar(x, fs.sign)
@@ -265,7 +265,7 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::FloatingPoint)
265265
end
266266

267267

268-
function _pfmt_g(out::IO, fs::FormatSpec, x::FloatingPoint)
268+
function _pfmt_g(out::IO, fs::FormatSpec, x::AbstractFloat)
269269
# number decomposition
270270
ax = abs(x)
271271
if 1.0e-4 <= ax < 1.0e6
@@ -275,7 +275,7 @@ function _pfmt_g(out::IO, fs::FormatSpec, x::FloatingPoint)
275275
end
276276
end
277277

278-
function _pfmt_specialf(out::IO, fs::FormatSpec, x::FloatingPoint)
278+
function _pfmt_specialf(out::IO, fs::FormatSpec, x::AbstractFloat)
279279
if isinf(x)
280280
if x > 0
281281
_pfmt_s(out, fs, "Inf")

src/fmtspec.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ end
7777

7878
const _spec_regex = r"^(.?[<>])?([ +-])?(#)?(\d+)?(,)?(.\d+)?([bcdeEfFgGnosxX])?$"
7979

80-
function FormatSpec(s::String)
80+
function FormatSpec(s::AbstractString)
8181
# default spec
8282
_fill = ' '
8383
_align = '\0'
@@ -165,7 +165,7 @@ type _HEX end
165165
type _Bin end
166166

167167
_srepr(x) = repr(x)
168-
_srepr(x::String) = x
168+
_srepr(x::AbstractString) = x
169169
_srepr(x::Char) = string(x)
170170

171171
function printfmt(io::IO, fs::FormatSpec, x)
@@ -197,4 +197,4 @@ end
197197
printfmt(fs::FormatSpec, x) = printfmt(STDOUT, fs, x)
198198

199199
fmt(fs::FormatSpec, x) = (buf = IOBuffer(); printfmt(buf, fs, x); bytestring(buf))
200-
fmt(spec::String, x) = fmt(FormatSpec(spec), x)
200+
fmt(spec::AbstractString, x) = fmt(FormatSpec(spec), x)

src/formatexpr.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ immutable ArgSpec
1313
end
1414
end
1515

16-
getarg(args, sp::ArgSpec) =
16+
getarg(args, sp::ArgSpec) =
1717
(a = args[sp.argidx]; sp.hasfilter ? sp.filter(a) : a)
1818

1919
# pos > 0: must not have iarg in expression (use pos+1), return (entry, pos + 1)
2020
# pos < 0: must have iarg in expression, return (entry, -1)
2121
# pos = 0: no positional argument before, can be either, return (entry, 1) or (entry, -1)
22-
function make_argspec(s::String, pos::Int)
22+
function make_argspec(s::AbstractString, pos::Int)
2323
# for argument position
2424
iarg::Int = -1
2525
hasfil::Bool = false
@@ -60,7 +60,7 @@ immutable FormatEntry
6060
spec::FormatSpec
6161
end
6262

63-
function make_formatentry(s::String, pos::Int)
63+
function make_formatentry(s::AbstractString, pos::Int)
6464
@assert s[1] == '{' && s[end] == '}'
6565
sc = s[2:end-1]
6666
icolon = search(sc, ':')
@@ -86,7 +86,7 @@ end
8686

8787
_raise_unmatched_lbrace() = error("Unmatched { in format expression.")
8888

89-
function find_next_entry_open(s::String, si::Int)
89+
function find_next_entry_open(s::AbstractString, si::Int)
9090
slen = length(s)
9191
p = search(s, '{', si)
9292
p < slen || _raise_unmatched_lbrace()
@@ -103,15 +103,15 @@ function find_next_entry_open(s::String, si::Int)
103103
return (p, utf8(pre))
104104
end
105105

106-
function find_next_entry_close(s::String, si::Int)
106+
function find_next_entry_close(s::AbstractString, si::Int)
107107
slen = length(s)
108108
p = search(s, '}', si)
109109
p > 0 || _raise_unmatched_lbrace()
110110
# println("close at $p")
111111
return p
112112
end
113113

114-
function FormatExpr(s::String)
114+
function FormatExpr(s::AbstractString)
115115
slen = length(s)
116116

117117
# init
@@ -159,12 +159,11 @@ function printfmt(io::IO, fe::FormatExpr, args...)
159159
end
160160
end
161161

162-
printfmt(io::IO, fe::String, args...) = printfmt(io, FormatExpr(fe), args...)
163-
printfmt(fe::Union(String,FormatExpr), args...) = printfmt(STDOUT, fe, args...)
162+
printfmt(io::IO, fe::AbstractString, args...) = printfmt(io, FormatExpr(fe), args...)
163+
@compat printfmt(fe::Union{AbstractString,FormatExpr}, args...) = printfmt(STDOUT, fe, args...)
164164

165-
printfmtln(io::IO, fe::Union(String,FormatExpr), args...) = (printfmt(io, fe, args...); println(io))
166-
printfmtln(fe::Union(String,FormatExpr), args...) = printfmtln(STDOUT, fe, args...)
165+
@compat printfmtln(io::IO, fe::Union{AbstractString,FormatExpr}, args...) = (printfmt(io, fe, args...); println(io))
166+
@compat printfmtln(fe::Union{AbstractString,FormatExpr}, args...) = printfmtln(STDOUT, fe, args...)
167167

168-
format(fe::Union(String,FormatExpr), args...) =
168+
@compat format(fe::Union{AbstractString,FormatExpr}, args...) =
169169
(buf = IOBuffer(); printfmt(buf, fe, args...); bytestring(buf))
170-

0 commit comments

Comments
 (0)