Skip to content

Commit 93b91e2

Browse files
committed
make package 0.6-only
remove Compat and duplicated code
1 parent c94496c commit 93b91e2

File tree

8 files changed

+34
-118
lines changed

8 files changed

+34
-118
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.4
7-
- 0.5
6+
- 0.6
87
- nightly
98
notifications:
109
email: false

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.4
2-
Compat 0.8.0
1+
julia 0.6-pre

src/Formatting.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ module Formatting
99
printfmt, printfmtln, fmt, format,
1010
sprintf1, generate_formatter
1111

12-
using Compat
13-
1412
include("cformat.jl" )
1513
include("fmtspec.jl")
1614
include("fmtcore.jl")

src/cformat.jl

Lines changed: 6 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
formatters = Dict{ Compat.ASCIIString, Function }()
1+
formatters = Dict{ String, Function }()
22

3-
if VERSION >= v"0.6.0-dev.1671"
4-
5-
sprintf1( fmt::Compat.ASCIIString, x ) = eval(Expr(:call, generate_formatter( fmt ), x))
3+
sprintf1( fmt::String, x ) = eval(Expr(:call, generate_formatter( fmt ), x))
64

75
function checkfmt(fmt)
86
test = Base.Printf.parse( fmt )
97
(length( test ) == 1 && typeof( test[1] ) <: Tuple) ||
108
error( "Only one AND undecorated format string is allowed")
119
end
1210

13-
function generate_formatter( fmt::Compat.ASCIIString )
11+
function generate_formatter( fmt::String )
1412
global formatters
1513

1614
haskey( formatters, fmt ) && return formatters[fmt]
@@ -65,85 +63,8 @@ function checkcommas(s)
6563
s
6664
end
6765

68-
else
69-
70-
sprintf1( fmt::Compat.ASCIIString, x ) = (generate_formatter( fmt ))(x)
71-
72-
function generate_formatter( fmt::Compat.ASCIIString )
73-
global formatters
74-
if haskey( formatters, fmt )
75-
return formatters[fmt]
76-
end
77-
78-
func = @compat Symbol("sprintf_", replace(base64encode(fmt), "=", "!"))
79-
80-
if !contains( fmt, "'" )
81-
test = Base.Printf.parse( fmt )
82-
if length( test ) != 1 || !( typeof( test[1] ) <: Tuple )
83-
error( "Only one AND undecorated format string is allowed")
84-
end
85-
86-
code = quote
87-
function $func( x )
88-
@sprintf( $fmt, x )
89-
end
90-
end
91-
else
92-
conversion = fmt[end]
93-
if !in( conversion, "sduifF" )
94-
error( "thousand separator not defined for " * string( conversion ) * " conversion")
95-
end
96-
fmtactual = replace( fmt, "'", "", 1 )
97-
test = Base.Printf.parse( fmtactual )
98-
if length( test ) != 1 || !( typeof( test[1] ) <: Tuple )
99-
error( "Only one AND undecorated format string is allowed")
100-
end
101-
if in( conversion, "sfF" )
102-
code = quote
103-
function $func{T<:Real}( x::T )
104-
s = @sprintf( $fmtactual, x )
105-
# commas are added to only the numerator
106-
if T <: Rational && endswith( $fmtactual, "s" )
107-
spos = findfirst( s, '/' )
108-
s = addcommas( s[1:spos-1] ) * s[spos:end]
109-
else
110-
dpos = findfirst( s, '.' )
111-
if dpos != 0
112-
s = addcommas( s[1:dpos-1] ) * s[ dpos:end ]
113-
else # find the rightmost digit
114-
for i in length( s ):-1:1
115-
if isdigit( s[i] )
116-
s = addcommas( s[1:i] ) * s[i+1:end]
117-
break
118-
end
119-
end
120-
end
121-
end
122-
s
123-
end
124-
end
125-
else
126-
code = quote
127-
function $func( x )
128-
s = @sprintf( $fmtactual, x )
129-
for i in length( s ):-1:1
130-
if isdigit( s[i] )
131-
s = addcommas( s[1:i] ) * s[i+1:end]
132-
break
133-
end
134-
end
135-
s
136-
end
137-
end
138-
end
139-
end
140-
f = eval( code )
141-
formatters[ fmt ] = f
142-
f
143-
end
144-
end
14566

146-
function addcommas( s::Compat.ASCIIString )
67+
function addcommas( s::String )
14768
len = length(s)
14869
t = ""
14970
for i in 1:3:len
@@ -170,7 +91,7 @@ function generate_format_string(;
17091
signed::Bool=false,
17192
positivespace::Bool=false,
17293
alternative::Bool=false,
173-
conversion::Compat.ASCIIString="f" #aAdecEfFiosxX
94+
conversion::String="f" #aAdecEfFiosxX
17495
)
17596
s = "%"
17697
if commas
@@ -220,7 +141,7 @@ function format{T<:Real}( x::T;
220141
tryden::Int = 0, # if 2 or higher, try to use this denominator, without losing precision
221142
suffix::AbstractString="", # useful for units/%
222143
autoscale::Symbol=:none, # :metric, :binary or :finance
223-
conversion::Compat.ASCIIString=""
144+
conversion::String=""
224145
)
225146
checkwidth = commas
226147
if conversion == ""

src/fmtcore.jl

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

1313
### print string or char
1414

15-
@compat function _pfmt_s(out::IO, fs::FormatSpec, s::Union{AbstractString,Char})
15+
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-
@compat _mul(x::Integer, ::Union{_Hex, _HEX}) = x << 4
38+
_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-
@compat _div(x::Integer, ::Union{_Hex, _HEX}) = x >> 4
43+
_div(x::Integer, ::Union{_Hex, _HEX}) = x >> 4
4444

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

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

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))
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))
6565

6666
_signchar(x::Number, s::Char) = x < 0 ? '-' :
6767
s == '+' ? '+' :
6868
s == ' ' ? ' ' : '\0'
6969

70-
function _pfmt_int{Op}(out::IO, sch::Char, ip::Compat.ASCIIString, zs::Integer, ax::Integer, op::Op)
70+
function _pfmt_int{Op}(out::IO, sch::Char, ip::String, zs::Integer, ax::Integer, op::Op)
7171
# print sign
7272
if sch != '\0'
7373
write(out, sch)
@@ -222,8 +222,8 @@ function _pfmt_floate(out::IO, sch::Char, zs::Integer, u::Real, prec::Int, e::In
222222
e = -e
223223
end
224224
(e1, e2) = divrem(e, 10)
225-
write(out, @compat Char('0' + e1))
226-
write(out, @compat Char('0' + e2))
225+
write(out, Char('0' + e1))
226+
write(out, Char('0' + e2))
227227
end
228228

229229

src/fmtspec.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function printfmt(io::IO, fs::FormatSpec, x)
176176
cls = fs.cls
177177
ty = fs.typ
178178
if cls == 'i'
179-
ix = @compat Integer(x)
179+
ix = Integer(x)
180180
ty == 'd' || ty == 'n' ? _pfmt_i(io, fs, ix, _Dec()) :
181181
ty == 'x' ? _pfmt_i(io, fs, ix, _Hex()) :
182182
ty == 'X' ? _pfmt_i(io, fs, ix, _HEX()) :
@@ -194,7 +194,7 @@ function printfmt(io::IO, fs::FormatSpec, x)
194194
elseif cls == 's'
195195
_pfmt_s(io, fs, _srepr(x))
196196
else # cls == 'c'
197-
_pfmt_s(io, fs, @compat Char(x))
197+
_pfmt_s(io, fs, Char(x))
198198
end
199199
end
200200

src/formatexpr.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function make_argspec(s::AbstractString, pos::Int)
3232
else
3333
iarg = ifil > 1 ? parse(Int,s[1:ifil-1]) : -1
3434
hasfil = true
35-
ff = eval(@compat Symbol(s[ifil+2:end]))
35+
ff = eval(Symbol(s[ifil+2:end]))
3636
end
3737
end
3838

@@ -78,10 +78,10 @@ end
7878
### Format expression
7979

8080
type FormatExpr
81-
prefix::Compat.UTF8String
82-
suffix::Compat.UTF8String
81+
prefix::String
82+
suffix::String
8383
entries::Vector{FormatEntry}
84-
inter::Vector{Compat.UTF8String}
84+
inter::Vector{String}
8585
end
8686

8787
_raise_unmatched_lbrace() = error("Unmatched { in format expression.")
@@ -100,7 +100,7 @@ function find_next_entry_open(s::AbstractString, si::Int)
100100
pre = replace(pre, "{{", '{')
101101
pre = replace(pre, "}}", '}')
102102
end
103-
return (p, convert(Compat.UTF8String, pre))
103+
return (p, convert(String, pre))
104104
end
105105

106106
function find_next_entry_close(s::AbstractString, si::Int)
@@ -115,10 +115,10 @@ function FormatExpr(s::AbstractString)
115115
slen = length(s)
116116

117117
# init
118-
prefix = convert(Compat.UTF8String, "")
119-
suffix = convert(Compat.UTF8String, "")
118+
prefix = ""
119+
suffix = ""
120120
entries = FormatEntry[]
121-
inter = Compat.UTF8String[]
121+
inter = String[]
122122

123123
# scan
124124
(p, prefix) = find_next_entry_open(s, 1)
@@ -160,10 +160,10 @@ function printfmt(io::IO, fe::FormatExpr, args...)
160160
end
161161

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

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...)
165+
printfmtln(io::IO, fe::Union{AbstractString,FormatExpr}, args...) = (printfmt(io, fe, args...); println(io))
166+
printfmtln(fe::Union{AbstractString,FormatExpr}, args...) = printfmtln(STDOUT, fe, args...)
167167

168-
@compat format(fe::Union{AbstractString,FormatExpr}, args...) =
168+
format(fe::Union{AbstractString,FormatExpr}, args...) =
169169
sprint(printfmt, fe, args...)

test/cformat.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Formatting
2-
using Compat
32
using Base.Test
43

54
_erfinv(z) = sqrt(π) * Base.Math.@horner(z, 0, 1, 0, π/12, 0, 7π^2/480, 0, 127π^3/40320, 0,

0 commit comments

Comments
 (0)