|
1 | 1 | #= |
2 | 2 | Search functions for Str strings |
3 | 3 |
|
4 | | -Copyright 2018 Gandalf Software, Inc., Scott P. Jones, and other contributors to the Julia language |
| 4 | +Copyright 2018-2020 Gandalf Software, Inc., Scott P. Jones, |
| 5 | +and other contributors to the Julia language |
5 | 6 | Licensed under MIT License, see LICENSE.md |
6 | 7 | Based in part on julia/base/strings/search.jl |
7 | 8 | =# |
8 | | - |
9 | 9 | """ |
10 | 10 | find(Fwd, pattern, string::AbstractString, start::Integer) |
11 | 11 |
|
@@ -153,10 +153,10 @@ find(pat::Function, ::Type{D}, str::AbstractString) where {D<:FindOp} = find(D, |
153 | 153 | find(pat::Function, ::Type{D}, str::AbstractString, pos) where {D<:FindOp} = find(D, pat, str, pos) |
154 | 154 |
|
155 | 155 | find(::Type{D}, pred::P, str::AbstractString, |
156 | | - pos::Integer) where {P<:Fix2{Union{typeof(==),typeof(isequal)}, <:AbsChar}, D<:Direction} = |
| 156 | + pos::Integer) where {P<:Fix2{Union{typeof(==),typeof(isequal)}, <:AbstractChar}, D<:Direction} = |
157 | 157 | find(D, pred.x, str, pos) |
158 | 158 |
|
159 | | -function find(::Type{D}, ch::AbsChar, str::AbstractString, pos::Integer) where {D<:Direction} |
| 159 | +function find(::Type{D}, ch::AbstractChar, str::AbstractString, pos::Integer) where {D<:Direction} |
160 | 160 | pos < Int(D===Fwd) && (@boundscheck boundserr(str, pos); return 0) |
161 | 161 | if pos > (len = ncodeunits(str)) |
162 | 162 | @boundscheck pos > len+1 && boundserr(str, pos) |
|
171 | 171 | _get_dir(::Type{First}) = Fwd() |
172 | 172 | _get_dir(::Type{Last}) = Rev() |
173 | 173 |
|
174 | | -find(::Type{D}, ch::AbsChar, str::AbstractString) where {D<:Union{First,Last}} = |
| 174 | +find(::Type{D}, ch::AbstractChar, str::AbstractString) where {D<:Union{First,Last}} = |
175 | 175 | ((len = ncodeunits(str)) == 0 || !is_valid(eltype(str), ch) ? 0 |
176 | 176 | : _srch_cp(_get_dir(D), EncodingStyle(str), str, ch, |
177 | 177 | D === First ? 1 : lastindex(str), len)) |
|
270 | 270 | # _srch_cp is only called with values that are valid for that string type, |
271 | 271 | # and checking as already been done on the position (pos) |
272 | 272 | # These definitions only work for SingleCU types |
273 | | -_srch_cp(::Fwd, ::SingleCU, str::T, cp::AbsChar, pos, len) where {T<:Str} = |
| 273 | +_srch_cp(::Fwd, ::SingleCU, str::T, cp::AbstractChar, pos, len) where {T<:Str} = |
274 | 274 | @preserve str _srch_codeunit(Fwd(), pointer(str), cp%codeunit(T), pos, len) |
275 | | -_srch_cp(::Rev, ::SingleCU, str::T, cp::AbsChar, pos, len) where {T<:Str} = |
| 275 | +_srch_cp(::Rev, ::SingleCU, str::T, cp::AbstractChar, pos, len) where {T<:Str} = |
276 | 276 | @preserve str _srch_codeunit(Rev(), pointer(str), cp%codeunit(T), pos) |
277 | 277 |
|
278 | 278 | function _srch_cp(::Fwd, cus, str, cp, pos, len) |
@@ -423,7 +423,7 @@ occurs_in(needle::Char, hay::Str) = _occurs_in(needle, hay) |
423 | 423 | occurs_in(needle::Str, hay::Str) = _occurs_in(needle, hay) |
424 | 424 |
|
425 | 425 | in(chr::Chr, str::AbstractString) = _occurs_in(chr, str) |
426 | | -in(chr::AbsChar, str::Str) = _occurs_in(chr, str) |
| 426 | +in(chr::AbstractChar, str::Str) = _occurs_in(chr, str) |
427 | 427 | in(pat::Str, str::AbstractString) = _occurs_in(pat, str) |
428 | 428 | in(pat::AbstractString, str::Str) = _occurs_in(pat, str) |
429 | 429 | in(pat::Str, str::Str) = _occurs_in(pat, str) |
0 commit comments