From 7003390053d3321124051f7df1bc3579118647c0 Mon Sep 17 00:00:00 2001 From: ScottPJones Date: Fri, 27 Oct 2023 08:18:10 -0400 Subject: [PATCH] Match Base behaviour for findprev when pos < 0 (return 0, instead of bounderror) --- Project.toml | 4 ++-- src/search.jl | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index d581837..514f705 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,7 @@ authors = ["ScottPJones "] 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" @@ -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" diff --git a/src/search.jl b/src/search.jl index 9592eaf..9a7d899 100644 --- a/src/search.jl +++ b/src/search.jl @@ -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 @@ -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 @@ -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