Skip to content

Commit cf00550

Browse files
authored
fix eltype for partition iterators of substrings (#51773)
Fixes #51771 The convert method that asserts in #51771 is arguably still faulty though.
1 parent 37611b4 commit cf00550

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

base/strings/util.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ end
575575

576576
# Specialization for partition(s,n) to return a SubString
577577
eltype(::Type{PartitionIterator{T}}) where {T<:AbstractString} = SubString{T}
578+
# SubStrings do not nest
579+
eltype(::Type{PartitionIterator{T}}) where {T<:SubString} = T
578580

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

test/iterators.jl

Lines changed: 4 additions & 0 deletions
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)