Skip to content

Commit 83d84a2

Browse files
committed
Update to use AbstractChar
1 parent 7472f6b commit 83d84a2

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
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.0.3"
7+
version = "1.0.4"
88

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

src/search.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#=
22
Search functions for Str strings
33
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
56
Licensed under MIT License, see LICENSE.md
67
Based in part on julia/base/strings/search.jl
78
=#
8-
99
"""
1010
find(Fwd, pattern, string::AbstractString, start::Integer)
1111
@@ -153,10 +153,10 @@ find(pat::Function, ::Type{D}, str::AbstractString) where {D<:FindOp} = find(D,
153153
find(pat::Function, ::Type{D}, str::AbstractString, pos) where {D<:FindOp} = find(D, pat, str, pos)
154154

155155
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} =
157157
find(D, pred.x, str, pos)
158158

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}
160160
pos < Int(D===Fwd) && (@boundscheck boundserr(str, pos); return 0)
161161
if pos > (len = ncodeunits(str))
162162
@boundscheck pos > len+1 && boundserr(str, pos)
@@ -171,7 +171,7 @@ end
171171
_get_dir(::Type{First}) = Fwd()
172172
_get_dir(::Type{Last}) = Rev()
173173

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}} =
175175
((len = ncodeunits(str)) == 0 || !is_valid(eltype(str), ch) ? 0
176176
: _srch_cp(_get_dir(D), EncodingStyle(str), str, ch,
177177
D === First ? 1 : lastindex(str), len))
@@ -270,9 +270,9 @@ end
270270
# _srch_cp is only called with values that are valid for that string type,
271271
# and checking as already been done on the position (pos)
272272
# 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} =
274274
@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} =
276276
@preserve str _srch_codeunit(Rev(), pointer(str), cp%codeunit(T), pos)
277277

278278
function _srch_cp(::Fwd, cus, str, cp, pos, len)
@@ -423,7 +423,7 @@ occurs_in(needle::Char, hay::Str) = _occurs_in(needle, hay)
423423
occurs_in(needle::Str, hay::Str) = _occurs_in(needle, hay)
424424

425425
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)
427427
in(pat::Str, str::AbstractString) = _occurs_in(pat, str)
428428
in(pat::AbstractString, str::Str) = _occurs_in(pat, str)
429429
in(pat::Str, str::Str) = _occurs_in(pat, str)

src/traits.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ValidatedStyle(::Type{<:AbstractString}) = UnknownValidity()
55
ValidatedStyle(::Type{<:Str}) = AlwaysValid()
66

7-
ValidatedStyle(A::T) where {T<:Union{AbsChar,AbstractString}} = ValidatedStyle(T)
7+
ValidatedStyle(A::T) where {T<:Union{AbstractChar,AbstractString}} = ValidatedStyle(T)
88

99
CharSetStyle(::Type{<:Str{C}}) where {C<:CSE} = CharSetStyle(C)
1010

src/utf16search.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#=
22
Optimized search functions for UTF16Str
33
4-
Copyright 2017-2018 Gandalf Software, Inc., Scott P. Jones
4+
Copyright 2017-2020 Gandalf Software, Inc., Scott P. Jones
55
Licensed under MIT License, see LICENSE.md
66
=#
77

8-
function _srch_cp(::Fwd, ::MultiCU, str::Str{UTF16CSE}, cp::AbsChar, pos, len)
8+
function _srch_cp(::Fwd, ::MultiCU, str::Str{UTF16CSE}, cp::AbstractChar, pos, len)
99
@preserve str begin
1010
beg = pointer(str)
1111
(ch = codepoint(cp)) <= 0x0ffff && return _srch_codeunit(Fwd(), beg, ch%UInt16, pos, len)
@@ -24,7 +24,7 @@ function _srch_cp(::Fwd, ::MultiCU, str::Str{UTF16CSE}, cp::AbsChar, pos, len)
2424
end
2525
end
2626

27-
function _srch_cp(::Rev, ::MultiCU, str::Str{UTF16CSE}, cp::AbsChar, pos, len)
27+
function _srch_cp(::Rev, ::MultiCU, str::Str{UTF16CSE}, cp::AbstractChar, pos, len)
2828
@preserve str begin
2929
beg = pointer(str)
3030
(ch = codepoint(cp)) <= 0x0ffff && _srch_codeunit(Rev(), beg, ch%UInt16, pos)

src/utf8search.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#=
22
Optimized search functions for UTFStr (UTF-8 encoding)
33
4-
Copyright 2017-2018 Gandalf Software, Inc., Scott P. Jones
4+
Copyright 2017-2020 Gandalf Software, Inc., Scott P. Jones
55
Licensed under MIT License, see LICENSE.md
66
=#
7-
function _srch_cp(::Fwd, ::MultiCU, str::Str{UTF8CSE}, cp::AbsChar, pos, len)
7+
function _srch_cp(::Fwd, ::MultiCU, str::Str{UTF8CSE}, cp::AbstractChar, pos, len)
88
@preserve str begin
99
(ch = codepoint(cp)) < 0x80 &&
1010
return _srch_codeunit(Fwd(), pointer(str), ch%UInt8, pos, len)
@@ -33,7 +33,7 @@ function _srch_cp(::Fwd, ::MultiCU, str::Str{UTF8CSE}, cp::AbsChar, pos, len)
3333
end
3434
end
3535

36-
function _srch_cp(::Rev, ::MultiCU, str::Str{UTF8CSE}, cp::AbsChar, pos, len)
36+
function _srch_cp(::Rev, ::MultiCU, str::Str{UTF8CSE}, cp::AbstractChar, pos, len)
3737
@preserve str begin
3838
(ch = codepoint(cp)) < 0x80 && return _srch_codeunit(Rev(), pointer(str), ch%UInt8, pos)
3939
init = beg = pointer(str)

src/util.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#=
22
Utility functions for Str strings
33
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
56
Licensed under MIT License, see LICENSE.md
67
Based initially on julia/test/strings/util.jl
78
=#
@@ -43,7 +44,7 @@ lpad(str::MaybeSub{<:Str}, cnt::Integer, pad::AbstractString) =
4344
(cnt -= length(str)) <= 0 ? str : _lpad(cnt, pad, str)
4445
lpad(ch::Chr, cnt::Integer, pad::AbstractString) =
4546
(cnt -= 1) <= 0 ? string(ch) : _lpad(cnt, pad, ch)
46-
lpad(str::MaybeSub{<:Str}, cnt::Integer, pad::AbsChar=' ') =
47+
lpad(str::MaybeSub{<:Str}, cnt::Integer, pad::AbstractChar=' ') =
4748
(cnt -= length(str)) <= 0 ? str : string(pad^cnt, str)
4849
lpad(ch::Chr, cnt::Integer, pad::AbstractChar=' ') =
4950
(cnt -= 1) <= 0 ? string(ch) : string(pad^cnt, ch)
@@ -56,12 +57,13 @@ rpad(str::MaybeSub{<:Str}, cnt::Integer, pad::AbstractString) =
5657
(cnt -= length(str)) <= 0 ? str : _rpad(cnt, pad, str)
5758
rpad(ch::Chr, cnt::Integer, pad::AbstractString) =
5859
(cnt -= 1) <= 0 ? string(ch) : _rpad(cnt, pad, ch)
59-
rpad(str::MaybeSub{<:Str}, cnt::Integer, pad::AbsChar=' ') =
60+
rpad(str::MaybeSub{<:Str}, cnt::Integer, pad::AbstractChar=' ') =
6061
(cnt -= length(str)) <= 0 ? str : string(str, pad^cnt)
61-
rpad(ch::Chr, cnt::Integer, pad::AbsChar=' ') =
62+
rpad(ch::Chr, cnt::Integer, pad::AbstractChar=' ') =
6263
(cnt -= 1) <= 0 ? string(ch) : string(ch, pad^cnt)
6364

64-
const SetOfChars = Union{Tuple{Vararg{<:AbsChar}},AbstractVector{<:AbsChar},Set{<:AbsChar}}
65+
const SetOfChars =
66+
Union{Tuple{Vararg{<:AbstractChar}},AbstractVector{<:AbstractChar},Set{<:AbstractChar}}
6567

6668
function __split(str, splitter, limit::Integer, keep_empty::Bool, strs::Vector)
6769
pos = 1

0 commit comments

Comments
 (0)