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.
  • Loading branch information
KristofferC committed Oct 23, 2023
1 parent 37611b4 commit cf00550
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 @@ -575,6 +575,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 cf00550

Please sign in to comment.