pub struct SearchFlags {
pub compact_whitespace: bool,
pub compact_optional_whitespace: bool,
pub ignore_lowercase: bool,
pub ignore_uppercase: bool,
pub text_test: bool,
pub trim: bool,
pub bin_test: bool,
pub full_word: bool,
pub start_anchor: bool,
}Expand description
Search modifier flags parsed from the /[sCcWwTtBbf] suffix on a
search rule.
Mirrors StringFlags for the eight STRING_* letters that alter
the literal-pattern comparison (/c, /C, /w, /W, /t, /T,
/b, /f), plus a search-only start_anchor field for /s which
shifts the GNU file previous-match anchor to the START of the
matched region. The default (all false) preserves byte-exact
comparison and match-END anchor advance.
SearchFlags is structurally parallel to StringFlags: when one
struct grows a field, the other gains the same field in lockstep
so that SearchFlags::to_string_flags can keep handing off to
compare_string_with_flags without a generic refactor. The
search-only start_anchor field has no analog in string rules.
/c vs /C are asymmetric in the same way as StringFlags:
the pattern character controls fold direction. See StringFlags
and GOTCHAS S6.5 for the rationale.
§Examples
use libmagic_rs::parser::ast::SearchFlags;
let plain = SearchFlags::default();
assert!(!plain.start_anchor);
assert!(plain.is_empty());
assert!(!plain.needs_byte_compare());
let start = SearchFlags::default().with_start_anchor(true);
assert!(start.start_anchor);
assert!(!start.is_empty());
// /s is anchor-only -- does not force the byte-compare slow path.
assert!(!start.needs_byte_compare());
let case = SearchFlags::default().with_ignore_lowercase(true);
assert!(case.needs_byte_compare());Fields§
§compact_whitespace: bool/W – STRING_COMPACT_WHITESPACE. Pattern whitespace requires at
least one whitespace byte in the file, then any further whitespace
in the file is consumed greedily.
compact_optional_whitespace: bool/w – STRING_COMPACT_OPTIONAL_WHITESPACE. Pattern whitespace
matches zero or more whitespace bytes in the file.
ignore_lowercase: bool/c – STRING_IGNORE_LOWERCASE. When the pattern char is
lowercase, the file byte is to_ascii_lowercase’d before
comparison. Uppercase pattern chars are compared literally.
ignore_uppercase: bool/C – STRING_IGNORE_UPPERCASE. When the pattern char is
uppercase, the file byte is to_ascii_uppercase’d before
comparison. Lowercase pattern chars are compared literally.
text_test: bool/t – STRING_TEXTTEST. Hint that this rule applies to text
files. Captured for MIME-output integration; does not currently
alter comparison.
trim: bool/T – STRING_TRIM. Trim leading and trailing ASCII whitespace
from the pattern before comparison.
bin_test: bool/b – STRING_BINTEST. Hint that this rule applies to binary
files. Captured for MIME-output integration; does not currently
alter comparison.
full_word: bool/f – STRING_FULL_WORD. Post-match check that the byte after
the matched region is either end-of-buffer or a non-word
character (ASCII alphanumeric or _).
start_anchor: bool/s – magic(5) “search-start” flag. When true, the GNU file
previous-match anchor advance lands on the match-START index
rather than match-END (the default). Mirrors libmagic’s
FILE_SEARCH anchor handling in src/softmagic.c::moffset. The
dispatch happens in
src/evaluator/types/search.rs::search_bytes_consumed.
Implementations§
Source§impl SearchFlags
impl SearchFlags
Sourcepub const fn is_empty(self) -> bool
pub const fn is_empty(self) -> bool
Returns true when every flag is false (default-constructed).
Sourcepub const fn needs_byte_compare(self) -> bool
pub const fn needs_byte_compare(self) -> bool
Returns true when any flag alters the literal-pattern
comparison, forcing the byte-walk slow path through
compare_string_with_flags. The anchor-only / metadata-only
flags (/s, /t, /b) do not trigger byte-compare;
they preserve the memchr::memmem::find fast path.
Sourcepub const fn to_string_flags(self) -> StringFlags
pub const fn to_string_flags(self) -> StringFlags
Project the eight shared flag fields onto a StringFlags for
handoff to compare_string_with_flags. The search-only
start_anchor field is dropped (it is anchor-advance policy,
not comparison policy).
§Examples
use libmagic_rs::parser::ast::SearchFlags;
let sf = SearchFlags::default()
.with_ignore_lowercase(true)
.with_trim(true)
.with_start_anchor(true);
let projected = sf.to_string_flags();
assert!(projected.ignore_lowercase);
assert!(projected.trim);
// /s has no analog in StringFlags.Sourcepub const fn with_compact_whitespace(self, value: bool) -> Self
pub const fn with_compact_whitespace(self, value: bool) -> Self
Builder-style setter for compact_whitespace (/W).
Sourcepub const fn with_compact_optional_whitespace(self, value: bool) -> Self
pub const fn with_compact_optional_whitespace(self, value: bool) -> Self
Builder-style setter for compact_optional_whitespace (/w).
Sourcepub const fn with_ignore_lowercase(self, value: bool) -> Self
pub const fn with_ignore_lowercase(self, value: bool) -> Self
Builder-style setter for ignore_lowercase (/c).
Sourcepub const fn with_ignore_uppercase(self, value: bool) -> Self
pub const fn with_ignore_uppercase(self, value: bool) -> Self
Builder-style setter for ignore_uppercase (/C).
Sourcepub const fn with_text_test(self, value: bool) -> Self
pub const fn with_text_test(self, value: bool) -> Self
Builder-style setter for text_test (/t).
Sourcepub const fn with_bin_test(self, value: bool) -> Self
pub const fn with_bin_test(self, value: bool) -> Self
Builder-style setter for bin_test (/b).
Sourcepub const fn with_full_word(self, value: bool) -> Self
pub const fn with_full_word(self, value: bool) -> Self
Builder-style setter for full_word (/f).
Sourcepub const fn with_start_anchor(self, value: bool) -> Self
pub const fn with_start_anchor(self, value: bool) -> Self
Builder-style setter for start_anchor (/s).
Trait Implementations§
Source§impl Clone for SearchFlags
impl Clone for SearchFlags
Source§fn clone(&self) -> SearchFlags
fn clone(&self) -> SearchFlags
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SearchFlags
impl Debug for SearchFlags
Source§impl Default for SearchFlags
impl Default for SearchFlags
Source§fn default() -> SearchFlags
fn default() -> SearchFlags
Source§impl<'de> Deserialize<'de> for SearchFlags
impl<'de> Deserialize<'de> for SearchFlags
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for SearchFlags
impl PartialEq for SearchFlags
Source§fn eq(&self, other: &SearchFlags) -> bool
fn eq(&self, other: &SearchFlags) -> bool
self and other values to be equal, and is used by ==.