11#=
22Search functions for Str strings
33
4- Copyright 2018-2020 Gandalf Software, Inc., Scott P. Jones,
4+ Copyright 2018-2023 Gandalf Software, Inc., Scott P. Jones,
55and other contributors to the Julia language
66Licensed under MIT License, see LICENSE.md
77Based in part on julia/base/strings/search.jl
@@ -131,7 +131,11 @@ for (S,T) in ((:AbstractString, :Str), (:Str, :AbstractString), (:Str, :Str),
131131end
132132
133133function find (:: Type{D} , fun:: Function , str:: AbstractString , pos:: Integer ) where {D<: Direction }
134- pos < Int (D=== Fwd) && (@boundscheck boundserr (str, pos); return 0 )
134+ if pos < 1
135+ D === Fwd && @boundscheck boundserr (str, pos)
136+ # Just return 0 if < 0 for Rev (match Base bug)
137+ return 0
138+ end
135139 if pos > (len = ncodeunits (str))
136140 @boundscheck pos > len+ 1 && boundserr (str, pos)
137141 return 0
@@ -157,7 +161,11 @@ find(::Type{D}, pred::P, str::AbstractString,
157161 find (D, pred. x, str, pos)
158162
159163function find (:: Type{D} , ch:: AbstractChar , str:: AbstractString , pos:: Integer ) where {D<: Direction }
160- pos < Int (D=== Fwd) && (@boundscheck boundserr (str, pos); return 0 )
164+ if pos < 1
165+ D === Fwd && @boundscheck boundserr (str, pos)
166+ # Just return 0 if < 0 for Rev (match Base bug)
167+ return 0
168+ end
161169 if pos > (len = ncodeunits (str))
162170 @boundscheck pos > len+ 1 && boundserr (str, pos)
163171 return 0
0 commit comments