Skip to content

Commit

Permalink
Fix writing of AnnotatedChars to AnnotatedIOBuffer (#53941)
Browse files Browse the repository at this point in the history
The AnnotatedString(::AnnotatedChar) constructor actually does not
exist. Considering that String(::Char) is not defined, and we don't try
this anywhere else, the obvious fix is to just construct the appropriate
AnnotatedString here.

We can think about more properly Char-optimised writes in the future if
it comes up.
  • Loading branch information
tecosaur authored Apr 18, 2024
1 parent 38a9725 commit 42b3134
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/strings/annotated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ function write(io::AnnotatedIOBuffer, astr::Union{AnnotatedString, SubString{<:A
write(io.io, String(astr))
end

write(io::AnnotatedIOBuffer, c::AnnotatedChar) = write(io, AnnotatedString(c))
write(io::AnnotatedIOBuffer, c::AnnotatedChar) =
write(io, AnnotatedString(string(c), map(a -> (1:ncodeunits(c), a), annotations(c))))
write(io::AnnotatedIOBuffer, x::AbstractString) = write(io.io, x)
write(io::AnnotatedIOBuffer, s::Union{SubString{String}, String}) = write(io.io, s)
write(io::AnnotatedIOBuffer, b::UInt8) = write(io.io, b)
Expand Down

0 comments on commit 42b3134

Please sign in to comment.