@@ -127,17 +127,16 @@ findfirst(ch::AbstractChar, string::AbstractString) = findfirst(==(ch), string)
127127function findnext (testf:: Function , s:: AbstractString , i:: Integer )
128128 i = Int (i)
129129 z = ncodeunits (s) + 1
130- 1 ≤ i ≤ z || throw (BoundsError (s, i))
130+ 1 ≤ i ≤ z || throw (BoundsError (s, i))
131131 @inbounds i == z || isvalid (s, i) || string_index_err (s, i)
132- e = lastindex (s )
133- while i <= e
134- testf ( @inbounds s[i]) && return i
135- i = @inbounds nextind (s, i)
132+ for (j, d) in pairs ( SubString (s, i) )
133+ if testf (d)
134+ return i + j - 1
135+ end
136136 end
137137 return nothing
138138end
139139
140-
141140in (c:: AbstractChar , s:: AbstractString ) = (findfirst (isequal (c),s)!= = nothing )
142141
143142function _searchindex (s:: Union{AbstractString,ByteArray} ,
@@ -335,16 +334,18 @@ findlast(ch::AbstractChar, string::AbstractString) = findlast(==(ch), string)
335334
336335# AbstractString implementation of the generic findprev interface
337336function findprev (testf:: Function , s:: AbstractString , i:: Integer )
338- i = Int (i)
339- z = ncodeunits (s) + 1
340- 0 ≤ i ≤ z || throw (BoundsError (s, i))
341- i == z && return nothing
342- @inbounds i == 0 || isvalid (s, i) || string_index_err (s, i)
343- while i >= 1
344- testf (@inbounds s[i]) && return i
345- i = @inbounds prevind (s, i)
337+ if i < 1
338+ return i == 0 ? nothing : throw (BoundsError (s, i))
346339 end
347- return nothing
340+ n = ncodeunits (s)
341+ if i > n
342+ return i == n+ 1 ? nothing : throw (BoundsError (s, i))
343+ end
344+ # r[reverseind(r,i)] == reverse(r)[i] == s[i]
345+ # s[reverseind(s,j)] == reverse(s)[j] == r[j]
346+ r = reverse (s)
347+ j = findnext (testf, r, reverseind (r, i))
348+ j === nothing ? nothing : reverseind (s, j)
348349end
349350
350351function _rsearchindex (s:: AbstractString ,
0 commit comments