Skip to content

Commit d166d2c

Browse files
tecosaurKristofferC
authored andcommitted
Fix writing of AnnotatedChars to AnnotatedIOBuffer (#53941)
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. (cherry picked from commit 42b3134)
1 parent a3277ab commit d166d2c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

base/strings/annotated.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ function write(io::AnnotatedIOBuffer, astr::Union{AnnotatedString, SubString{<:A
484484
write(io.io, String(astr))
485485
end
486486

487-
write(io::AnnotatedIOBuffer, c::AnnotatedChar) = write(io, AnnotatedString(c))
487+
write(io::AnnotatedIOBuffer, c::AnnotatedChar) =
488+
write(io, AnnotatedString(string(c), map(a -> (1:ncodeunits(c), a), annotations(c))))
488489
write(io::AnnotatedIOBuffer, x::AbstractString) = write(io.io, x)
489490
write(io::AnnotatedIOBuffer, s::Union{SubString{String}, String}) = write(io.io, s)
490491
write(io::AnnotatedIOBuffer, b::UInt8) = write(io.io, b)

0 commit comments

Comments
 (0)