Skip to content

Commit

Permalink
Don't try to use new SubString constructor
Browse files Browse the repository at this point in the history
We need to use the kludge that is eval(Expr(:new, ...)) instead.
  • Loading branch information
tecosaur committed Jul 27, 2024
1 parent 93e7496 commit 51793a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function _ansi_writer(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedS
string_writer(io, s.string)
elseif s isa SubString
string_writer(
io, SubString(s.string.string, s.offset, s.ncodeunits, Val(:noshift)))
io, eval(Expr(:new, SubString{typeof(s.string.string)}, s.string.string, s.offset, s.ncodeunits)))
end
end

Expand Down
10 changes: 5 additions & 5 deletions src/strings/annotated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ cmp(a::AnnotatedString, b::AnnotatedString) = cmp(a.string, b.string)
# To prevent substring equality from hitting the generic fallback

function ==(a::SubString{<:AnnotatedString}, b::SubString{<:AnnotatedString})
SubString(a.string.string, a.offset, a.ncodeunits, Val(:noshift)) ==
SubString(b.string.string, b.offset, b.ncodeunits, Val(:noshift)) &&
eval(Expr(:new, SubString{typeof(a.string.string)}, a.string.string, a.offset, a.ncodeunits)) ==
eval(Expr(:new, SubString{typeof(b.string.string)}, b.string.string, b.offset, b.ncodeunits)) &&
annotations(a) == annotations(b)
end

==(a::SubString{<:AnnotatedString}, b::AnnotatedString) =
annotations(a) == annotations(b) && SubString(a.string.string, a.offset, a.ncodeunits, Val(:noshift)) == b.string
annotations(a) == annotations(b) && eval(Expr(:new, SubString{typeof(a.string.string)}, a.string.string, a.offset, a.ncodeunits)) == b.string

==(a::SubString{<:AnnotatedString}, b::AbstractString) =
isempty(annotations(a)) && SubString(a.string.string, a.offset, a.ncodeunits, Val(:noshift)) == b
isempty(annotations(a)) && eval(Expr(:new, SubString{typeof(a.string.string)}, a.string.string, a.offset, a.ncodeunits)) == b

==(a::AbstractString, b::SubString{<:AnnotatedString}) = b == a

Expand Down Expand Up @@ -264,7 +264,7 @@ function annotatedstring(xs...)
push!(annotations, (rstart:rstop, annot))
end
end
print(s, SubString(x.string.string, x.offset, x.ncodeunits, Val(:noshift)))
print(s, eval(Expr(:new, SubString{typeof(x.string.string)}, x.string.string, x.offset, x.ncodeunits)))
elseif x isa AnnotatedChar
for annot in x.annotations
push!(annotations, (1+size:1+size, annot))
Expand Down

0 comments on commit 51793a1

Please sign in to comment.