From 51793a1a8c84d303c3009929398aa9d10eaeeb31 Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 27 Jul 2024 12:14:00 +0800 Subject: [PATCH] Don't try to use new SubString constructor We need to use the kludge that is eval(Expr(:new, ...)) instead. --- src/io.jl | 2 +- src/strings/annotated.jl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/io.jl b/src/io.jl index 04fa61c4..53cc27c8 100644 --- a/src/io.jl +++ b/src/io.jl @@ -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 diff --git a/src/strings/annotated.jl b/src/strings/annotated.jl index 75aee5c4..afdcd71f 100644 --- a/src/strings/annotated.jl +++ b/src/strings/annotated.jl @@ -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 @@ -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))