Skip to content

Commit fae3c71

Browse files
committed
Update to work around changes in Compat in Julia 1.3
1 parent aed7804 commit fae3c71

File tree

8 files changed

+33
-31
lines changed

8 files changed

+33
-31
lines changed

Project.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ keywords = ["Strings", "Formatting"]
2323
license = "MIT"
2424
name = "Format"
2525
uuid = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
26-
version = "1.0.0"
26+
version = "1.0.1"
2727

2828
[deps]
29-
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
29+
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
30+
31+
[extras]
32+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
33+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
34+
35+
[targets]
36+
test = ["Test", "Random"]
3037

3138
[compat]
3239
julia = "^1.0.0"
33-
Compat = "≥ 1.0.1"

src/Format.jl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ __precompile__(true)
33
module Format
44

55
import Base.show
6-
using Compat
7-
using Compat.Printf
8-
const V6_COMPAT = VERSION < v"0.7.0-DEV"
9-
10-
_stdout() = @static V6_COMPAT ? STDOUT : stdout
11-
_codeunits(s) = Vector{UInt8}(@static V6_COMPAT ? s : codeunits(s))
12-
@static if V6_COMPAT
13-
const m_eval = eval
14-
else
15-
m_eval(expr) = Core.eval(@__MODULE__, expr)
16-
end
6+
7+
using Printf
8+
const PF = @static VERSION >= v"1.4.0-DEV.180" ? Printf : Base.Printf
9+
10+
_stdout() = stdout
11+
_codeunits(s) = Vector{UInt8}(codeunits(s))
12+
m_eval(expr) = Core.eval(@__MODULE__, expr)
1713

1814
export FormatSpec, FormatExpr, printfmt, printfmtln, format, generate_formatter
1915
export pyfmt, cfmt, fmt

src/cformat.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ formatters = Dict{ ASCIIStr, Function }()
33
cfmt( fmt::ASCIIStr, x ) = m_eval(Expr(:call, generate_formatter( fmt ), x))
44

55
function checkfmt(fmt)
6-
test = Base.Printf.parse( fmt )
6+
test = PF.parse( fmt )
77
(length( test ) == 1 && typeof( test[1] ) <: Tuple) ||
88
error( "Only one AND undecorated format string is allowed")
99
end
@@ -38,7 +38,7 @@ function generate_formatter( fmt::ASCIIStr )
3838
end
3939

4040
function addcommasreal(s)
41-
dpos = Compat.findfirst( isequal('.'), s )
41+
dpos = findfirst( isequal('.'), s )
4242
dpos !== nothing && return string(addcommas( s[1:dpos-1] ), s[ dpos:end ])
4343
# find the rightmost digit
4444
for i in length( s ):-1:1
@@ -49,7 +49,7 @@ end
4949

5050
function addcommasrat(s)
5151
# commas are added to only the numerator
52-
spos = Compat.findfirst( isequal('/'), s )
52+
spos = findfirst( isequal('/'), s )
5353
string(addcommas( s[1:spos-1] ), s[spos:end])
5454
end
5555

@@ -254,10 +254,10 @@ function format( x::T;
254254
checkwidth = true
255255
end
256256
elseif stripzeros && in( actualconv[1], "fFeEs" )
257-
dpos = Compat.findfirst( isequal('.'), s )
257+
dpos = findfirst( isequal('.'), s )
258258
dpos === nothing && (dpos = length(s))
259259
if actualconv[1] in "eEs"
260-
epos = Compat.findfirst(isequal(actualconv[1] == 'E' ? 'E' : 'e'), s)
260+
epos = findfirst(isequal(actualconv[1] == 'E' ? 'E' : 'e'), s)
261261
rpos = (epos === nothing) ? length( s ) : (epos-1)
262262
else
263263
rpos = length(s)

src/fmt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ end
125125

126126
function _optional_commas(x::Real, s::AbstractString, fspec::FormatSpec)
127127
prevwidth = length(s)
128-
dpos = Compat.findfirst( isequal('.'), s)
128+
dpos = findfirst( isequal('.'), s)
129129
s = dpos === nothing ? addcommas(s) : string(addcommas(s[1:dpos-1]), '.', s[dpos+1:end])
130130

131131
# check for excess width from commas

src/fmtcore.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ end
159159

160160
function _pfmt_f(out::IO, fs::FormatSpec, x::AbstractFloat)
161161
# separate sign, integer, and decimal part
162-
rax = Compat.round(abs(x), digits = fs.prec)
162+
rax = round(abs(x); digits = fs.prec)
163163
sch = _signchar(x, fs.sign)
164164
intv = trunc(Integer, rax)
165165
decv = rax - intv
@@ -214,7 +214,7 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
214214
e = 0
215215
u = zero(x)
216216
else
217-
rax = Compat.round(ax, sigdigits = fs.prec + 1)
217+
rax = round(ax; sigdigits = fs.prec + 1)
218218
e = floor(Integer, log10(rax)) # exponent
219219
u = rax * exp10(-e) # significand
220220
end

src/formatexpr.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function make_argspec(s::AbstractString, pos::Int)
2626
ff::Function = Base.identity
2727

2828
if !isempty(s)
29-
filrange = Compat.findfirst("|>", s)
29+
filrange = findfirst("|>", s)
3030
if filrange === nothing
3131
iarg = parse(Int, s)
3232
else
@@ -64,7 +64,7 @@ end
6464
function make_formatentry(s::AbstractString, pos::Int)
6565
@assert s[1] == '{' && s[end] == '}'
6666
sc = s[2:prevind(s, lastindex(s))]
67-
icolon = Compat.findfirst(isequal(':'), sc)
67+
icolon = findfirst(isequal(':'), sc)
6868
if icolon === nothing # no colon
6969
(argspec, pos) = make_argspec(sc, pos)
7070
spec = FormatSpec('s')
@@ -89,10 +89,10 @@ _raise_unmatched_lbrace() = error("Unmatched { in format expression.")
8989

9090
function find_next_entry_open(s::AbstractString, si::Int)
9191
slen = lastindex(s)
92-
p = Compat.findnext(isequal('{'), s, si)
92+
p = findnext(isequal('{'), s, si)
9393
(p === nothing || p < slen) || _raise_unmatched_lbrace()
9494
while p !== nothing && s[p+1] == '{' # escape `{{`
95-
p = Compat.findnext(isequal('{'), s, p+2)
95+
p = findnext(isequal('{'), s, p+2)
9696
(p === nothing || p < slen) || _raise_unmatched_lbrace()
9797
end
9898
pre = p !== nothing ? s[si:prevind(s, p)] : s[si:end]
@@ -104,7 +104,7 @@ function find_next_entry_open(s::AbstractString, si::Int)
104104
end
105105

106106
function find_next_entry_close(s::AbstractString, si::Int)
107-
p = Compat.findnext(isequal('}'), s, si)
107+
p = findnext(isequal('}'), s, si)
108108
p !== nothing || _raise_unmatched_lbrace()
109109
return p
110110
end

test/cformat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
_erfinv(z) = sqrt(π) * Base.Math.@horner(z, 0, 1, 0, π/12, 0, 7π^2/480, 0, 127π^3/40320, 0,
22
4369π^4/5806080, 0, 34807π^5/182476800) / 2
33

4-
set_seed!(seed) = @static VERSION < v"0.7.0" ? srand(seed) : Random.seed!(seed)
4+
set_seed!(seed) = Random.seed!(seed)
55

66
function test_equality()
77
println( "test cformat equality...")

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Format
2-
using Compat.Test
3-
using Compat.Printf
4-
using Compat.Random
2+
using Test
3+
using Printf
4+
using Random
55

66
@testset "cformat" begin include( "cformat.jl" ) end
77
@testset "fmtspec" begin include( "fmtspec.jl" ) end

0 commit comments

Comments
 (0)