Skip to content

Commit 4b32f67

Browse files
committed
Show OffsetRanges as ranges
1 parent 663542a commit 4b32f67

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/OffsetArrays.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ Base.getindex(a::AbstractRange, r::OffsetRange) = OffsetArray(a[parent(r)], r.of
182182
@inline @propagate_inbounds Base.getindex(r::LinRange, s::IIUR) =
183183
OffsetArray(r[s.indices], s)
184184

185+
function Base.show(io::IO, r::OffsetRange)
186+
show(io, r.parent)
187+
o = r.offsets[1]
188+
print(io, " with indices ", o+1:o+length(r))
189+
end
190+
Base.show(io::IO, ::MIME"text/plain", r::OffsetRange) = show(io, r)
191+
185192
### Convenience functions ###
186193

187194
Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ end
231231
@test summary(view(a, :, 5)) == "$(shownsz)view(OffsetArray(::Array{$(Int),2}, -1:0, 5:6), :, 5) with eltype $(Int) with indices -1:0"
232232
a = OffsetArray(reshape([1]))
233233
@test summary(a) == "0-dimensional OffsetArray(::Array{$(Int),0}) with eltype $(Int)"
234+
235+
show(io, OffsetArray(3:5, 0:2))
236+
@test String(take!(io)) == "3:5 with indices 0:2"
234237
end
235238

236239
@testset "readdlm/writedlm" begin

0 commit comments

Comments
 (0)