Skip to content

Commit cc186c6

Browse files
authored
improve printing for homogenous arrays (#63)
This came up on Slack. Makes arrays of `InlineString`s a bit easier to read.
1 parent 9b4ff8f commit cc186c6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/InlineStrings.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ Base.Array{UInt8}(s::InlineString) = Vector{UInt8}(codeunits(s))
176176

177177
Base.show(io::IO, ::MIME"text/plain", s::InlineString) = Base.print_quoted(io, s)
178178
function Base.show(io::IO, s::InlineString) # So `repr` shows how to recreate `s`
179-
print(io, typeof(s), "(")
180-
Base.print_quoted(io, s)
181-
print(io, ")")
179+
if get(io, :typeinfo, Any) === typeof(s)
180+
Base.print_quoted(io, s)
181+
else
182+
print(io, typeof(s), "(")
183+
Base.print_quoted(io, s)
184+
print(io, ")")
185+
end
182186
end
183187

184188
# add a codeunit to end of string method

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,4 +558,7 @@ end
558558
# repr
559559
@test sprint(show, s) == "String7(\"abc\")"
560560
@test eval(Meta.parse(repr(s))) === s
561+
562+
@test repr(String31["foo", "bar"]) == "String31[\"foo\", \"bar\"]"
563+
@test repr(InlineString[inline1"a", inline15"a"]) == "InlineString[String1(\"a\"), String15(\"a\")]"
561564
end

0 commit comments

Comments
 (0)