Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display "(empty range)" in case of empty ranges #57697

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ end

show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges

function show(io::IO, ::MIME"text/plain", r::UnitRange)
print(io, repr(first(r)), ':', repr(last(r)))
if isempty(r)
print(io, " (empty range)")
end
end

function show(io::IO, ::MIME"text/plain", r::LinRange)
isempty(r) && return show(io, r)
# show for LinRange, e.g.
Expand Down
6 changes: 3 additions & 3 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ julia> searchsorted([1, 2, 4, 5, 5, 7], 5) # multiple matches
4:5
julia> searchsorted([1, 2, 4, 5, 5, 7], 3) # no match, insert in the middle
3:2
3:2 (empty range)
julia> searchsorted([1, 2, 4, 5, 5, 7], 9) # no match, insert at end
7:6
7:6 (empty range)
julia> searchsorted([1, 2, 4, 5, 5, 7], 0) # no match, insert at start
1:0
1:0 (empty range)
julia> searchsorted([1=>"one", 2=>"two", 2=>"two", 4=>"four"], 2=>"two", by=first) # compare the keys of the pairs
2:3
Expand Down