Skip to content

Commit 2a66639

Browse files
committed
update IOStrings and SplicedStrings for Julia 1.0
1 parent ed638ec commit 2a66639

File tree

6 files changed

+33
-43
lines changed

6 files changed

+33
-43
lines changed

src/AbstractArray.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Base.size(a::JSON.Array) = (length(a), )
1818

1919
# Iterate
2020

21-
function Base.iterate(j::JSON.Array, (i, c) = (j.i, 0x00))
21+
Base.iterate(j::JSON.Array, i = (j.i, 0x00)) = _iterate(j, i)
22+
function _iterate(j::JSON.Array, (i, c))
2223
i, c = nextindex(j, i, c)
2324
if c == ']'
2425
return nothing
@@ -35,9 +36,5 @@ Base.length(j::JSON.Array{IOString{T}}) where T =
3536
Base.getindex(j::JSON.Array{IOString{T}}, i::Integer) where T =
3637
pump(() -> getvalue(x, getindex_ic(j, i)...), j.s)
3738

38-
# FIXME
39-
#Base.done(j::JSON.Array{IOString{T}}, i) where T =
40-
# pump(() -> _done(j, i), j.s)
41-
42-
#Base.next(j::JSON.Array{IOString{T}}, i) where T =
43-
# pump(() -> _next(j, i), j.s)
39+
Base.iterate(j::JSON.Array{IOString{T}}, i = (j.i, 0x00)) where T =
40+
pump(() -> _iterate(j, i), j.s)

src/AbstractDict.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Base.length(a::JSON.Object) = div(collection_length(a), 2)
3131

3232
# Iterate
3333

34-
function Base.iterate(j::JSON.Object, (i, c) = (j.i, 0x00))
34+
Base.iterate(j::JSON.Object, i = (j.i, 0x00)) = _iterate(j, i)
35+
function _iterate(j::JSON.Object, (i, c))
3536

3637
i, c = nextindex(j, i, c)
3738

@@ -107,15 +108,11 @@ end
107108

108109
# IOString Wrappers
109110

110-
#FIXME
111-
#Base.length(j::JSON.Object{IOString{T}}) where T =
112-
# pump(() -> div(collection_length(j), 2), j.s)
111+
Base.length(j::JSON.Object{IOString{T}}) where T =
112+
pump(() -> div(collection_length(j), 2), j.s)
113113

114-
#Base.get(j::JSON.Object{IOString{T}}, key, default) where T =
115-
# pump(() -> _get(j, key, default), j.s)
114+
Base.get(j::JSON.Object{IOString{T}}, key, default) where T =
115+
pump(() -> _get(j, key, default), j.s)
116116

117-
#Base.done(j::JSON.Object{IOString{T}}, i) where T =
118-
# pump(() -> _done(j, i), j.s)
119-
120-
#Base.next(j::JSON.Object{IOString{T}}, i) where T =
121-
# pump(() -> _next(j, i), j.s)
117+
Base.iterate(j::JSON.Object{IOString{T}}, i = (j.i, 0x00)) where T =
118+
pump(() -> _iterate(j, i), j.s)

src/AbstractString.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ Base.codeunit(s::JSON.String) = codeunit(s.s)
4040
Base.codeunit(s::JSON.String, i::Integer) = codeunit(s.s, s.i + i))
4141

4242
@propagate_inbounds(
43-
function Base.iterate(s::JSON.String, i::Integer=1)
43+
Base.iterate(s::JSON.String, i::Integer=1) = _iterate(s, i))
44+
@propagate_inbounds(
45+
function _iterate(s::JSON.String, i)
4446
i, c = json_char(s.s, s.i + i)
4547
if c == nothing
4648
return nothing
@@ -293,7 +295,7 @@ end
293295

294296
#FIXME
295297
#https://github.com/JuliaLang/julia/commit/1f0c6fa35ab64ad66a5bb413fad474e2c722c290#r27686527
296-
Base.@propagate_inbounds function Base.iterate(s::IOString, i::Int)
298+
@propagate_inbounds function Base.iterate(s::IOString, i::Int = 1)
297299
b = codeunit(s, i)
298300
i > ncodeunits(s) && return nothing
299301
u = UInt32(b) << 24
@@ -333,3 +335,6 @@ Base.convert(::Type{SubString}, j::JSON.String{IOString{T}}) where T =
333335

334336
Base.ncodeunits(j::JSON.String{IOString{T}}) where T =
335337
pump(() -> scan_string(j.s, j.i)[1] - j.i - 1, j.s)
338+
339+
Base.iterate(j::JSON.String{IOString{T}}, i::Integer=1) where T =
340+
pump(() -> _iterate(j, i), j.s)

src/IOStrings.jl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,19 @@ Base.String(s::IOString) = convert(Base.String, s)
5858

5959
Base.IteratorSize(::Type{IOString}) = Base.SizeUnknown()
6060
Base.ncodeunits(s::IOString) = s.buf.size
61-
# FIXME pump here ??
6261
Base.codeunit(s::IOString) = UInt8
62+
@propagate_inbounds Base.codeunit(s::IOString, i::Integer) = s.buf.data[i]
63+
64+
Base.checkbounds(s::IOString, I::Union{Integer,AbstractArray}) =
65+
checkbounds(Bool, s, I) ? nothing :
66+
incomplete(s) ? throw(IncompleteError()) :
67+
throw(BoundsError(s, I))
6368

64-
#FIXME
65-
#@propagate_inbounds Base.codeunit(s::IOString, i::Integer) = s.buf.data[i]
66-
@propagate_inbounds function Base.codeunit(s::IOString, i::Integer)
67-
c = s.buf.data[i]
68-
while c == IOStrings.ASCII_ETB && bytesavailable(s.io) > 0
69-
pump(s)
70-
c = s.buf.data[i]
71-
end
72-
return c
73-
end
7469

7570
Base.pointer(s::IOString) = pointer(s.buf.data)
7671
Base.pointer(s::IOString, i) = pointer(s.buf.data, i)
7772

78-
incomplete(s::IOString) = s.buf.data[ncodeunits(s) + 1] == ASCII_ETB
73+
incomplete(s::IOString) = codeunit(s, ncodeunits(s) + 1) == ASCII_ETB
7974

8075
recoverable(e) = false
8176
recoverable(::IncompleteError) = true

src/LazyJSON.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ using Base: @propagate_inbounds
99

1010
const JSON = LazyJSON
1111

12-
const enable_iostrings = false
1312
const enable_getproperty = true
1413

1514
include("SplicedStrings.jl") ; using .SplicedStrings: SplicedString
@@ -138,14 +137,10 @@ value(ss::SubString{<:SupportedString}, path=nothing; kw...) =
138137

139138
value(bytes, path=nothing; kw...) = value(Base.String(bytes), path; kw...)
140139

141-
@static if enable_iostrings
142140
function value(io::IO, path=nothing; kw...)
143141
s = IOString(io)
144142
return pump(() -> value(s, path; kw...), s)
145143
end
146-
else
147-
value(io::IO, path=nothing; kw...) = value(read(io, String), path, kw...)
148-
end
149144

150145
IOStrings.recoverable(e::JSON.ParseError) = e.c == IOStrings.ASCII_ETB
151146

src/SplicedStrings.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,24 +360,25 @@ function Base.isvalid(s::SplicedString, i::Int)
360360
return isvalid(fragment_si(s, i)...)
361361
end)
362362

363-
364-
#FIXME
365-
#=
366363
@propagate_inbounds(
367-
function Base.next(s::SplicedString, i::Integer)
364+
function Base.iterate(s::SplicedString, i::Integer=1)
365+
if i == index_offset || isempty(s.v)
366+
return nothing
367+
end
368368
fs, fi = fragment_si(s, i)
369-
c, fi = @inbounds next(fs, fi)
369+
c, fi = @inbounds iterate(fs, fi)
370370
l = ncodeunits(fs)
371371
i = i & fragment_mask | fi + index_offset
372372
if fi > l
373373
n = i >> fragment_bits + 1
374374
if n < length(s.v)
375375
i = n << fragment_bits | 1 + index_offset
376+
else
377+
i = index_offset
376378
end
377379
end
378380
return c, i
379381
end)
380-
=#
381382

382383
@propagate_inbounds(
383384
function Base.nextind(s::SplicedString, i::Int)::Int

0 commit comments

Comments
 (0)