Skip to main content

StringFlags

Struct StringFlags 

Source
#[non_exhaustive]
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 (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§compact_whitespace: bool

/WSTRING_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

/wSTRING_COMPACT_OPTIONAL_WHITESPACE. Pattern whitespace matches zero or more whitespace bytes in the file.

§ignore_lowercase: bool

/cSTRING_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

/CSTRING_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

/tSTRING_TEXTTEST. Hint that this rule applies to text files. Captured for MIME-output integration; does not currently alter comparison.

§trim: bool

/TSTRING_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

/bSTRING_BINTEST. Hint that this rule applies to binary files. Captured for MIME-output integration; does not currently alter comparison.

§full_word: bool

/fSTRING_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

Source

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.

Source

pub const fn with_compact_whitespace(self, value: bool) -> Self

Builder-style setter for compact_whitespace (/W).

Source

pub const fn with_compact_optional_whitespace(self, value: bool) -> Self

Builder-style setter for compact_optional_whitespace (/w).

Source

pub const fn with_ignore_lowercase(self, value: bool) -> Self

Builder-style setter for ignore_lowercase (/c).

Source

pub const fn with_ignore_uppercase(self, value: bool) -> Self

Builder-style setter for ignore_uppercase (/C).

Source

pub const fn with_text_test(self, value: bool) -> Self

Builder-style setter for text_test (/t).

Source

pub const fn with_trim(self, value: bool) -> Self

Builder-style setter for trim (/T).

Source

pub const fn with_bin_test(self, value: bool) -> Self

Builder-style setter for bin_test (/b).

Source

pub const fn with_full_word(self, value: bool) -> Self

Builder-style setter for full_word (/f).

Trait Implementations§

Source§

impl Clone for StringFlags

Source§

fn clone(&self) -> StringFlags

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for StringFlags

Source§

impl Debug for StringFlags

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StringFlags

Source§

fn default() -> StringFlags

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for StringFlags

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for StringFlags

Source§

impl PartialEq for StringFlags

Source§

fn eq(&self, other: &StringFlags) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for StringFlags

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for StringFlags

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.