Skip to content

Commit

Permalink
Correct annotation calculation with annot substr
Browse files Browse the repository at this point in the history
The commit e1a76bb was ultimately
reverted due to it seeming to introduce an abort signal in CI.

I suspect this could be connected to the code in the StyledStrings
stdlib that has an @inbounds next to an assumption that substring ranges
are valid (regioniterator.jl:13).

The annotation calculation for SubStrings was incorrect, as it didn't
take into account the substring offset or width. CI will hopefully tell
us if this is the root cause.
  • Loading branch information
tecosaur committed Feb 14, 2024
1 parent 6faf589 commit f855c1d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions base/strings/annotated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,13 @@ See also: `annotate!`.
"""
annotations(s::AnnotatedString) = s.annotations

annotations(s::SubString{<:AnnotatedString}) =
annotations(s, s.offset+1:s.offset+s.ncodeunits)
function annotations(s::SubString{<:AnnotatedString})
map(function ((region, annot),)
region = max(1, first(region) - s.offset):min(s.ncodeunits, last(region) - s.offset)
(region, annot)
end,
annotations(s.string, s.offset+1:s.offset+s.ncodeunits))
end

function annotations(s::AnnotatedString, pos::UnitRange{<:Integer})
# TODO optimise
Expand Down

0 comments on commit f855c1d

Please sign in to comment.