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. It turns
out there's an underlying issue with a compiler flag being broken,
however I've also noticed that the annotation calculation for SubStrings
was incorrect, as it didn't take into account the substring offset or
width. We might as well fix this.
  • Loading branch information
tecosaur committed Feb 19, 2024
1 parent 15bb4dc commit c4a9965
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions base/strings/annotated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,16 @@ 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(((region, annot),) -> (first(region)-s.offset:last(region)-s.offset, annot),
annotations(s.string, s.offset+1:s.offset+s.ncodeunits))
end

function annotations(s::AnnotatedString, pos::UnitRange{<:Integer})
# TODO optimise
filter(label -> !isempty(intersect(pos, first(label))),
s.annotations)
Tuple{UnitRange{Int64}, Pair{Symbol, Any}}[
(max(first(pos), first(region)):min(last(pos), last(region)), annot)
for (region, annot) in s.annotations if !isempty(intersect(pos, region))]
end

annotations(s::AnnotatedString, pos::Integer) = annotations(s, pos:pos)
Expand Down

0 comments on commit c4a9965

Please sign in to comment.