Skip to content

Commit 4e1759c

Browse files
KristofferCKristofferC
authored and
KristofferC
committed
fix eltype for partition iterators of substrings (#51773)
Fixes #51771 The convert method that asserts in #51771 is arguably still faulty though. (cherry picked from commit cf00550)
1 parent 7ae1535 commit 4e1759c

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

base/strings/util.jl

+2
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ end
571571

572572
# Specialization for partition(s,n) to return a SubString
573573
eltype(::Type{PartitionIterator{T}}) where {T<:AbstractString} = SubString{T}
574+
# SubStrings do not nest
575+
eltype(::Type{PartitionIterator{T}}) where {T<:SubString} = T
574576

575577
function iterate(itr::PartitionIterator{<:AbstractString}, state = firstindex(itr.c))
576578
state > ncodeunits(itr.c) && return nothing

test/iterators.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1001,3 +1001,7 @@ end
10011001
end
10021002
@test v == ()
10031003
end
1004+
1005+
@testset "collect partition substring" begin
1006+
@test collect(Iterators.partition(lstrip("01111", '0'), 2)) == ["11", "11"]
1007+
end

0 commit comments

Comments
 (0)