Skip to content

Commit

Permalink
fix eltype for partition iterators of substrings (#51773)
Browse files Browse the repository at this point in the history
Fixes #51771

The convert method that asserts in #51771 is arguably still faulty
though.

(cherry picked from commit cf00550)
  • Loading branch information
KristofferC authored and KristofferC committed Oct 24, 2023
1 parent 7ae1535 commit 4e1759c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ end

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

function iterate(itr::PartitionIterator{<:AbstractString}, state = firstindex(itr.c))
state > ncodeunits(itr.c) && return nothing
Expand Down
4 changes: 4 additions & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1001,3 +1001,7 @@ end
end
@test v == ()
end

@testset "collect partition substring" begin
@test collect(Iterators.partition(lstrip("01111", '0'), 2)) == ["11", "11"]
end

0 comments on commit 4e1759c

Please sign in to comment.