@@ -153,7 +153,7 @@ lastindex(s::AnnotatedString) = lastindex(s.string)
153
153
function getindex (s:: AnnotatedString , i:: Integer )
154
154
@boundscheck checkbounds (s, i)
155
155
@inbounds if isvalid (s, i)
156
- AnnotatedChar (s. string[i], annotations (s, i))
156
+ AnnotatedChar (s. string[i], map (last, annotations (s, i) ))
157
157
else
158
158
string_index_err (s, i)
159
159
end
@@ -354,12 +354,16 @@ annotate!(c::AnnotatedChar, @nospecialize(labelval::Pair{Symbol, <:Any})) =
354
354
(push! (c. annotations, labelval); c)
355
355
356
356
"""
357
- annotations(str::AnnotatedString, [position::Union{Integer, UnitRange}])
358
- annotations(str::SubString{AnnotatedString}, [position::Union{Integer, UnitRange}])
357
+ annotations(str::Union{AnnotatedString, SubString{AnnotatedString}},
358
+ [position::Union{Integer, UnitRange}]) ->
359
+ Vector{Tuple{UnitRange{Int}, Pair{Symbol, Any}}}
359
360
360
361
Get all annotations that apply to `str`. Should `position` be provided, only
361
362
annotations that overlap with `position` will be returned.
362
363
364
+ Annotations are provided together with the regions they apply to, in the form of
365
+ a vector of region–annotation tuples.
366
+
363
367
See also: `annotate!`.
364
368
"""
365
369
annotations (s:: AnnotatedString ) = s. annotations
@@ -369,22 +373,22 @@ annotations(s::SubString{<:AnnotatedString}) =
369
373
370
374
function annotations (s:: AnnotatedString , pos:: UnitRange{<:Integer} )
371
375
# TODO optimise
372
- annots = filter (label -> ! isempty (intersect (pos, first (label))),
373
- s. annotations)
374
- last .(annots)
376
+ filter (label -> ! isempty (intersect (pos, first (label))),
377
+ s. annotations)
375
378
end
376
379
377
380
annotations (s:: AnnotatedString , pos:: Integer ) = annotations (s, pos: pos)
378
381
379
382
annotations (s:: SubString{<:AnnotatedString} , pos:: Integer ) =
380
383
annotations (s. string, s. offset + pos)
384
+
381
385
annotations (s:: SubString{<:AnnotatedString} , pos:: UnitRange{<:Integer} ) =
382
386
annotations (s. string, first (pos)+ s. offset: last (pos)+ s. offset)
383
387
384
388
"""
385
- annotations(chr::AnnotatedChar)
389
+ annotations(chr::AnnotatedChar) -> Vector{Pair{Symbol, Any}}
386
390
387
- Get all annotations of `chr`.
391
+ Get all annotations of `chr`, in the form of a vector of annotation pairs .
388
392
"""
389
393
annotations (c:: AnnotatedChar ) = c. annotations
390
394
0 commit comments