pub struct RegexFlags {
pub case_insensitive: bool,
pub start_offset: bool,
}Expand description
Regex modifier flags parsed from the /[cs] suffix on a regex rule.
The /l “line-based window” modifier is not represented here; it
lives on RegexCount::Lines so that the type-level encoding makes
“line count” and “byte count” mutually exclusive. An earlier design
used two separate fields (line_based: bool + count: Option<u32>)
which admitted the cross-field state line_based: true, count: None;
under the current encoding that case is expressed explicitly as
RegexCount::Lines(None) – the regex/l
shorthand – and is behaviorally equivalent to RegexCount::Default
(both walk the full 8192-byte capped window).
All flags default to false via RegexFlags::default, equivalent
to a plain regex with no /c or /s suffix.
§Examples
use libmagic_rs::parser::ast::RegexFlags;
let plain = RegexFlags::default();
assert!(!plain.case_insensitive);
assert!(!plain.start_offset);
let case_and_start = RegexFlags::default()
.with_case_insensitive(true)
.with_start_offset(true);
assert!(case_and_start.case_insensitive);
assert!(case_and_start.start_offset);Fields§
§case_insensitive: bool/c – case-insensitive matching. When true, ASCII letter
casing is ignored during pattern matching.
start_offset: bool/s – advance the GNU file previous-match anchor to the start
of the matched region instead of its end. Matches libmagic’s
REGEX_OFFSET_START flag, which zeros the length contribution in
moffset() for FILE_REGEX. Useful for chaining child rules that
need to re-match from the position where the parent regex began.
Implementations§
Source§impl RegexFlags
impl RegexFlags
Sourcepub const fn with_case_insensitive(self, value: bool) -> Self
pub const fn with_case_insensitive(self, value: bool) -> Self
Builder-style setter for RegexFlags::case_insensitive (/c).
Chain after RegexFlags::default() to construct RegexFlags
values without exhaustive struct literals. If a new flag is
added to RegexFlags in the future, callers using the builder
form keep compiling; callers using struct literals would need
an update.
Sourcepub const fn with_start_offset(self, value: bool) -> Self
pub const fn with_start_offset(self, value: bool) -> Self
Builder-style setter for RegexFlags::start_offset (/s).
Chain after RegexFlags::default() to construct RegexFlags
values without exhaustive struct literals.
Trait Implementations§
Source§impl Clone for RegexFlags
impl Clone for RegexFlags
Source§fn clone(&self) -> RegexFlags
fn clone(&self) -> RegexFlags
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more