Clarification on the `str::pattern::SearchStep`

I was going thrrough the Searcher api and came across this.

I was curious about the following line: "Note that there might be more than one Reject between two Matches, there is no requirement for them to be combined into one."

My confusion is this: if there are >1 Rejects between two Matches, what would that be ? In other words, the enum SearchStep contains only two variants: Match and Reject. In case a specific span in between two Matches is not a Reject, which is indicated by >1 Rejects, is there any state that specific span could occupy other than a Match ?

If I understand correctly, this simply means that this outcome is possible (in pseudocode):

let (m1, m2, m3, m4) = (,,,
assert!(matches!((m1, m2, m3, m4), (

I.e., if you got a Reject, you can't assume that the next call will not yield Reject too.

Ok. Thanks for your reply. I think I have understood it. I think the wordings are a bit nuanced, and correct.

I was assuming that the results of each next call would produce contiguous spans. That assumption is not correct. That is the only possible explanation. In other words, the start and end points of the spans m1, m2... need not be contiguous. They can jumping all around, depending on the algorithm in use. For a normal case, like Boyer Moore, or KMP, it's quite likely that they would be contiguous. However, the specs are a bit more generic than that, which is great !

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.