Skip to main content

ct_regex_internal/matcher/
primitive.rs

1use std::fmt::{self, Debug};
2
3use crate::expr::IndexedCaptures;
4use crate::haystack::{HaystackItem, HaystackOf};
5use crate::matcher::{Matcher, impl_all_captures_single, impl_all_matches_single};
6use crate::sealed::Sealed;
7
8#[derive(#[automatically_derived]
impl<const N : u8> ::core::default::Default for Byte<N> {
    #[inline]
    fn default() -> Byte<N> { Byte {} }
}Default, #[automatically_derived]
impl<const N : u8> ::core::clone::Clone for Byte<N> {
    #[inline]
    fn clone(&self) -> Byte<N> { *self }
}Clone, #[automatically_derived]
impl<const N : u8> ::core::marker::Copy for Byte<N> { }Copy)]
9pub struct Byte<const N: u8>;
10
11impl<const N: u8> Sealed for Byte<N> {}
12
13impl<const N: u8> Matcher<u8> for Byte<N> {
14    fn matches<'a, H: HaystackOf<'a, u8>>(hay: &mut H) -> bool {
15        if hay.item() == Some(N) {
16            hay.progress();
17            true
18        } else {
19            false
20        }
21    }
22
23    u8
crate::matcher::AllMatchesSingle
u8
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<u8, H, Self>(hay);impl_all_matches_single!(u8);
24    u8
crate::matcher::AllCapturesSingle
u8
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<u8, H, Self>(hay, caps);impl_all_captures_single!(u8);
25}
26
27impl<const N: u8> Debug for Byte<N> {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        f.write_fmt(format_args!("{0:#04x}", N))write!(f, "{N:#04x}")
30    }
31}
32
33#[derive(#[automatically_derived]
impl<const A : u8, const B : u8> ::core::default::Default for ByteRange<A, B>
    {
    #[inline]
    fn default() -> ByteRange<A, B> { ByteRange {} }
}Default, #[automatically_derived]
impl<const A : u8, const B : u8> ::core::clone::Clone for ByteRange<A, B> {
    #[inline]
    fn clone(&self) -> ByteRange<A, B> { *self }
}Clone, #[automatically_derived]
impl<const A : u8, const B : u8> ::core::marker::Copy for ByteRange<A, B> { }Copy)]
34pub struct ByteRange<const A: u8, const B: u8>;
35
36impl<const A: u8, const B: u8> Sealed for ByteRange<A, B> {}
37
38impl<const A: u8, const B: u8> Matcher<u8> for ByteRange<A, B> {
39    fn matches<'a, H: HaystackOf<'a, u8>>(hay: &mut H) -> bool {
40        if let Some(byte) = hay.item()
41            && A <= byte
42            && byte <= B
43        {
44            hay.progress();
45            true
46        } else {
47            false
48        }
49    }
50
51    u8
crate::matcher::AllMatchesSingle
u8
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<u8, H, Self>(hay);impl_all_matches_single!(u8);
52    u8
crate::matcher::AllCapturesSingle
u8
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<u8, H, Self>(hay, caps);impl_all_captures_single!(u8);
53}
54
55impl<const A: u8, const B: u8> Debug for ByteRange<A, B> {
56    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57        f.write_fmt(format_args!("[{0:#04x}-{1:#04x}]", A, B))write!(f, "[{A:#04x}-{B:#04x}]")
58    }
59}
60
61#[derive(#[automatically_derived]
impl<const N : char> ::core::default::Default for Scalar<N> {
    #[inline]
    fn default() -> Scalar<N> { Scalar {} }
}Default, #[automatically_derived]
impl<const N : char> ::core::clone::Clone for Scalar<N> {
    #[inline]
    fn clone(&self) -> Scalar<N> { *self }
}Clone, #[automatically_derived]
impl<const N : char> ::core::marker::Copy for Scalar<N> { }Copy)]
62pub struct Scalar<const N: char>;
63
64impl<const N: char> Sealed for Scalar<N> {}
65
66impl<const N: char> Matcher<char> for Scalar<N> {
67    fn matches<'a, H: HaystackOf<'a, char>>(hay: &mut H) -> bool {
68        if hay.item() == Some(N) {
69            hay.progress();
70            true
71        } else {
72            false
73        }
74    }
75
76    char
crate::matcher::AllMatchesSingle
char
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<char, H, Self>(hay);impl_all_matches_single!(char);
77    char
crate::matcher::AllCapturesSingle
char
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<char, H, Self>(hay, caps);impl_all_captures_single!(char);
78}
79
80impl<const N: char> Debug for Scalar<N> {
81    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82        f.write_fmt(format_args!("{0}", N.escape_debug()))write!(f, "{}", N.escape_debug())
83    }
84}
85
86#[derive(#[automatically_derived]
impl<const A : char, const B : char> ::core::default::Default for
    ScalarRange<A, B> {
    #[inline]
    fn default() -> ScalarRange<A, B> { ScalarRange {} }
}Default, #[automatically_derived]
impl<const A : char, const B : char> ::core::clone::Clone for
    ScalarRange<A, B> {
    #[inline]
    fn clone(&self) -> ScalarRange<A, B> { *self }
}Clone, #[automatically_derived]
impl<const A : char, const B : char> ::core::marker::Copy for
    ScalarRange<A, B> {
}Copy)]
87pub struct ScalarRange<const A: char, const B: char>;
88
89impl<const A: char, const B: char> Sealed for ScalarRange<A, B> {}
90
91impl<const A: char, const B: char> Matcher<char> for ScalarRange<A, B> {
92    fn matches<'a, H: HaystackOf<'a, char>>(hay: &mut H) -> bool {
93        if let Some(scalar) = hay.item()
94            && A <= scalar
95            && scalar <= B
96        {
97            hay.progress();
98            true
99        } else {
100            false
101        }
102    }
103
104    char
crate::matcher::AllMatchesSingle
char
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<char, H, Self>(hay);impl_all_matches_single!(char);
105    char
crate::matcher::AllCapturesSingle
char
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<char, H, Self>(hay, caps);impl_all_captures_single!(char);
106}
107
108impl<const A: char, const B: char> Debug for ScalarRange<A, B> {
109    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110        f.write_fmt(format_args!("[{0}-{1}]", A.escape_debug(), B.escape_debug()))write!(f, "[{}-{}]", A.escape_debug(), B.escape_debug())
111    }
112}
113
114#[derive(#[automatically_derived]
impl ::core::default::Default for Always {
    #[inline]
    fn default() -> Always { Always {} }
}Default, #[automatically_derived]
impl ::core::clone::Clone for Always {
    #[inline]
    fn clone(&self) -> Always { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Always { }Copy)]
115pub struct Always;
116
117impl Sealed for Always {}
118
119impl<I: HaystackItem> Matcher<I> for Always {
120    fn matches<'a, H: HaystackOf<'a, I>>(_hay: &mut H) -> bool {
121        true
122    }
123
124    I
crate::matcher::AllMatchesSingle
I
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<I, H, Self>(hay);impl_all_matches_single!(I);
125    I
crate::matcher::AllCapturesSingle
I
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<I, H, Self>(hay, caps);impl_all_captures_single!(I);
126}
127
128impl Debug for Always {
129    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
130        f.write_fmt(format_args!("()"))write!(f, "()")
131    }
132}
133
134#[derive(#[automatically_derived]
impl ::core::default::Default for Start {
    #[inline]
    fn default() -> Start { Start {} }
}Default, #[automatically_derived]
impl ::core::clone::Clone for Start {
    #[inline]
    fn clone(&self) -> Start { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Start { }Copy)]
135pub struct Start;
136
137impl Sealed for Start {}
138
139impl<I: HaystackItem> Matcher<I> for Start {
140    fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool {
141        hay.is_start()
142    }
143
144    I
crate::matcher::AllMatchesSingle
I
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<I, H, Self>(hay);impl_all_matches_single!(I);
145    I
crate::matcher::AllCapturesSingle
I
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<I, H, Self>(hay, caps);impl_all_captures_single!(I);
146}
147
148impl Debug for Start {
149    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
150        f.write_fmt(format_args!("\\A"))write!(f, "\\A")
151    }
152}
153
154#[derive(#[automatically_derived]
impl ::core::default::Default for End {
    #[inline]
    fn default() -> End { End {} }
}Default, #[automatically_derived]
impl ::core::clone::Clone for End {
    #[inline]
    fn clone(&self) -> End { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for End { }Copy)]
155pub struct End;
156
157impl Sealed for End {}
158
159impl<I: HaystackItem> Matcher<I> for End {
160    fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool {
161        hay.is_end()
162    }
163
164    I
crate::matcher::AllMatchesSingle
I
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<I, H, Self>(hay);impl_all_matches_single!(I);
165    I
crate::matcher::AllCapturesSingle
I
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<I, H, Self>(hay, caps);impl_all_captures_single!(I);
166}
167
168impl Debug for End {
169    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
170        f.write_fmt(format_args!("\\z"))write!(f, "\\z")
171    }
172}
173
174#[derive(#[automatically_derived]
impl ::core::default::Default for LineStart {
    #[inline]
    fn default() -> LineStart { LineStart {} }
}Default, #[automatically_derived]
impl ::core::clone::Clone for LineStart {
    #[inline]
    fn clone(&self) -> LineStart { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for LineStart { }Copy)]
175pub struct LineStart;
176
177impl Sealed for LineStart {}
178
179impl<I: HaystackItem> Matcher<I> for LineStart {
180    fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool {
181        hay.is_line_start()
182    }
183
184    I
crate::matcher::AllMatchesSingle
I
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<I, H, Self>(hay);impl_all_matches_single!(I);
185    I
crate::matcher::AllCapturesSingle
I
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<I, H, Self>(hay, caps);impl_all_captures_single!(I);
186}
187
188impl Debug for LineStart {
189    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
190        f.write_fmt(format_args!("^"))write!(f, "^")
191    }
192}
193
194#[derive(#[automatically_derived]
impl ::core::default::Default for LineEnd {
    #[inline]
    fn default() -> LineEnd { LineEnd {} }
}Default, #[automatically_derived]
impl ::core::clone::Clone for LineEnd {
    #[inline]
    fn clone(&self) -> LineEnd { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for LineEnd { }Copy)]
195pub struct LineEnd;
196
197impl Sealed for LineEnd {}
198
199impl<I: HaystackItem> Matcher<I> for LineEnd {
200    fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool {
201        hay.is_line_end()
202    }
203
204    I
crate::matcher::AllMatchesSingle
I
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<I, H, Self>(hay);impl_all_matches_single!(I);
205    I
crate::matcher::AllCapturesSingle
I
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<I, H, Self>(hay, caps);impl_all_captures_single!(I);
206}
207
208impl Debug for LineEnd {
209    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
210        f.write_fmt(format_args!("$"))write!(f, "$")
211    }
212}
213
214#[derive(#[automatically_derived]
impl ::core::default::Default for CRLFStart {
    #[inline]
    fn default() -> CRLFStart { CRLFStart {} }
}Default, #[automatically_derived]
impl ::core::clone::Clone for CRLFStart {
    #[inline]
    fn clone(&self) -> CRLFStart { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CRLFStart { }Copy)]
215pub struct CRLFStart;
216
217impl Sealed for CRLFStart {}
218
219impl<I: HaystackItem> Matcher<I> for CRLFStart {
220    fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool {
221        hay.is_crlf_start()
222    }
223
224    I
crate::matcher::AllMatchesSingle
I
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<I, H, Self>(hay);impl_all_matches_single!(I);
225    I
crate::matcher::AllCapturesSingle
I
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<I, H, Self>(hay, caps);impl_all_captures_single!(I);
226}
227
228impl Debug for CRLFStart {
229    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
230        f.write_fmt(format_args!("^"))write!(f, "^")
231    }
232}
233
234#[derive(#[automatically_derived]
impl ::core::default::Default for CRLFEnd {
    #[inline]
    fn default() -> CRLFEnd { CRLFEnd {} }
}Default, #[automatically_derived]
impl ::core::clone::Clone for CRLFEnd {
    #[inline]
    fn clone(&self) -> CRLFEnd { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CRLFEnd { }Copy)]
235pub struct CRLFEnd;
236
237impl Sealed for CRLFEnd {}
238
239impl<I: HaystackItem> Matcher<I> for CRLFEnd {
240    fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool {
241        hay.is_crlf_end()
242    }
243
244    I
crate::matcher::AllMatchesSingle
I
&mut H
hay
Self::AllMatches<'a, H>
crate::matcher::all_matches_single::<I, H, Self>(hay);impl_all_matches_single!(I);
245    I
crate::matcher::AllCapturesSingle
I
&mut H
hay
&mut IndexedCaptures
caps
Self::AllCaptures<'a, H>
crate::matcher::all_captures_single::<I, H, Self>(hay, caps);impl_all_captures_single!(I);
246}
247
248impl Debug for CRLFEnd {
249    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
250        f.write_fmt(format_args!("$"))write!(f, "$")
251    }
252}