fn pattern_match<P: AsRef<Path>>(pattern: &str,path: P) -> bool {
    //Convert pattern to regex
    let mut last_was_star = false;
    let mut regstr = String::from("^");

    //TODO: find out if .chars could make problems with utf8 characters
    for ch in pattern.chars() {
        match (ch,last_was_star) {
            ('*',true) => {
                last_was_star = false;
                regstr.push_str(".*");
            },
            (c,true) => {
                last_was_star = false;
                regstr.push_str("[^\\\\/]*");
                push_escaped(&mut regstr,c);
            },
            ('*',false) => {
                last_was_star = true;
            },
            (c,false) => {
                push_escaped(&mut regstr,c);
            }

        }
    }
    if last_was_star {
        regstr.push_str("[^\\\\/]*");
    }
    regstr.push_str("$");

    //Apply regex to path
    let re = Regex::new(&regstr).unwrap();

    re.is_match(path.as_ref().to_str().unwrap())
}
/// Checks if two file patterns with "wildcards" match
//TODO: allow escaping characters in search pattern?
//TODO: Return value to determine how specific it matched (for deciding which pattern of more matches most)
Checks if two file patterns with "wildcards" match
TODO: allow escaping characters in search pattern.
TODO: Return value to determine how specific it matched (for deciding which pattern of more matches most)
Checks if two file patterns with " wildcards " match TODO : allow escaping characters in search pattern . TODO : Return value to determine how specific it matched ( for deciding which pattern of more matches most )
fn pattern_match<P: AsRef<Path>>(pattern: &str,path: P) -> bool {
    //Convert pattern to regex
    let mut last_was_star = false;
    let mut regstr = String::from("^");
    //TODO: find out if .chars could make problems with utf8 characters
    for ch in pattern.chars() {
        match (ch,last_was_star) {
            ('*',true) => {
                last_was_star = false;
                regstr.push_str(".*");
            },
            (c,true) => {
                last_was_star = false;
                regstr.push_str("[^\\\\/]*");
                push_escaped(&mut regstr,c);
            },
            ('*',false) => {
                last_was_star = true;
            },
            (c,false) => {
                push_escaped(&mut regstr,c);
            }
        }
    }
    if last_was_star {
        regstr.push_str("[^\\\\/]*");
    }
    regstr.push_str("$");
    //Apply regex to path
    let re = Regex::new(&regstr).unwrap();
    re.is_match(path.as_ref().to_str().unwrap())
}
fn pattern_match < P : AsRef < Path > > ( pattern : & str , path : P ) -> bool { //Convert pattern to regex let mut last_was_star = false ; let mut regstr = String :: from ( " " ) ; //TODO: find out if .chars could make problems with utf8 characters for ch in pattern . chars ( ) { match ( ch , last_was_star ) { ( '*' , true ) => { last_was_star = false ; regstr . push_str ( " " ) ; } , ( c , true ) => { last_was_star = false ; regstr . push_str ( " \\ \\ " ) ; push_escaped ( & mut regstr , c ) ; } , ( '*' , false ) => { last_was_star = true ; } , ( c , false ) => { push_escaped ( & mut regstr , c ) ; } } } if last_was_star { regstr . push_str ( " \\ \\ " ) ; } regstr . push_str ( " " ) ; //Apply regex to path let re = Regex :: new ( & regstr ) . unwrap ( ) ; re . is_match ( path . as_ref ( ) . to_str ( ) . unwrap ( ) ) }
Checks if two file patterns with "wildcards" match
TODO: allow escaping characters in search pattern?
Checks if two file patterns with " wildcards " match TODO : allow escaping characters in search pattern?
pattern
&str
path
P
pattern
&str
path
P