RFC: Added an FindIterator to str #9442
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements an
FindIterator
with.find_iter()
and.find_rev_iter()
on string slices that works like.find()
and.rfind()
, but returns all matches instead of just the first one.This touches upon a few other design questions I'm having of the string library:
_rev
, which has met some resistance. This PR would allow removing at leastfind()
andrfind()
completely and replace them with this Iterator._rev
suffix completly - see Should the reverse iterators on strings and vectors be removed? #9391."foo".find_iter('o').nth(0)
and"foo".find_iter('f').invert().nth(0)
would become quite long though, which touches on Consider removing the_iter
suffixes on specialized Iterator constructors #9440.Also as part of this PR I'm moving
str::CharEq
tochar::CharEq
, introduce a new traitToChar
, and implement them both forascii::Ascii
.I'm doing the movement of
CharEq
because it seems to me that even though it's being intended to be used by string functions, the actual trait encapsulates something relevant for chars in general. Andstr.rs
needs any chance it can get to become shorter. ;)The
ToChar
trait is necessary for the implementation ofFindIterator
to not include two almost identical copies of the same function in bothnext()
andnext_back()