1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use crate::temex_match::TemexMatch;
use std::iter::FusedIterator;

/// An iterator over all non-overlapping matches of a trace.
///
/// The iterator yields a `TemexMatch` value. The iterator stops when no
/// more matches can be found.
pub struct TemexMatches<'r, 't> {
    pub re_matches: regex::bytes::Matches<'r, 't>,
    pub(crate) width: usize,
}

impl Iterator for TemexMatches<'_, '_> {
    type Item = TemexMatch;

    fn next(&mut self) -> Option<TemexMatch> {
        let re_match = self.re_matches.next()?;

        let start = re_match.start() / self.width;
        let end = re_match.end() / self.width;

        Some(TemexMatch { start, end })
    }
}

impl FusedIterator for TemexMatches<'_, '_> {}