Skip to content

Commit 75617bd

Browse files
committed
Switch noshift substring constructor to unsafe_substring
1 parent c642041 commit 75617bd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/JuliaSyntaxHighlighting.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,19 @@ function highlight!(str::AnnotatedString; syntax_errors::Bool = false)
460460
str
461461
end
462462

463+
# The undocumented :noshift constructor was removed between Julia 1.12 and Julia 1.13.
464+
@static if isdefined(Base, :unsafe_substring)
465+
function plain_string(s::SubString{<:AnnotatedString})
466+
@inbounds Base.unsafe_substring(s.string, s.offset + 1, s.ncodeunits)
467+
end
468+
else
469+
function plain_string(s::SubString{AnnotatedString{S}}) where S
470+
SubString{S}(s.string.string, s.offset, s.ncodeunits, Val(:noshift))
471+
end
472+
end
473+
463474
function highlight!(str::SubString{AnnotatedString{S}}; syntax_errors::Bool = false) where {S}
464-
plainstr = SubString{S}(str.string.string, str.offset, str.ncodeunits, Val(:noshift))
475+
plainstr = plain_string(str)
465476
for ann in _hl_annotations(plainstr, parseall(GreenNode, plainstr, ignore_errors=true); syntax_errors)
466477
annotate!(str, ann.region, ann.label, ann.value)
467478
end

0 commit comments

Comments
 (0)