ct_regex_internal/expr/
captures.rs1use std::fmt::Debug;
2use std::ops::Range;
3
4use crate::haystack::HaystackSlice;
5use crate::util::cons_tree::ConsBranch;
6
7#[derive(#[automatically_derived]
impl ::core::fmt::Debug for IndexedCaptures {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"IndexedCaptures", &&self.0)
}
}Debug, #[automatically_derived]
impl ::core::default::Default for IndexedCaptures {
#[inline]
fn default() -> IndexedCaptures {
IndexedCaptures(::core::default::Default::default())
}
}Default, #[automatically_derived]
impl ::core::clone::Clone for IndexedCaptures {
#[inline]
fn clone(&self) -> IndexedCaptures {
IndexedCaptures(::core::clone::Clone::clone(&self.0))
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for IndexedCaptures {
#[inline]
fn eq(&self, other: &IndexedCaptures) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for IndexedCaptures {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ConsBranch<IndexedCapture>>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for IndexedCaptures {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash)]
8pub struct IndexedCaptures(pub ConsBranch<IndexedCapture>);
9
10#[derive(#[automatically_derived]
impl ::core::fmt::Debug for IndexedCapture {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"IndexedCapture", "index", &self.index, "cap", &&self.cap)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for IndexedCapture {
#[inline]
fn clone(&self) -> IndexedCapture {
IndexedCapture {
index: ::core::clone::Clone::clone(&self.index),
cap: ::core::clone::Clone::clone(&self.cap),
}
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for IndexedCapture {
#[inline]
fn eq(&self, other: &IndexedCapture) -> bool {
self.index == other.index && self.cap == other.cap
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for IndexedCapture {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<usize>;
let _: ::core::cmp::AssertParamIsEq<Range<usize>>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for IndexedCapture {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.index, state);
::core::hash::Hash::hash(&self.cap, state)
}
}Hash)]
11pub struct IndexedCapture {
12 pub index: usize,
13 pub cap: Range<usize>,
14}
15
16impl IndexedCaptures {
17 pub fn push(&mut self, index: usize, cap: Range<usize>) {
18 self.0.push(IndexedCapture { index, cap });
19 }
20
21 pub fn into_array<const N: usize>(self) -> [Option<Range<usize>>; N] {
24 let mut res = [const { None }; N];
25
26 for item in self.0.into_iter_owned() {
27 match res.get(item.index) {
28 None => {
::core::panicking::panic_fmt(format_args!("capture index exceeds maximum group number"));
}panic!("capture index exceeds maximum group number"),
29 Some(None) => res[item.index] = Some(item.cap.clone()),
30 Some(_) => (),
33 }
34 }
35
36 res
37 }
38}
39
40pub trait Capture<'a, S: HaystackSlice<'a>>: Debug {
41 fn whole_match_range(&self) -> Range<usize>;
42 fn whole_match(&self) -> S;
43}
44
45pub trait FromRanges<'a, S: HaystackSlice<'a>, const N: usize>: Sized + Debug {
46 fn from_ranges(ranges: [Option<Range<usize>>; N], slice: S) -> Option<Self>;
47}