Skip to content

Commit 625850a

Browse files
committed
Update to not use start/next/done, for v1.0
1 parent 43a5fa0 commit 625850a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/compat.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ function Base.lstrip(s::AbstractString, chars::_Chars)
4040
SubString(s, e+1, e)
4141
end
4242

43+
@static if NEW_ITERATE
44+
using Iterators
45+
function Base.rstrip(f, s::AbstractString)
46+
for (i, c) in Iterators.reverse(pairs(s))
47+
f(c) || return SubString(s, 1, i)
48+
end
49+
SubString(s, 1, 0)
50+
end
51+
else
4352
function Base.rstrip(s::AbstractString, chars::_Chars)
4453
r = RevString(s)
4554
i = start(r)
@@ -50,6 +59,7 @@ function Base.rstrip(s::AbstractString, chars::_Chars)
5059
end
5160
s[1:0]
5261
end
62+
end
5363

5464
Base.strip(s::AbstractString, chars::_Chars) = lstrip(rstrip(s, chars), chars)
5565

test/basic.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,13 @@ mutable struct CharStr <: AbstractString
7171
chars::Vector{Char}
7272
CharStr(x) = new(collect(x))
7373
end
74-
start(x::CharStr) = 1
75-
next(x::CharStr, i::Int) = @static NEW_ITERATE ? iterate(x.chars, i) : next(x.chars, i)
76-
done(x::CharStr, i::Int) = i > length(x.chars)
77-
@static NEW_ITERATE && (iterate(x::CharStr, i::Int=1) = iterate(x.chars, i))
74+
@static if NEW_ITERATE
75+
literate(x::CharStr, i::Int=1) = iterate(x.chars, i)
76+
else
77+
start(x::CharStr) = 1
78+
next(x::CharStr, i::Int) = next(x.chars, i)
79+
done(x::CharStr, i::Int) = i > length(x.chars)
80+
end
7881

7982
lastindex(x::CharStr) = lastindex(x.chars)
8083
ncodeunits(x::CharStr) = lastindex(x.chars)

0 commit comments

Comments
 (0)