From 6a7fd254d43626aa0d3a707befdebaecd5352fd0 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 8 Mar 2022 09:42:15 -0600 Subject: [PATCH] Prepare for invalidation-resistant calls to `match` --- base/strings/substring.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/base/strings/substring.jl b/base/strings/substring.jl index 2c701a03d0633a..86efbc1f6df3e4 100644 --- a/base/strings/substring.jl +++ b/base/strings/substring.jl @@ -55,6 +55,11 @@ convert(::Type{SubString{S}}, s::AbstractString) where {S<:AbstractString} = SubString(convert(S, s)) convert(::Type{T}, s::T) where {T<:SubString} = s +# Regex match allows only Union{String, SubString{String}} so define conversion to this type +convert(::Type{Union{String, SubString{String}}}, s::String) = s +convert(::Type{Union{String, SubString{String}}}, s::SubString{String}) = s +convert(::Type{Union{String, SubString{String}}}, s::AbstractString) = convert(String, s) + function String(s::SubString{String}) parent = s.string copy = GC.@preserve parent unsafe_string(pointer(parent, s.offset+1), s.ncodeunits)