Struct glob::Pattern[src]
pub struct Pattern {
// some fields omitted
}A compiled Unix shell style pattern.
Methods
impl Pattern
fn new(pattern: &str) -> Pattern
This function compiles Unix shell style patterns: ? matches any single
character, * matches any (possibly empty) sequence of characters and
[...] matches any character inside the brackets, unless the first
character is ! in which case it matches any character except those
between the ! and the ]. Character sequences can also specify ranges
of characters, as ordered by Unicode, so e.g. [0-9] specifies any
character between 0 and 9 inclusive.
The metacharacters ?, *, [, ] can be matched by using brackets
(e.g. [?]). When a ] occurs immediately following [ or [! then
it is interpreted as being part of, rather then ending, the character
set, so ] and NOT ] can be matched by []] and [!]] respectively.
The - character can be specified inside a character sequence pattern by
placing it at the start or the end, e.g. [abc-].
When a [ does not have a closing ] before the end of the string then
the [ will be treated literally.
fn escape(s: &str) -> String
Escape metacharacters within the given string by surrounding them in
brackets. The resulting string will, when compiled into a Pattern,
match the input string and nothing else.
fn matches(&self, str: &str) -> bool
Return if the given str matches this Pattern using the default
match options (i.e. MatchOptions::new()).
Example
extern crate glob; fn main() { use glob::Pattern; assert!(Pattern::new("c?t").matches("cat")); assert!(Pattern::new("k[!e]tteh").matches("kitteh")); assert!(Pattern::new("d*g").matches("doog")); }use glob::Pattern; assert!(Pattern::new("c?t").matches("cat")); assert!(Pattern::new("k[!e]tteh").matches("kitteh")); assert!(Pattern::new("d*g").matches("doog"));
fn matches_path(&self, path: &Path) -> bool
Return if the given Path, when converted to a str, matches this Pattern
using the default match options (i.e. MatchOptions::new()).
fn matches_with(&self, str: &str, options: MatchOptions) -> bool
Return if the given str matches this Pattern using the specified match options.
fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool
Return if the given Path, when converted to a str, matches this Pattern
using the specified match options.