pub enum RegexCount {
Default,
Bytes(NonZeroU32),
Lines(Option<NonZeroU32>),
}Expand description
Scan window specifier for a TypeKind::Regex rule.
Encodes the three mutually-exclusive scan modes in a single enum so
that the “byte count” and “line count” cases cannot be confused. The
regex/l shorthand (line mode with no explicit count) is represented
explicitly as RegexCount::Lines(None), which
is behaviorally equivalent to RegexCount::Default – both walk
the full 8192-byte capped window – but preserves the magic-file
surface syntax of the original rule. The 8192-byte hard cap
(matching GNU file’s FILE_REGEX_MAX) is applied by the evaluator
on every variant.
§Examples
use libmagic_rs::parser::ast::RegexCount;
use std::num::NonZeroU32;
// Plain `regex` (no suffix): default 8192-byte window.
assert_eq!(RegexCount::default(), RegexCount::Default);
// `regex/100`: scan at most 100 bytes.
let hundred_bytes = RegexCount::Bytes(NonZeroU32::new(100).unwrap());
// `regex/1l`: scan the first line.
let one_line = RegexCount::Lines(NonZeroU32::new(1));
// `regex/l`: line-mode with no explicit count (walks terminators
// to the end of the 8192-byte capped window).
let unbounded_lines = RegexCount::Lines(None);Variants§
Default
No scan bound (plain regex with no suffix). Scans the default
8192-byte window from the rule’s offset.
Bytes(NonZeroU32)
Byte-bounded scan (regex/N with no /l flag). The window is
min(n, 8192, remaining_buffer) bytes long. NonZeroU32 makes
a zero-byte scan unrepresentable.
Lines(Option<NonZeroU32>)
Line-bounded scan (regex/Nl or regex/l). The window walks
LF / CRLF / bare CR line terminators from the offset. With
Some(n), the walk stops after the Nth terminator (inclusive).
With None (the regex/l shorthand), the walk continues to
the end of the 8192-byte capped window. Either way the
effective byte window is capped at 8192.
Trait Implementations§
Source§impl Clone for RegexCount
impl Clone for RegexCount
Source§fn clone(&self) -> RegexCount
fn clone(&self) -> RegexCount
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more