pub struct StringFlags {
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,
}Expand description
String modifier flags parsed from the /[cCwWtTbf] suffix on a string
rule.
Mirrors libmagic’s STRING_* flag bits from src/file.h. Each flag
alters how compare_string_with_flags walks the pattern and buffer in
parallel. The default (all false) preserves byte-exact comparison.
/c vs /C are asymmetric: the pattern character controls
direction. With /c, only lowercase pattern chars trigger case-folding
(the file byte is tolower’d). With /C, only uppercase pattern chars
trigger folding (the file byte is toupper’d). Mixed-case patterns
behave intuitively: /c FoO matches FoO, Foo, FOO but not
fOO (the uppercase F is literal). See GOTCHAS S6.5 for the
rationale and src/softmagic.c for the canonical libmagic contract.
/B is NOT a string flag – it is the pstring 1-byte length-width
letter (PSTRING_1_BE). string/B is rejected at parse time. See
GOTCHAS S6.6.
§Examples
use libmagic_rs::parser::ast::StringFlags;
let plain = StringFlags::default();
assert!(!plain.ignore_lowercase);
let case_insensitive = StringFlags::default().with_ignore_lowercase(true);
assert!(case_insensitive.ignore_lowercase);
let compound = StringFlags::default()
.with_ignore_lowercase(true)
.with_compact_optional_whitespace(true);
assert!(compound.ignore_lowercase);
assert!(compound.compact_optional_whitespace);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. The trim is applied at
evaluation time (in read_pattern_match) so the AST keeps the
original pattern bytes; the comparison function receives the
trimmed slice.
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 _).
Implementations§
Source§impl StringFlags
impl StringFlags
Sourcepub const fn is_empty(self) -> bool
pub const fn is_empty(self) -> bool
Returns true when every flag is false (the byte-exact fast
path). The evaluator dispatcher uses this to skip the
parallel-walk comparison when no flags are set.
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).
Trait Implementations§
Source§impl Clone for StringFlags
impl Clone for StringFlags
Source§fn clone(&self) -> StringFlags
fn clone(&self) -> StringFlags
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 StringFlags
impl Debug for StringFlags
Source§impl Default for StringFlags
impl Default for StringFlags
Source§fn default() -> StringFlags
fn default() -> StringFlags
Source§impl<'de> Deserialize<'de> for StringFlags
impl<'de> Deserialize<'de> for StringFlags
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 StringFlags
impl PartialEq for StringFlags
Source§fn eq(&self, other: &StringFlags) -> bool
fn eq(&self, other: &StringFlags) -> bool
self and other values to be equal, and is used by ==.