Skip to content

Commit 90ac502

Browse files
authored
Merge pull request #24 from JuliaString/spj/findprev
Match Base behaviour for findprev when pos < 0 (return 0, instead of error)
2 parents 2720ea2 + 7003390 commit 90ac502

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["ScottPJones <[email protected]>"]
44
keywords = ["Strings"]
55
license = "MIT"
66
uuid = "e79e7a6a-7bb1-5a4d-9d64-da657b06f53a"
7-
version = "1.1.4"
7+
version = "1.1.5"
88

99
[deps]
1010
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
@@ -28,5 +28,5 @@ julia = "^1.6"
2828
ModuleInterfaceTools = "1"
2929
MurmurHash3 = "^1.2"
3030
StrAPI = "^1.1"
31-
ChrBase = "^1.0.3"
31+
ChrBase = "^1.0.4"
3232
CharSetEncodings = "1"

src/search.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#=
22
Search 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,
55
and other contributors to the Julia language
66
Licensed under MIT License, see LICENSE.md
77
Based in part on julia/base/strings/search.jl
@@ -131,7 +131,11 @@ for (S,T) in ((:AbstractString, :Str), (:Str, :AbstractString), (:Str, :Str),
131131
end
132132

133133
function 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

159163
function 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

Comments
 (0)