easy_regex/settings/
mod.rs1pub mod base;
12pub mod group;
13
14#[derive(Clone, Copy)]
15pub enum Flags {
17 Insensitive,
18 Multiline,
19 DotMatchNewLine,
20 IgnoreWhitespace,
21 Sensitive,
22 SingleLine,
23 DotDisMatchNewLine,
24 IncludeWhitespace,
25}
26
27impl Flags {
28 pub fn as_str(&self) -> &'static str {
37 match self {
38 Flags::Insensitive => "?i",
39 Flags::Multiline => "?m",
40 Flags::DotMatchNewLine => "?s",
41 Flags::IgnoreWhitespace => "?x",
42 Flags::Sensitive => "?-i",
43 Flags::SingleLine => "?-m",
44 Flags::DotDisMatchNewLine => "?-s",
45 Flags::IncludeWhitespace => "?-x",
46 }
47 }
48}
49
50pub struct Settings {
52 pub is_optional: bool,
53 pub is_optional_ungreedy: bool,
54 pub is_one_or_more: bool,
55 pub is_nil_or_more: bool,
56 pub with_left_boundary: bool,
57 pub with_left_non_boundary: bool,
58 pub with_right_boundary: bool,
59 pub with_right_non_boundary: bool,
60 pub range: Option<(Option<u8>, Option<u8>)>,
61 pub exactly: Option<u8>,
62 pub flags: Option<Flags>,
63}
64
65impl Default for Settings {
66 fn default() -> Self {
67 Settings {
68 is_optional: false,
69 is_optional_ungreedy: false,
70 is_one_or_more: false,
71 is_nil_or_more: false,
72 with_left_boundary: false,
73 with_left_non_boundary: false,
74 with_right_boundary: false,
75 with_right_non_boundary: false,
76 range: None,
77 exactly: None,
78 flags: None,
79 }
80 }
81}
82
83impl Settings {
84 pub fn exactly(number: u8) -> Self {
85 Settings {
86 exactly: Some(number),
87 ..Default::default()
88 }
89 }
90
91 pub fn range(from: Option<u8>, to: Option<u8>) -> Self {
92 Settings {
93 range: Some((from, to)),
94 ..Default::default()
95 }
96 }
97}
98
99pub struct GroupSettings {
101 pub other: Settings,
102 pub is_non_capture: bool,
103}
104
105impl Default for GroupSettings {
106 fn default() -> Self {
107 GroupSettings {
108 other: Settings::default(),
109 is_non_capture: false,
110 }
111 }
112}
113
114impl GroupSettings {
115 pub fn grp_exactly(number: u8) -> Self {
116 GroupSettings {
117 other: Settings {
118 exactly: Some(number),
119 ..Default::default()
120 },
121 ..Default::default()
122 }
123 }
124
125 pub fn grp_range(from: Option<u8>, to: Option<u8>) -> Self {
126 GroupSettings {
127 other: Settings {
128 range: Some((from, to)),
129 ..Default::default()
130 },
131 ..Default::default()
132 }
133 }
134}