1use super::AsciiByte;
2
3pub(crate) struct PatternCtor<T>(pub(crate) T);
4
5impl PatternCtor<u8> {
6 pub(crate) const fn conv(self) -> Pattern {
7 Pattern::AsciiByte(AsciiByte::new(self.0))
8 }
9}
10
11impl PatternCtor<&'static str> {
12 pub(crate) const fn conv(self) -> Pattern {
13 if let [b: u8 @ 0..=127] = *self.0.as_bytes() {
14 Pattern::AsciiByte(AsciiByte::new(byte:b))
15 } else {
16 Pattern::Str(self.0)
17 }
18 }
19}
20
21impl PatternCtor<char> {
22 pub(crate) const fn conv(self) -> Pattern {
23 let code: u32 = self.0 as u32;
24 if let c: u32 @ 0..=127 = code {
25 Pattern::AsciiByte(AsciiByte::new(byte:c as u8))
26 } else {
27 Pattern::Char(crate::char_encoding::char_to_display(self.0))
28 }
29 }
30}
31
32#[derive(Copy, Clone)]
33pub(crate) enum Pattern {
34 AsciiByte(AsciiByte),
35 Str(&'static str),
36 Char(crate::char_encoding::FmtChar),
37}
38
39pub(crate) enum PatternNorm<'a> {
40 AsciiByte(AsciiByte),
41 Str(&'a [u8]),
42}
43
44impl Pattern {
45 pub(crate) const fn normalize(&self) -> PatternNorm<'_> {
46 match self {
47 Pattern::AsciiByte(ab: &AsciiByte) => PatternNorm::AsciiByte(*ab),
48 Pattern::Str(str: &&str) => PatternNorm::Str(str.as_bytes()),
49 Pattern::Char(char: &FmtChar) => PatternNorm::Str(char.as_bytes()),
50 }
51 }
52}
53