### dowild_with method example Source: https://docs.rs/simplematch/latest/simplematch/trait.DoWild.html Example for the dowild_with method, which accepts customizable Options. Here, case-insensitive matching is enabled via Options::default().case_insensitive(true), and the pattern "foo*" matches "foobar". ```rust use simplematch::{DoWild, Options}; assert_eq!( "foo*".dowild_with("foobar", Options::default().case_insensitive(true)), true ); ``` -------------------------------- ### dowild basic usage Source: https://docs.rs/simplematch/latest/simplematch/fn.dowild.html Example of using the dowild function with byte slices to match a wildcard pattern. ```rust use simplematch::dowild; assert_eq!(dowild("*bc".as_bytes(), "aaabc".as_bytes()), true); ``` -------------------------------- ### Customizing dowild_with options Source: https://docs.rs/simplematch Example of using Options to perform case-insensitive matching with a custom wildcard character. ```rust use simplematch::{dowild_with, Options}; let options = Options::default() .case_insensitive(true) .wildcard_any_with(b'%'); assert_eq!( dowild_with("foo%".as_bytes(), "FOOBAR".as_bytes(), options), true ); ``` -------------------------------- ### Usage of dowild with char types Source: https://docs.rs/simplematch Example showing how to use the DoWild trait with character vectors. ```rust use simplematch::DoWild; let pattern = "foo*".chars().collect::>(); let haystack = "foobar".chars().collect::>(); assert_eq!(pattern.dowild(haystack), true); ``` -------------------------------- ### dowild_with with case-insensitive option Source: https://docs.rs/simplematch/latest/simplematch/fn.dowild_with.html Example using `dowild_with` with byte slices and case-insensitive matching. The pattern `*bc` matches `AAabc` when case-insensitivity is enabled. ```rust use simplematch::{dowild_with, Options}; assert_eq!( dowild_with( "*bc".as_bytes(), "AAabc".as_bytes(), Options::default().case_insensitive(true) ), true ); ``` -------------------------------- ### DoWild trait usage Source: https://docs.rs/simplematch/latest/simplematch/fn.dowild.html Example of using the DoWild trait to call dowild directly on a string. ```rust use simplematch::DoWild; assert_eq!("*bc".dowild("aaabc"), true); ``` -------------------------------- ### dowild_with via DoWild trait with custom wildcard Source: https://docs.rs/simplematch/latest/simplematch/fn.dowild_with.html Example using the `DoWild` trait to call `dowild_with` directly on a string, customizing the wildcard character to `%`. The pattern `%bc` matches `aaabc`. ```rust use simplematch::{DoWild, Options}; assert_eq!( "%bc".dowild_with("aaabc", Options::default().wildcard_any_with(b'%')), true ); ``` -------------------------------- ### Class prune method Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Removes classes with a starting index smaller than the given index from the front of the internal deque. ```rust /// Remove classes that have a smaller starting index than the given `index` #[inline] fn prune(&mut self, index: usize) { while let Some(first) = self.0.front() { if first.start < index { self.0.pop_front(); } else { break; } } } ``` -------------------------------- ### Verify Options Configuration Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Demonstrates the use of the verified method to ensure options are valid, showing a successful configuration and a failure case when assigning duplicate characters. ```rust .wildcard_any_with(b'%') .verified() .unwrap(); ``` ```rust use simplematch::{Options, SimpleMatchError}; assert_eq!( Options::default().wildcard_any_with(b'?').verified(), Err(SimpleMatchError::DuplicateCharacterAssignment) ); ``` -------------------------------- ### Verify valid options with verified Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Shows that a valid configuration returns the Options on success. ```rust use simplematch::{Options, SimpleMatchError}; let options = Options::default() .wildcard_any_with(b'%') .verified() .unwrap(); ``` -------------------------------- ### Options::new Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Creates a new Options instance for the dowild_with function. ```APIDOC ## Options::new ### Description Creates a new `Options` for the `dowild_with` function. ### Signature ```rust pub const fn new() -> Self ``` ### Parameters None. ### Returns - `Self` - A new `Options` instance. ### Example ```rust use simplematch::Options; let options = Options::::new(); ``` ``` -------------------------------- ### Options::verify Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Checks the Options for configuration errors, such as duplicate character assignments. ```APIDOC ## Options::verify ### Description Check `Options` for configuration errors. An invalid configuration consists of duplicate character assignments. For example you can’t use `*` for the escape character and `wildcard_any` character simultaneously. ### Signature ```rust pub fn verify(&self) -> Result<(), SimpleMatchError> ``` ### Parameters None. ### Returns - `Result<(), SimpleMatchError>` - `Ok(())` if the configuration is valid, otherwise `Err(SimpleMatchError)`. ### Errors Returns an error if these `Options` are invalid. ### Example ```rust use simplematch::{Options, SimpleMatchError}; assert_eq!( Options::default().wildcard_any_with(b'?').verified(), Err(SimpleMatchError::DuplicateCharacterAssignment) ); ``` ``` -------------------------------- ### Options::verified Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Consumes and returns the Options if valid, otherwise returns an error. ```APIDOC ## Options::verified ### Description A convenience method that consumes and returns these `Options` if it succeeds. The only difference to `verify` is, that this method consumes the `Options` returning it on success. ### Signature ```rust pub fn verified(self) -> Result ``` ### Parameters None. ### Returns - `Result` - `Ok(Self)` if the configuration is valid, otherwise `Err(SimpleMatchError)`. ### Errors Returns an error if `Options` are invalid. ### Example ```rust use simplematch::{Options, SimpleMatchError}; let options = Options::default() .wildcard_any_with(b'%') .verified() .unwrap(); assert_eq!( Options::default().wildcard_any_with(b'?').verified(), Err(SimpleMatchError::DuplicateCharacterAssignment) ); ``` ``` -------------------------------- ### Options::wildcard_any_with Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Sets a custom token for matching any number of characters (default is '*'). ```APIDOC ## Options::wildcard_any_with ### Description Use this `token` instead of the default `*` to match any occurrences of a characters. ### Signature ```rust pub const fn wildcard_any_with(self, token: T) -> Self ``` ### Parameters - `token` (T) - Required - The token to use for matching any sequence of characters. ### Returns - `Self` - The updated `Options` instance. ### Example ```rust use simplematch::Options; let options = Options::default().wildcard_any_with(b'%'); ``` ``` -------------------------------- ### Trait Wildcard Source: https://docs.rs/simplematch/latest/simplematch/trait.Wildcard.html Documentation for the Wildcard trait in the simplematch crate, including required constants, methods, and implementations for char and u8. ```APIDOC ## Trait Wildcard ### Description Defines the interface for types that can be matched against wildcard patterns. It provides default tokens for wildcard syntax and methods for character matching. ### Required Associated Constants - **DEFAULT_ANY** (Self) - The default token to match any number of characters, usually `*`. - **DEFAULT_CLASS_CLOSE** (Self) - The default token to close a character class pattern, usually `]`. - **DEFAULT_CLASS_HYPHEN** (Self) - The default token to specify a range, usually `-`. - **DEFAULT_CLASS_NEGATE** (Self) - The default token to negate a character class, usually `!`. - **DEFAULT_CLASS_OPEN** (Self) - The default token to open a character class pattern, usually `[`. - **DEFAULT_ESCAPE** (Self) - The default token to escape special characters, usually `\`. - **DEFAULT_ONE** (Self) - The default token to match exactly one character, usually `?`. ### Required Methods - **match_one_case_insensitive(first: Self, second: Self) -> bool** - Returns `true` if two characters match case-insensitively. - **match_one_case_sensitive(first: Self, second: Self) -> bool** - Returns `true` if two characters match case-sensitively. - **match_range_case_insensitive(token: Self, low: Self, high: Self) -> bool** - Returns `true` if the `token` matches the range from `low` to `high` case-insensitively. - **match_range_case_sensitive(token: Self, low: Self, high: Self) -> bool** - Returns `true` if the `token` matches the range from `low` to `high` case-sensitively. ### Implementations on Foreign Types #### impl Wildcard for char - **DEFAULT_ANY** = `'*'` - **DEFAULT_ESCAPE** = `'\\'` - **DEFAULT_ONE** = `'?'` - **DEFAULT_CLASS_CLOSE** = `']'` - **DEFAULT_CLASS_HYPHEN** = `'-'` - **DEFAULT_CLASS_NEGATE** = `'!'` - **DEFAULT_CLASS_OPEN** = `'['` - Provides implementations for all required methods. #### impl Wildcard for u8 - **DEFAULT_ANY** = `42u8` - **DEFAULT_ESCAPE** = `92u8` - **DEFAULT_ONE** = `63u8` - **DEFAULT_CLASS_CLOSE** = `93u8` - **DEFAULT_CLASS_HYPHEN** = `45u8` - **DEFAULT_CLASS_NEGATE** = `33u8` - **DEFAULT_CLASS_OPEN** = `91u8` - Provides implementations for all required methods. ### Dyn Compatibility This trait is **not** dyn compatible (not object safe). ``` -------------------------------- ### Options::enable_classes_with Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Enables character classes with a custom negation token. ```APIDOC ## Options::enable_classes_with ### Description If `true`, enable character classes `[...]` but use this `token` for the negation. The default is `false` and the default negation character is exclamation mark `!`. ### Signature ```rust pub const fn enable_classes_with(self, negation: T) -> Self ``` ### Parameters - `negation` (T) - Required - The token to use for negation within character classes. ### Returns - `Self` - The updated `Options` instance. ### Example ```rust use simplematch::Options; let options = Options::default().enable_classes_with(b'^'); ``` ``` -------------------------------- ### Options default and new methods Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Provides default Options with case-sensitive matching, escaping disabled, and classes disabled. ```rust impl Default for Options where T: Wildcard, { fn default() -> Self { Self::new() } } impl Options where T: Wildcard, { /// Create new `Options` for the [`dowild_with`] function. #[must_use] pub const fn new() -> Self { Self { case_sensitive: true, wildcard_escape: T::DEFAULT_ESCAPE, is_classes_enabled: false, class_negate: T::DEFAULT_CLASS_NEGATE, wildcard_any: T::DEFAULT_ANY, wildcard_one: T::DEFAULT_ONE, is_escape_enabled: false, } } ``` -------------------------------- ### Verify options with wildcard_any_with Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Shows that assigning '?' with wildcard_any_with fails verification, returning DuplicateCharacterAssignment error. ```rust use simplematch::{Options, SimpleMatchError}; assert_eq!( Options::default().wildcard_any_with(b'?').verified(), Err(SimpleMatchError::DuplicateCharacterAssignment) ); ``` -------------------------------- ### Class constructors and push method Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Creates new positive or negative Class instances and adds a ClassKind, avoiding duplicates. ```rust /// Create a new positive `Class`. #[inline] const fn new_positive() -> Self { Self::Positive(Vec::new()) } /// Create a new negative `Class`. #[inline] const fn new_negative() -> Self { Self::Negative(Vec::new()) } /// Add a new [`ClassKind`] to this `Class`. #[inline] fn push(&mut self, kind: ClassKind) { match self { Self::Positive(kinds) | Self::Negative(kinds) => { if kinds.last() != Some(&kind) { kinds.push(kind); } } } } ``` -------------------------------- ### fn dowild_with(&self, haystack: Self, options: Options) -> bool Source: https://docs.rs/simplematch/latest/simplematch/trait.DoWild.html Matches this pattern against the specified haystack with customizable Options. See dowild_with for more details. ```APIDOC ## fn dowild_with(&self, haystack: Self, options: Options) -> bool ### Description Matches this `pattern` against the specified `haystack` with customizable `Options`. See `dowild_with` for more details. ### Signature ```rust fn dowild_with(&self, haystack: Self, options: Options) -> bool; ``` ### Parameters - `haystack` (Self) - The string or slice to match against. - `options` (Options) - Customizable options for matching, such as case sensitivity. ### Returns - `bool` - `true` if the pattern matches the haystack with the given options, `false` otherwise. ### Example ```rust use simplematch::{DoWild, Options}; assert_eq!( "foo*".dowild_with("foobar", Options::default().case_insensitive(true)), true ); ``` ``` -------------------------------- ### Add simplematch to Cargo.toml Source: https://docs.rs/simplematch Include the simplematch dependency in your project's Cargo.toml file. ```toml [dependencies] simplematch = "0.3.1" ``` -------------------------------- ### Options::wildcard_one_with Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Sets a custom token for matching exactly one character (default is '?'). ```APIDOC ## Options::wildcard_one_with ### Description Use this `token` instead of the default `?` to match exactly one character. ### Signature ```rust pub const fn wildcard_one_with(self, token: T) -> Self ``` ### Parameters - `token` (T) - Required - The token to use for matching exactly one character. ### Returns - `Self` - The updated `Options` instance. ### Example ```rust use simplematch::Options; let options = Options::default().wildcard_any_with(b'_'); ``` ``` -------------------------------- ### Options::case_insensitive Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Sets whether matching is case-insensitive. Default is case-sensitive. ```APIDOC ## Options::case_insensitive ### Description If `true`, match the pattern case-insensitive. The default is to match case-sensitive. ### Signature ```rust pub const fn case_insensitive(self, yes: bool) -> Self ``` ### Parameters - `yes` (bool) - Required - If `true`, enables case-insensitive matching. ### Returns - `Self` - The updated `Options` instance. ### Example ```rust use simplematch::Options; let options: Options = Options::default().case_insensitive(true); ``` ``` -------------------------------- ### dowild_with Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Matches a pattern against a haystack with customizable options. This function allows you to specify options such as case sensitivity. ```APIDOC ## `dowild_with` ### Description Matches a pattern against a haystack with customizable options. This function allows you to specify options such as case sensitivity. ### Signature ```rust pub fn dowild_with(pattern: T, haystack: T, options: Options) -> bool where T: Wildcard, ``` ### Parameters - **pattern** (`T`) - The wildcard pattern to match. - **haystack** (`T`) - The string to test against the pattern. - **options** (`Options`) - The options to customize matching behavior. ### Returns - **bool** - `true` if the haystack matches the pattern, `false` otherwise. ### Example ```rust use simplematch::{dowild_with, Options}; assert_eq!( dowild_with("foo*", "foobar", Options::default().case_insensitive(true)), true ); ``` ``` -------------------------------- ### Options Struct Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Customize the matching behavior of the dowild_with function. This struct is non-exhaustive and contains fields for case sensitivity, character class negation, enabling classes and escaping, and wildcard tokens. ```APIDOC ## Struct Options ### Description Customize the matching behavior of the `dowild_with` function. This struct is non-exhaustive, meaning it may have additional fields added in the future and cannot be constructed with traditional struct syntax in external crates. ### Fields - **case_sensitive** (bool) - If `true`, patterns are matched case-sensitive. Default is `true`. Only ASCII characters are considered. - **class_negate** (T) - The token to negate a character class. Default is `!`. - **is_classes_enabled** (bool) - Set to `true` to enable character classes `[...]`. Default is `false`. - **is_escape_enabled** (bool) - Set to `true` to enable escaping special characters in the pattern. Default is `false`. Default escapable characters are `*` and `?`, and `[` if character classes are enabled. If the escape character is not escaping a special character, it is matched literally. - **wildcard_any** (T) - The token to match zero or more occurrences of any character. Default is `*`. - **wildcard_escape** (T) - The token to escape special characters. Default is backslash `\`. - **wildcard_one** (T) - The token to match exactly one occurrence of any character. Default is `?`. ### Usage This struct is used with the `dowild_with` function to customize matching behavior. ``` -------------------------------- ### Use dowild on &str Source: https://docs.rs/simplematch/latest/simplematch/trait.DoWild.html Shows how to use the dowild method directly on a &str pattern. The pattern "foo*" matches the haystack "foobar" and returns true. ```rust use simplematch::DoWild; assert_eq!("foo*".dowild("foobar"), true); ``` -------------------------------- ### fn dowild(&self, haystack: Self) -> bool Source: https://docs.rs/simplematch/latest/simplematch/trait.DoWild.html Matches this pattern against the specified haystack using simple wildcard rules. See dowild for more details. ```APIDOC ## fn dowild(&self, haystack: Self) -> bool ### Description Matches this `pattern` against the specified `haystack` using simple wildcard rules. See `dowild` for more details. ### Signature ```rust fn dowild(&self, haystack: Self) -> bool; ``` ### Parameters - `haystack` (Self) - The string or slice to match against. ### Returns - `bool` - `true` if the pattern matches the haystack, `false` otherwise. ### Example ```rust use simplematch::DoWild; assert_eq!("foo*".dowild("foobar"), true); ``` ``` -------------------------------- ### Options::enable_escape_with Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Enables escaping with a custom token instead of the default backslash. ```APIDOC ## Options::enable_escape_with ### Description Enable escaping of special characters but use this `token` instead of the default. The default is `false` and the default escape character is backslash `\`. ### Signature ```rust pub const fn enable_escape_with(self, token: T) -> Self ``` ### Parameters - `token` (T) - Required - The token to use as the escape character. ### Returns - `Self` - The updated `Options` instance. ### Example ```rust use simplematch::Options; let options = Options::default().enable_escape_with(b'#'); ``` ``` -------------------------------- ### Options::enable_classes Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Enables character classes [...] in patterns. Default is disabled. ```APIDOC ## Options::enable_classes ### Description If `true`, enable character classes `[...]`. The default is `false`. ### Signature ```rust pub const fn enable_classes(self, yes: bool) -> Self ``` ### Parameters - `yes` (bool) - Required - If `true`, enables character classes. ### Returns - `Self` - The updated `Options` instance. ### Example ```rust use simplematch::Options; let options: Options = Options::default().enable_classes(true); ``` ``` -------------------------------- ### Create new Options with case_insensitive Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Creates an Options instance with case-insensitive matching enabled. The default is case-sensitive. ```rust use simplematch::Options; let options: Options = Options::default().case_insensitive(true); ``` -------------------------------- ### dowild Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Matches a pattern against a haystack using simple wildcard rules. This is the core function of the `simplematch` crate. ```APIDOC ## `dowild` ### Description Matches a pattern against a haystack using simple wildcard rules. This is the core function of the `simplematch` crate. ### Signature ```rust pub fn dowild(pattern: T, haystack: T) -> bool where T: Wildcard, ``` ### Parameters - **pattern** (`T`) - The wildcard pattern to match. - **haystack** (`T`) - The string to test against the pattern. ### Returns - **bool** - `true` if the haystack matches the pattern, `false` otherwise. ### Example ```rust use simplematch::dowild; assert_eq!(dowild("foo*", "foobar"), true); ``` ``` -------------------------------- ### Set custom wildcard one token Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Uses the provided token instead of the default '?' to match exactly one character. ```rust use simplematch::Options; let options = Options::default().wildcard_any_with(b'_'); ``` -------------------------------- ### Options case_insensitive method Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Sets case sensitivity. When true, matching is case-insensitive; default is case-sensitive. ```rust /// If `true` match the pattern case-insensitive. /// /// The default is to match case-sensitive. /// /// # Examples /// /// ```rust /// use simplematch::Options; /// /// let options: Options = Options::default().case_insensitive(true); /// ``` #[must_use] pub const fn case_insensitive(mut self, yes: bool) -> Self { self.case_sensitive = !yes; self } ``` -------------------------------- ### Direct access with dowild_with Source: https://docs.rs/simplematch Calling dowild_with directly on a string slice with custom options. ```rust use simplematch::{DoWild, Options}; assert_eq!( "foo*".dowild_with("FOObar", Options::default().case_insensitive(true)), true ); ``` -------------------------------- ### Wildcard Matching Unit Tests Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Tests for case-sensitive and case-insensitive character matching using rstest. ```rust #[rstest] #[case::same_case_sensitive(b'j', b'j', true, true)] #[case::different_case_case_sensitive(b'j', b'J', true, false)] #[case::different_char_case_sensitive(b'a', b'b', true, false)] #[case::same_case_insensitive(b'j', b'j', false, true)] #[case::different_case_insensitive(b'j', b'J', false, true)] #[case::different_char_case_insensitive(b'a', b'B', false, false)] fn impl_wildcard_match_one( #[case] first: u8, #[case] second: u8, #[case] case_sensitive: bool, #[case] expected: bool, ) { if case_sensitive { assert_eq!(Wildcard::match_one_case_sensitive(first, second), expected); assert_eq!( Wildcard::match_one_case_sensitive(first as char, second as char), expected ); } else { assert_eq!( Wildcard::match_one_case_insensitive(first, second), expected ); assert_eq!( Wildcard::match_one_case_insensitive(first as char, second as char), expected ); } } ``` -------------------------------- ### Set custom wildcard any token Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Uses the provided token instead of the default '*' to match any occurrences of characters. ```rust use simplematch::Options; let options = Options::default().wildcard_any_with(b'%'); ``` -------------------------------- ### Enable character classes with enable_classes Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Enables character classes [...] in patterns. The default is false. ```rust use simplematch::Options; let options: Options = Options::default().enable_classes(true); ``` -------------------------------- ### Function signature for dowild_with Source: https://docs.rs/simplematch The signature for the customizable dowild_with function. ```rust use simplematch::Options; pub fn dowild_with(pattern: &[T], haystack: &[T], options: Options) -> bool where T: Wildcard + Ord, ``` -------------------------------- ### Class is_match method Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Checks if a token matches the class, using provided match_one and match_range closures. Positive classes match if any kind contains the token; negative classes match if none do. ```rust /// Returns `true` if a positive `Class` contains the given `token` or if negative doesn't /// contain the `token`. #[inline] fn is_match(&self, token: T, match_one: F, match_range: G) -> bool where F: Fn(T, T) -> bool + Copy, G: Fn(T, T, T) -> bool + Copy, { match self { Self::Positive(kinds) => kinds .iter() .any(|r| r.contains(&token, match_one, match_range)), Self::Negative(kinds) => !kinds .iter() .any(|r| r.contains(&token, match_one, match_range)), } } ``` -------------------------------- ### dowild Source: https://docs.rs/simplematch/latest/simplematch/fn.dowild.html Returns `true` if the wildcard pattern matches the `haystack`. Supports `*` for any amount of characters and `?` for exactly one character. This is the basic algorithm without customization options; use `dowild_with` for options. ```APIDOC ## dowild ### Description Returns `true` if the wildcard pattern matches the `haystack`. Allowed wildcard characters are `*` to match any amount of characters and `?` to match exactly one character. This is the basic algorithm without customization options to provide the best performance. If you need `Options` you can use `dowild_with`. ### Function Signature ```rust pub fn dowild(pattern: &[T], haystack: &[T]) -> bool where T: Wildcard, ``` ### Parameters - **pattern** (`&[T]`) - Required - The wildcard pattern to match against. - **haystack** (`&[T]`) - Required - The input to test against the pattern. ### Returns - **bool** - `true` if the pattern matches the haystack, otherwise `false`. ### Examples ```rust use simplematch::dowild; assert_eq!(dowild("*bc".as_bytes(), "aaabc".as_bytes()), true); ``` Alternatively, you can use the `DoWild` trait for a more convenient direct string matching: ```rust use simplematch::DoWild; assert_eq!("*bc".dowild("aaabc"), true); ``` ``` -------------------------------- ### Enable character classes with custom negation token Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Enables character classes but uses the provided token for negation instead of the default exclamation mark. The default is false. ```rust use simplematch::Options; let options = Options::default().enable_classes_with(b'^'); ``` -------------------------------- ### Enable escaping with custom token using enable_escape_with Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Enables escaping but uses the provided token instead of the default backslash. The default is false. ```rust use simplematch::Options; let options = Options::default().enable_escape_with(b'#'); ``` -------------------------------- ### dowild_with function signature Source: https://docs.rs/simplematch/latest/simplematch/fn.dowild_with.html Signature of the `dowild_with` function. It returns `true` if the wildcard pattern matches the haystack, with customization via `Options`. Use only when custom options are needed; otherwise `dowild` is more performant. ```rust pub fn dowild_with( pattern: &[T], haystack: &[T], options: Options, ) -> bool where T: Wildcard + Ord, ``` -------------------------------- ### dowild_with_worker implementation Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Internal function that performs the actual matching with customizable options. It destructures Options, defines closures for wildcard and class detection, and iterates through pattern and haystack. The function is slower than dowild due to customizability. ```rust fn dowild_with_worker( pattern: &[T], haystack: &[T], options: Options, match_one: F, match_range: G, ) -> bool where T: Wildcard + Ord, F: Fn(T, T) -> bool + Copy, G: Fn(T, T, T) -> bool + Copy, { let Options { class_negate, is_classes_enabled, is_escape_enabled, wildcard_any, wildcard_escape, wildcard_one, .. } = options; let is_wildcard_any = |token: T| token == wildcard_any; let is_wildcard_one = |token: T| token == wildcard_one; let is_escape = |token: T| is_escape_enabled && token == wildcard_escape; let is_class_open = |token: T| is_classes_enabled && token == T::DEFAULT_CLASS_OPEN; let is_special = |token: T| { token == wildcard_any || token == wildcard_one || token == wildcard_escape || (is_classes_enabled && token == T::DEFAULT_CLASS_OPEN) }; let is_valid_class_or_escape = |token: T, p_idx: usize, invalid_class_idx: usize| { (is_classes_enabled && token == T::DEFAULT_CLASS_OPEN && p_idx < invalid_class_idx) || (is_escape_enabled && token == wildcard_escape) }; let mut p_idx = 0; let mut h_idx = 0; let mut next_p_idx = 0; let mut next_h_idx = 0; // There are no allocations, yet. `CharacterClasses` allocate on first use. let mut classes = CharacterClasses::new(); let mut has_seen_wildcard_any = false; let mut invalid_class_idx = usize::MAX; ``` -------------------------------- ### Wildcard Range Matching Tests Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Tests for range matching logic when case sensitivity is enabled. ```rust #[rstest] #[case::all_the_same(b'j', b'j', b'j', true)] #[case::low_is_higher_high_is_same(b'j', b'k', b'j', false)] #[case::low_is_lower_high_is_same(b'j', b'i', b'j', true)] #[case::high_is_lower_low_is_same(b'j', b'k', b'i', false)] #[case::high_is_higher_low_is_same(b'j', b'j', b'k', true)] #[case::non_alpha_when_false(b'#', b'*', b']', false)] #[case::non_alpha_when_true(b'+', b'*', b']', true)] #[case::only_token_alpha(b'a', b'*', b']', false)] #[case::only_token_big_alpha(b'A', b'*', b']', true)] #[case::between_alphabetic(b']', b'*', b'B', false)] fn impl_wildcard_match_range_when_case_sensitive( #[case] token: u8, #[case] low: u8, #[case] high: u8, ``` -------------------------------- ### ClassKind contains and parse methods Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Contains checks if a token matches a range or single character. Parse and parse_first handle pattern parsing, including range detection and ordering. ```rust #[inline] fn contains(&self, token: &T, match_one: F, match_range: G) -> bool where F: Fn(T, T) -> bool, G: Fn(T, T, T) -> bool, { match self { Self::Range(low, high) => match_range(*token, *low, *high), Self::One(c) | Self::RangeOne(c) => match_one(*c, *token), } } /// Does no out of bounds check for the first character #[inline] fn parse(index: usize, pattern: &[T]) -> Option { if pattern[index] == T::DEFAULT_CLASS_CLOSE { None } else { Some(Self::parse_first(index, pattern)) } } /// Does no out of bounds and `]` check for the first character fn parse_first(index: usize, pattern: &[T]) -> Self { let first = pattern[index]; if index + 2 < pattern.len() && pattern[index + 1] == T::DEFAULT_CLASS_HYPHEN { let second = pattern[index + 2]; if second == T::DEFAULT_CLASS_CLOSE { Self::One(first) } else { match first.cmp(&second) { Ordering::Less => Self::Range(first, second), Ordering::Equal => Self::RangeOne(first), Ordering::Greater => Self::Range(second, first), } } } else { Self::One(first) } } #[inline] const fn len(&self) -> usize { match self { Self::Range(_, _) | Self::RangeOne(_) => 3, Self::One(_) => 1, } } ``` -------------------------------- ### dowild_with Source: https://docs.rs/simplematch/latest/simplematch/fn.dowild_with.html Returns `true` if the wildcard pattern matches the haystack, with customizable options. Supports case-insensitive matching, custom wildcard characters, escaping, and character classes. ```APIDOC ## Function dowild_with ### Description Returns `true` if the wildcard pattern matches the `haystack`. This method can be customized with `Options`. Don’t use this method if you only need the default `Options`; the `dowild` function is more performant in such cases. ### Signature ```rust pub fn dowild_with( pattern: &[T], haystack: &[T], options: Options, ) -> bool where T: Wildcard + Ord, ``` ### Parameters - **pattern** (`&[T]`) - The wildcard pattern to match. - **haystack** (`&[T]`) - The sequence to match against. - **options** (`Options`) - Customization options for matching behavior. ### Return Value - **bool** - `true` if the pattern matches the haystack, otherwise `false`. ### Behavior - Allowed wildcard characters are `*` to match any amount of characters and `?` to match exactly one character. - The `Options` structure allows for case-insensitive matching. - You can customize the `wildcard_any` character (`*`) and the `wildcard_one` character (`?`). - Escaping can be enabled, allowing you to specify a custom escape character. - Character classes and ranges, such as `[a-z]`, are supported. - The negation character can be customized to match all characters not included in a specified range, as in `[!a-z]`. ### Examples ```rust use simplematch::{dowild_with, Options}; assert_eq!( dowild_with( "*bc".as_bytes(), "AAabc".as_bytes(), Options::default().case_insensitive(true) ), true ); ``` Or more conveniently match directly on a string bringing the `DoWild` trait in scope. ```rust use simplematch::{DoWild, Options}; assert_eq!( "%bc".dowild_with("aaabc", Options::default().wildcard_any_with(b'%')), true ); ``` ``` -------------------------------- ### Test Wildcard::match_range_case_sensitive with rstest cases Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Parameterized test for Wildcard::match_range_case_sensitive. Uses rstest cases covering same-case, mixed-case, and non-alphabetic tokens. Asserts both u8 and char overloads return the expected boolean. ```Rust #[rstest] #[case::all_the_same_small(b'j', b'j', b'j', true)] #[case::all_the_same_big(b'J', b'J', b'J', true)] // This token is one of the characters between `Z` and `a` #[case::no_alpha_low_is_big(b'[', b'A', b'z', true)] #[case::no_alpha_both_big(b'[', b'A', b'Z', false)] #[case::no_alpha_low_is_small(b'[', b'a', b'z', false)] #[case::no_alpha_both_small(b'[', b'a', b'z', false)] #[case::all_small_middle(b'j', b'a', b'z', true)] #[case::all_small_low_is_higher(b'j', b'k', b'z', false)] #[case::all_small_high_is_lower(b'j', b'a', b'i', false)] #[case::all_big_middle(b'J', b'A', b'Z', true)] #[case::all_big_low_is_higher(b'J', b'K', b'Z', false)] #[case::all_big_high_is_lower(b'J', b'A', b'I', false)] #[case::big_a_to_j(b'z', b'A', b'j', true)] #[case::non_alpha_when_false(b'#', b'*', b']', false)] #[case::control_when_false(b'\x1f', b'*', b']', false)] #[case::non_alpha_when_true(b'+', b'*', b']', true)] #[case::only_token_alpha(b'a', b'*', b']', true)] #[case::only_token_big_alpha(b'A', b'*', b']', true)] #[case::between_alphabetic(b']', b'*', b'B', false)] fn impl_wildcard_match_range_when_case_sensitive( #[case] token: u8, #[case] low: u8, #[case] high: u8, #[case] expected: bool, ) { assert_eq!( Wildcard::match_range_case_sensitive(token, low, high), expected ); assert_eq!( Wildcard::match_range_case_sensitive(token as char, low as char, high as char), expected ); } ``` -------------------------------- ### Test Wildcard::match_range_case_insensitive with rstest cases Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Parameterized test for Wildcard::match_range_case_insensitive. Uses the same case set as the case-sensitive test. Asserts both u8 and char overloads return the expected boolean. ```Rust #[rstest] #[case::all_the_same_small(b'j', b'j', b'j', true)] #[case::all_the_same_big(b'J', b'J', b'J', true)] // This token is one of the characters between `Z` and `a` #[case::no_alpha_low_is_big(b'[', b'A', b'z', true)] #[case::no_alpha_both_big(b'[', b'A', b'Z', false)] #[case::no_alpha_low_is_small(b'[', b'a', b'z', false)] #[case::no_alpha_both_small(b'[', b'a', b'z', false)] #[case::all_small_middle(b'j', b'a', b'z', true)] #[case::all_small_low_is_higher(b'j', b'k', b'z', false)] #[case::all_small_high_is_lower(b'j', b'a', b'i', false)] #[case::all_big_middle(b'J', b'A', b'Z', true)] #[case::all_big_low_is_higher(b'J', b'K', b'Z', false)] #[case::all_big_high_is_lower(b'J', b'A', b'I', false)] #[case::big_a_to_j(b'z', b'A', b'j', true)] #[case::non_alpha_when_false(b'#', b'*', b']', false)] #[case::control_when_false(b'\x1f', b'*', b']', false)] #[case::non_alpha_when_true(b'+', b'*', b']', true)] #[case::only_token_alpha(b'a', b'*', b']', true)] #[case::only_token_big_alpha(b'A', b'*', b']', true)] #[case::between_alphabetic(b']', b'*', b'B', false)] fn impl_wildcard_match_range_when_case_insensitive( #[case] token: u8, #[case] low: u8, #[case] high: u8, #[case] expected: bool, ) { assert_eq!( Wildcard::match_range_case_insensitive(token, low, high), expected ); assert_eq!( Wildcard::match_range_case_insensitive(token as char, low as char, high as char), expected ); } ``` -------------------------------- ### Options::enable_escape Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Enables escaping of special characters in the pattern. Default escape character is backslash. ```APIDOC ## Options::enable_escape ### Description If `true`, enable escaping of special characters in the pattern. The default is `false` and the default escape character is backslash `\`. ### Signature ```rust pub const fn enable_escape(self, yes: bool) -> Self ``` ### Parameters - `yes` (bool) - Required - If `true`, enables escaping. ### Returns - `Self` - The updated `Options` instance. ### Example ```rust use simplematch::Options; let options: Options = Options::default().enable_escape(true); ``` ``` -------------------------------- ### Enable escaping with enable_escape Source: https://docs.rs/simplematch/latest/simplematch/struct.Options.html Enables escaping of special characters in the pattern. The default is false and the default escape character is backslash. ```rust use simplematch::Options; let options: Options = Options::default().enable_escape(true); ``` -------------------------------- ### Enum SimpleMatchError Source: https://docs.rs/simplematch/latest/simplematch/enum.SimpleMatchError.html The error type of the simplematch crate. It is an enum with a single variant indicating a duplicate character assignment. ```APIDOC ## Enum SimpleMatchError ### Description The `Error` of the simplematch crate. Represents errors that can occur during pattern matching. ### Definition ```rust pub enum SimpleMatchError { DuplicateCharacterAssignment, } ``` ### Variants - **DuplicateCharacterAssignment** - A character in `Options` was assigned multiple times. ### Trait Implementations - `Clone` - `Debug` - `Display` - `Error` (available on crate feature `std` only) - `Ord` - `PartialEq` - `PartialOrd` - `Copy` - `Eq` - `StructuralPartialEq` ``` -------------------------------- ### Wildcard trait definition Source: https://docs.rs/simplematch/latest/simplematch/trait.Wildcard.html Defines the Wildcard trait with required associated constants and methods for wildcard pattern matching. The trait is not dyn compatible. ```rust pub trait Wildcard: Eq + Copy + Clone { const DEFAULT_ANY: Self; const DEFAULT_CLASS_CLOSE: Self; const DEFAULT_CLASS_HYPHEN: Self; const DEFAULT_CLASS_NEGATE: Self; const DEFAULT_CLASS_OPEN: Self; const DEFAULT_ESCAPE: Self; const DEFAULT_ONE: Self; // Required methods fn match_one_case_insensitive(first: Self, second: Self) -> bool; fn match_one_case_sensitive(first: Self, second: Self) -> bool; fn match_range_case_insensitive(token: Self, low: Self, high: Self) -> bool; fn match_range_case_sensitive(token: Self, low: Self, high: Self) -> bool; } ``` -------------------------------- ### DoWild trait definition Source: https://docs.rs/simplematch/latest/simplematch/trait.DoWild.html Defines the DoWild trait with two required methods: dowild and dowild_with. The trait is implemented for &str, String, &[u8], Vec, &[char], and Vec. It is not dyn compatible. ```rust pub trait DoWild where T: Wildcard, { // Required methods fn dowild(&self, haystack: Self) -> bool; fn dowild_with(&self, haystack: Self, options: Options) -> bool; } ``` -------------------------------- ### dowild function signature Source: https://docs.rs/simplematch/latest/simplematch/fn.dowild.html The function signature for dowild, which requires the T type to implement the Wildcard trait. ```rust pub fn dowild(pattern: &[T], haystack: &[T]) -> bool where T: Wildcard, ``` -------------------------------- ### ASCII Case-Insensitive Range Check Source: https://docs.rs/simplematch/latest/src/simplematch/lib.rs.html Checks if an ASCII alphabetic token falls within a specified range, ignoring case. Note that this function can return true for tokens outside the range if the range spans across ASCII boundaries, consistent with common regex engine behavior. ```rust const fn is_in_ascii_range_case_insensitive(token: u8, low: u8, high: u8) -> bool { const ASCII_CASE_MASK: u8 = 0b0010_0000; if token.is_ascii_lowercase() { let token_uppercase = token ^ ASCII_CASE_MASK; low <= token_uppercase && token_uppercase <= high // Since token is alphabetic it is an uppercase character } else { let token_lowercase = token | ASCII_CASE_MASK; low <= token_lowercase && token_lowercase <= high } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.