ct_regex_internal/matcher/
capture.rs

1use std::{fmt::{self, Debug}, marker::PhantomData};
2
3use crate::{expr::IndexedCaptures, haystack::{HaystackItem, HaystackOf}, matcher::Matcher};
4
5#[derive(#[automatically_derived]
impl<I: ::core::default::Default + HaystackItem, A: ::core::default::Default +
    Matcher<I>, const N : usize> ::core::default::Default for
    CaptureGroup<I, A, N> {
    #[inline]
    fn default() -> CaptureGroup<I, A, N> {
        CaptureGroup(::core::default::Default::default(),
            ::core::default::Default::default())
    }
}Default)]
6pub struct CaptureGroup<I: HaystackItem, A: Matcher<I>, const N: usize>(
7    pub PhantomData<I>,
8    pub PhantomData<A>,
9);
10
11impl<I: HaystackItem, A: Matcher<I>, const N: usize> Matcher<I> for CaptureGroup<I, A, N> {
12    fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool {
13        A::matches(hay)
14    }
15
16    fn all_matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> Vec<usize> {
17        A::all_matches(hay)
18    }
19
20    fn captures<'a, H: HaystackOf<'a, I>>(hay: &mut H, caps: &mut IndexedCaptures) -> bool {
21        let start = hay.index();
22        if A::captures(hay, caps) {
23            caps.push(N, start..hay.index());
24            true
25        } else {
26            false
27        }
28    }
29
30    fn all_captures<'a, H: HaystackOf<'a, I>>(
31        hay: &mut H,
32        caps: &mut IndexedCaptures
33    ) -> Vec<(usize, IndexedCaptures)> {
34        let start = hay.index();
35        let mut captures = A::all_captures(hay, caps);
36
37        for (state_fork, caps_fork) in captures.iter_mut() {
38            caps_fork.push(N, start..*state_fork);
39        }
40
41        captures
42    }
43}
44
45impl<I: HaystackItem, A: Matcher<I>, const N: usize> Debug for CaptureGroup<I, A, N> {
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        f.write_fmt(format_args!("({0:?})", A::default()))write!(f, "({:?})", A::default())
48    }
49}