Skip to content

Commit

Permalink
Merge pull request JuliaIO#164 from TotalVerb/fw/v0.4
Browse files Browse the repository at this point in the history
Drop v0.3 support and clean up `@compat`s
  • Loading branch information
TotalVerb authored Aug 19, 2016
2 parents 495c75f + a2bb2d0 commit 21dcd64
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 69 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os:
- osx
- linux
julia:
- 0.3
- 0.4
- 0.5
- nightly
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

[![JSON](http://pkg.julialang.org/badges/JSON_0.3.svg)](http://pkg.julialang.org/?pkg=JSON&ver=0.3)
[![JSON](http://pkg.julialang.org/badges/JSON_0.4.svg)](http://pkg.julialang.org/?pkg=JSON&ver=0.4)
[![JSON](http://pkg.julialang.org/badges/JSON_0.5.svg)](http://pkg.julialang.org/?pkg=JSON&ver=0.5)
[![JSON](http://pkg.julialang.org/badges/JSON_0.6.svg)](http://pkg.julialang.org/?pkg=JSON&ver=0.6)

**Installation**: `julia> Pkg.add("JSON")`

Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.3
julia 0.4
Compat 0.8.4
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.3/julia-0.3-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.3/julia-0.3-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
Expand Down
16 changes: 8 additions & 8 deletions src/JSON.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ immutable AssociativeWrapper{T} <: Associative{Symbol, Any}
wrapped::T
fns::Array{Symbol, 1}
end
AssociativeWrapper(x) = AssociativeWrapper(x, @compat fieldnames(x))
AssociativeWrapper(x) = AssociativeWrapper(x, fieldnames(x))

typealias JSONPrimitive @compat(Union{
typealias JSONPrimitive Union{
Associative, Tuple, AbstractArray, AbstractString, Integer,
AbstractFloat, Bool, Void})
AbstractFloat, Bool, Void}

Base.getindex(w::AssociativeWrapper, s::Symbol) = getfield(w.wrapped, s)
Base.keys(w::AssociativeWrapper) = w.fns
Expand Down Expand Up @@ -70,7 +70,7 @@ for c in 0x00:0xFF
[c] # UTF-8 character copied verbatim
elseif haskey(REVERSE_ESCAPES, c)
[BACKSLASH, REVERSE_ESCAPES[c]]
elseif iscntrl(@compat Char(c)) || !isprint(@compat Char(c))
elseif iscntrl(Char(c)) || !isprint(Char(c))
UInt8[BACKSLASH, LATIN_U, hex(c, 4)...]
else
[c]
Expand Down Expand Up @@ -132,7 +132,7 @@ end

function print_escaped(io::IO, s::AbstractString)
@inbounds for c in s
c <= '\x7f' ? Base.write(io, escaped[@compat UInt8(c) + 0x01]) :
c <= '\x7f' ? Base.write(io, escaped[UInt8(c) + 0x01]) :
Base.print(io, c) #JSON is UTF8 encoded
end
end
Expand All @@ -149,15 +149,15 @@ function _writejson(io::IO, state::State, s::AbstractString)
Base.print(io, '"')
end

@compat function _writejson(io::IO, state::State, s::Union{Integer, AbstractFloat})
function _writejson(io::IO, state::State, s::Union{Integer, AbstractFloat})
if isnan(s) || isinf(s)
Base.print(io, "null")
else
Base.print(io, s)
end
end

@compat function _writejson(io::IO, state::State, n::Void)
function _writejson(io::IO, state::State, n::Void)
Base.print(io, "null")
end

Expand All @@ -178,7 +178,7 @@ function _writejson(io::IO, state::State, a::Associative)
end_object(io, state, true)
end

@compat function _writejson(io::IO, state::State, a::Union{AbstractVector,Tuple})
function _writejson(io::IO, state::State, a::Union{AbstractVector,Tuple})
if length(a) == 0
Base.print(io, "[]")
return
Expand Down
23 changes: 11 additions & 12 deletions src/Parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ skip past that byte. Otherwise, an error is thrown.
if byteat(ps) == c
incr!(ps)
else
_error("Expected '$(@compat Char(c))' here", ps)
_error("Expected '$(Char(c))' here", ps)
end
end

Expand Down Expand Up @@ -229,7 +229,7 @@ end


utf16_is_surrogate(c::UInt16) = (c & 0xf800) == 0xd800
utf16_get_supplementary(lead::UInt16, trail::UInt16) = @compat(Char(@compat(UInt32(lead-0xd7f7)<<10) + trail))
utf16_get_supplementary(lead::UInt16, trail::UInt16) = Char(UInt32(lead-0xd7f7)<<10 + trail)

function read_four_hex_digits!(ps::ParserState)
local n::UInt16 = 0
Expand All @@ -239,9 +239,9 @@ function read_four_hex_digits!(ps::ParserState)
n = n << 4 + if isjsondigit(b)
b - DIGIT_ZERO
elseif LATIN_A b LATIN_F
b - (LATIN_A - @compat UInt8(10))
b - (LATIN_A - UInt8(10))
elseif LATIN_UPPER_A b LATIN_UPPER_F
b - (LATIN_UPPER_A - @compat UInt8(10))
b - (LATIN_UPPER_A - UInt8(10))
else
_error(E_BAD_ESCAPE, ps)
end
Expand All @@ -258,7 +258,7 @@ function read_unicode_escape!(ps)
u2 = read_four_hex_digits!(ps)
utf16_get_supplementary(u1, u2)
else
@compat(Char(u1))
Char(u1)
end
end

Expand Down Expand Up @@ -295,7 +295,7 @@ has a leading zero.
"""
function hasleadingzero(bytes::Vector{UInt8}, from::Int, to::Int)
c = bytes[from]
from + 1 < to && c == @compat(UInt8('-')) &&
from + 1 < to && c == UInt8('-') &&
bytes[from + 1] == DIGIT_ZERO && isjsondigit(bytes[from + 2]) ||
from < to && to > from + 1 && c == DIGIT_ZERO &&
isjsondigit(bytes[from + 1])
Expand All @@ -322,10 +322,9 @@ the byte before `to`. Bytes enclosed should all be ASCII characters.
"""
function int_from_bytes(bytes::Vector{UInt8}, from::Int, to::Int)
@inbounds isnegative = bytes[from] == MINUS_SIGN ? (from += 1; true) : false
num = @compat Int64(0)
num = Int64(0)
@inbounds for i in from:to
num = (@compat Int64(10)) * num +
@compat Int64(bytes[i] - DIGIT_ZERO)
num = Int64(10) * num + Int64(bytes[i] - DIGIT_ZERO)
end
ifelse(isnegative, -num, num)
end
Expand Down Expand Up @@ -358,9 +357,9 @@ function parse_number(ps::ParserState)
c = current(ps)

if isjsondigit(c) || c == MINUS_SIGN
push!(number, @compat UInt8(c))
push!(number, UInt8(c))
elseif c in (PLUS_SIGN, LATIN_E, LATIN_UPPER_E, DECIMAL_POINT)
push!(number, @compat UInt8(c))
push!(number, UInt8(c))
isint = false
else
break
Expand All @@ -375,7 +374,7 @@ end

function unparameterize_type{T}(::Type{T})
candidate = typeintersect(T, Associative{Compat.UTF8String, Any})
candidate <: (@compat Union{}) ? T : candidate
candidate <: Union{} ? T : candidate
end

function parse{T<:Associative}(str::AbstractString; dicttype::Type{T}=Dict{Compat.UTF8String,Any})
Expand Down
70 changes: 35 additions & 35 deletions src/bytes.jl
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
# The following bytes have significant meaning in JSON
const BACKSPACE = @compat UInt8('\b')
const TAB = @compat UInt8('\t')
const NEWLINE = @compat UInt8('\n')
const FORM_FEED = @compat UInt8('\f')
const RETURN = @compat UInt8('\r')
const SPACE = @compat UInt8(' ')
const STRING_DELIM = @compat UInt8('"')
const PLUS_SIGN = @compat UInt8('+')
const DELIMITER = @compat UInt8(',')
const MINUS_SIGN = @compat UInt8('-')
const DECIMAL_POINT = @compat UInt8('.')
const SOLIDUS = @compat UInt8('/')
const DIGIT_ZERO = @compat UInt8('0')
const DIGIT_NINE = @compat UInt8('9')
const SEPARATOR = @compat UInt8(':')
const LATIN_UPPER_A = @compat UInt8('A')
const LATIN_UPPER_E = @compat UInt8('E')
const LATIN_UPPER_F = @compat UInt8('F')
const ARRAY_BEGIN = @compat UInt8('[')
const BACKSLASH = @compat UInt8('\\')
const ARRAY_END = @compat UInt8(']')
const LATIN_A = @compat UInt8('a')
const LATIN_B = @compat UInt8('b')
const LATIN_E = @compat UInt8('e')
const LATIN_F = @compat UInt8('f')
const LATIN_L = @compat UInt8('l')
const LATIN_N = @compat UInt8('n')
const LATIN_R = @compat UInt8('r')
const LATIN_S = @compat UInt8('s')
const LATIN_T = @compat UInt8('t')
const LATIN_U = @compat UInt8('u')
const OBJECT_BEGIN = @compat UInt8('{')
const OBJECT_END = @compat UInt8('}')
const BACKSPACE = UInt8('\b')
const TAB = UInt8('\t')
const NEWLINE = UInt8('\n')
const FORM_FEED = UInt8('\f')
const RETURN = UInt8('\r')
const SPACE = UInt8(' ')
const STRING_DELIM = UInt8('"')
const PLUS_SIGN = UInt8('+')
const DELIMITER = UInt8(',')
const MINUS_SIGN = UInt8('-')
const DECIMAL_POINT = UInt8('.')
const SOLIDUS = UInt8('/')
const DIGIT_ZERO = UInt8('0')
const DIGIT_NINE = UInt8('9')
const SEPARATOR = UInt8(':')
const LATIN_UPPER_A = UInt8('A')
const LATIN_UPPER_E = UInt8('E')
const LATIN_UPPER_F = UInt8('F')
const ARRAY_BEGIN = UInt8('[')
const BACKSLASH = UInt8('\\')
const ARRAY_END = UInt8(']')
const LATIN_A = UInt8('a')
const LATIN_B = UInt8('b')
const LATIN_E = UInt8('e')
const LATIN_F = UInt8('f')
const LATIN_L = UInt8('l')
const LATIN_N = UInt8('n')
const LATIN_R = UInt8('r')
const LATIN_S = UInt8('s')
const LATIN_T = UInt8('t')
const LATIN_U = UInt8('u')
const OBJECT_BEGIN = UInt8('{')
const OBJECT_END = UInt8('}')

const ESCAPES = @compat(Dict(
const ESCAPES = Dict(
STRING_DELIM => STRING_DELIM,
BACKSLASH => BACKSLASH,
SOLIDUS => SOLIDUS,
LATIN_B => BACKSPACE,
LATIN_F => FORM_FEED,
LATIN_N => NEWLINE,
LATIN_R => RETURN,
LATIN_T => TAB))
LATIN_T => TAB)
2 changes: 1 addition & 1 deletion src/specialized.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function parse_string(ps::MemoryParserState)
fastpath, len = predict_string(ps)

# Now read the string itself
b = @compat Array{UInt8, 1}(len)
b = Array{UInt8, 1}(len)

# Fast path occurs when the string has no escaped characters. This is quite
# often the case in real-world data, especially when keys are short strings.
Expand Down
4 changes: 2 additions & 2 deletions test/lowering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

@test JSON.json(Type151) == "\"Type151{T}\""

JSON.lower{T}(v::Type151{T}) = @compat Dict(:type => T, :value => v.x)
@test JSON.parse(JSON.json(Type151(1.0))) == @compat Dict(
JSON.lower{T}(v::Type151{T}) = Dict(:type => T, :value => v.x)
@test JSON.parse(JSON.json(Type151(1.0))) == Dict(
"type" => "Float64",
"value" => 1.0)
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ json_dollars = json(dollars)
write(w, json_dollars)

# unmatched brackets
brackets = @compat Dict("foo"=>"ba}r", "be}e]p"=>"boo{p")
brackets = Dict("foo"=>"ba}r", "be}e]p"=>"boo{p")
json_brackets = json(brackets)
@test JSON.parse(json_brackets) != nothing
write(w, json_dollars)

fetch(finished_async_tests)

zeros = @compat Dict("\0"=>"\0")
zeros = Dict("\0" => "\0")
json_zeros = json(zeros)
@test contains(json_zeros,"\\u0000")
@test !contains(json_zeros,"\\0")
Expand Down Expand Up @@ -192,7 +192,7 @@ a=JSON.parse(test21)
@test json([Int64[] Int64[]]') == "[]"

# ::Void values should be encoded as null
testDict = @compat Dict("a" => nothing)
testDict = Dict("a" => nothing)
nothingJson = JSON.json(testDict)
nothingDict = JSON.parse(nothingJson)
@test testDict == nothingDict
Expand Down Expand Up @@ -235,7 +235,7 @@ ejson2 = json(ev)
@test JSON.parse(ejson1) == JSON.parse(ejson2)

# test symbols are treated as strings
symtest = @compat Dict(:symbolarray => [:apple, :pear], :symbolsingleton => :hello)
symtest = Dict(:symbolarray => [:apple, :pear], :symbolsingleton => :hello)
@test (JSON.json(symtest) == "{\"symbolarray\":[\"apple\",\"pear\"],\"symbolsingleton\":\"hello\"}"
|| JSON.json(symtest) == "{\"symbolsingleton\":\"hello\",\"symbolarray\":[\"apple\",\"pear\"]}")

Expand Down Expand Up @@ -289,8 +289,8 @@ end
# Test for Issue #99
@test_throws ErrorException JSON.parse("[\"🍕\"_\"🍕\"")

# Check that printing to the default STDOUT doesn't fail
JSON.print(["JSON.jl tests pass!"],1)

# Lowering tests
include("lowering.jl")

# Check that printing to the default STDOUT doesn't fail
JSON.print(["JSON.jl tests pass!"],1)

0 comments on commit 21dcd64

Please sign in to comment.