Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit 4e6b271

Browse files
committed
introduce SearchIter
1 parent 26a78db commit 4e6b271

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/engine.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,32 @@ impl<S: StrDrive> State<S> {
282282
}
283283
}
284284

285+
pub struct SearchIter<'a, S: StrDrive> {
286+
pub req: Request<'a, S>,
287+
pub state: State<S>,
288+
}
289+
290+
impl<'a, S: StrDrive> Iterator for SearchIter<'a, S> {
291+
type Item = ();
292+
293+
fn next(&mut self) -> Option<Self::Item> {
294+
if self.req.start > self.req.end {
295+
return None;
296+
}
297+
298+
self.state.reset(self.req.start);
299+
self.state.search(self.req);
300+
if !self.state.has_matched {
301+
return None;
302+
}
303+
304+
self.req.must_advance = self.state.string_position == self.state.start;
305+
self.req.start = self.state.string_position;
306+
307+
Some(())
308+
}
309+
}
310+
285311
fn dispatch<S: StrDrive>(
286312
req: &Request<S>,
287313
state: &mut State<S>,

tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ fn test_info_literal2() {
126126
let (req, mut state) = p.state("pythonpython");
127127
state.search(req);
128128
assert!(state.has_matched);
129-
}
129+
}

0 commit comments

Comments
 (0)