Skip to content

Commit efa721b

Browse files
tecosaurKristofferC
authored andcommitted
Correct annotation calculation with annot substr
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.
1 parent 6bc4e8a commit efa721b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

base/strings/annotated.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,16 @@ See also: `annotate!`.
370370
"""
371371
annotations(s::AnnotatedString) = s.annotations
372372

373-
annotations(s::SubString{<:AnnotatedString}) =
374-
annotations(s, s.offset+1:s.offset+s.ncodeunits)
373+
function annotations(s::SubString{<:AnnotatedString})
374+
map(((region, annot),) -> (first(region)-s.offset:last(region)-s.offset, annot),
375+
annotations(s.string, s.offset+1:s.offset+s.ncodeunits))
376+
end
375377

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

382385
annotations(s::AnnotatedString, pos::Integer) = annotations(s, pos:pos)

0 commit comments

Comments
 (0)