Skip to content

Commit

Permalink
Match Base behaviour for findprev when pos < 0 (return 0, instead of …
Browse files Browse the repository at this point in the history
…bounderror)
  • Loading branch information
ScottPJones committed Oct 27, 2023
1 parent 2720ea2 commit 7003390
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["ScottPJones <[email protected]>"]
keywords = ["Strings"]
license = "MIT"
uuid = "e79e7a6a-7bb1-5a4d-9d64-da657b06f53a"
version = "1.1.4"
version = "1.1.5"

[deps]
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
Expand All @@ -28,5 +28,5 @@ julia = "^1.6"
ModuleInterfaceTools = "1"
MurmurHash3 = "^1.2"
StrAPI = "^1.1"
ChrBase = "^1.0.3"
ChrBase = "^1.0.4"
CharSetEncodings = "1"
14 changes: 11 additions & 3 deletions src/search.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#=
Search functions for Str strings
Copyright 2018-2020 Gandalf Software, Inc., Scott P. Jones,
Copyright 2018-2023 Gandalf Software, Inc., Scott P. Jones,
and other contributors to the Julia language
Licensed under MIT License, see LICENSE.md
Based in part on julia/base/strings/search.jl
Expand Down Expand Up @@ -131,7 +131,11 @@ for (S,T) in ((:AbstractString, :Str), (:Str, :AbstractString), (:Str, :Str),
end

function find(::Type{D}, fun::Function, str::AbstractString, pos::Integer) where {D<:Direction}
pos < Int(D===Fwd) && (@boundscheck boundserr(str, pos); return 0)
if pos < 1
D === Fwd && @boundscheck boundserr(str, pos)
# Just return 0 if < 0 for Rev (match Base bug)
return 0
end
if pos > (len = ncodeunits(str))
@boundscheck pos > len+1 && boundserr(str, pos)
return 0
Expand All @@ -157,7 +161,11 @@ find(::Type{D}, pred::P, str::AbstractString,
find(D, pred.x, str, pos)

function find(::Type{D}, ch::AbstractChar, str::AbstractString, pos::Integer) where {D<:Direction}
pos < Int(D===Fwd) && (@boundscheck boundserr(str, pos); return 0)
if pos < 1
D === Fwd && @boundscheck boundserr(str, pos)
# Just return 0 if < 0 for Rev (match Base bug)
return 0
end
if pos > (len = ncodeunits(str))
@boundscheck pos > len+1 && boundserr(str, pos)
return 0
Expand Down

0 comments on commit 7003390

Please sign in to comment.