Skip to content

Commit

Permalink
Fix startswith/endswith for Julia 1.10 (#68)
Browse files Browse the repository at this point in the history
* Fix startswith/endswith for Julia 1.10

* compat for 1.6

* oops
  • Loading branch information
quinnj committed Jul 29, 2023
1 parent 85fc0d1 commit dafec6f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/InlineStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,9 @@ function Base.repeat(x::T, r::Integer) where {T <: InlineString}
end

# copy/pasted from strings/util.jl
function Base.startswith(a::T, b::Union{String, SubString{String}, InlineString}) where {T <: InlineString}
#TODO: optimize this
Base.startswith(a::InlineString, b::InlineString) = invoke(startswith, Tuple{AbstractString, AbstractString}, a, b)
function Base.startswith(a::T, b::Union{String, SubString{String}}) where {T <: InlineString}
cub = ncodeunits(b)
ncodeunits(a) < cub && return false
ref = Ref{T}(_bswap(a))
Expand All @@ -693,7 +695,9 @@ function Base.startswith(a::T, b::Union{String, SubString{String}, InlineString}
end
end

function Base.endswith(a::T, b::Union{String, SubString{String}, InlineString}) where {T <: InlineString}
#TODO: optimize this
Base.endswith(a::InlineString, b::InlineString) = invoke(endswith, Tuple{AbstractString, AbstractString}, a, b)
function Base.endswith(a::T, b::Union{String, SubString{String}}) where {T <: InlineString}
cub = ncodeunits(b)
astart = ncodeunits(a) - ncodeunits(b) + 1
astart < 1 && return false
Expand Down

0 comments on commit dafec6f

Please sign in to comment.