pub fn regex_check(expression: &str, directory: impl AsRef<Path>) -> bool {
        if expression == "*" {
            return true;
        }

        let temp_splits: Vec<&str> = expression.split('*').collect();
        let mut splits: Vec<&str> = Vec::new();
        for i in temp_splits {
            if !i.is_empty() {
                splits.push(i);
            }
        }
        if splits.is_empty() {
            return false;
        }

        // Get rid of non unicode characters
        let directory = directory.as_ref().to_string_lossy();

        // Early checking if directory contains all parts needed by expression
        for split in &splits {
            if !directory.contains(split) {
                return false;
            }
        }

        let mut position_of_splits: Vec<usize> = Vec::new();

        // `git*` shouldn't be true for `/gitsfafasfs`
        if !expression.starts_with('*') && directory.find(&splits[0]).unwrap() > 0 {
            return false;
        }
        // `*home` shouldn't be true for `/homeowner`
        if !expression.ends_with('*') && !directory.ends_with(splits.last().unwrap()) {
            return false;
        }

        // At the end we check if parts between * are correctly positioned
        position_of_splits.push(directory.find(&splits[0]).unwrap());
        let mut current_index: usize;
        let mut found_index: usize;
        for i in splits[1..].iter().enumerate() {
            current_index = *position_of_splits.get(i.0).unwrap() + i.1.len();
            found_index = match directory[current_index..].find(i.1) {
                Some(t) => t,
                None => return false,
            };
            position_of_splits.push(found_index + current_index);
        }
        true
    }
/// Function to check if directory match expression
Function to check if directory match expression
Function to check if directory match expression
pub fn regex_check(expression: &str, directory: impl AsRef<Path>) -> bool {
        if expression == "*" {
            return true;
        }
        let temp_splits: Vec<&str> = expression.split('*').collect();
        let mut splits: Vec<&str> = Vec::new();
        for i in temp_splits {
            if !i.is_empty() {
                splits.push(i);
            }
        }
        if splits.is_empty() {
            return false;
        }
        // Get rid of non unicode characters
        let directory = directory.as_ref().to_string_lossy();
        // Early checking if directory contains all parts needed by expression
        for split in &splits {
            if !directory.contains(split) {
                return false;
            }
        }
        let mut position_of_splits: Vec<usize> = Vec::new();
        // `git*` shouldn't be true for `/gitsfafasfs`
        if !expression.starts_with('*') && directory.find(&splits[0]).unwrap() > 0 {
            return false;
        }
        // `*home` shouldn't be true for `/homeowner`
        if !expression.ends_with('*') && !directory.ends_with(splits.last().unwrap()) {
            return false;
        }
        // At the end we check if parts between * are correctly positioned
        position_of_splits.push(directory.find(&splits[0]).unwrap());
        let mut current_index: usize;
        let mut found_index: usize;
        for i in splits[1..].iter().enumerate() {
            current_index = *position_of_splits.get(i.0).unwrap() + i.1.len();
            found_index = match directory[current_index..].find(i.1) {
                Some(t) => t,
                None => return false,
            };
            position_of_splits.push(found_index + current_index);
        }
        true
    }
pub fn regex_check ( expression : & str , directory : impl AsRef < Path > ) -> bool { if expression == " " { return true ; } let temp_splits : Vec < & str > = expression . split ( '*' ) . collect ( ) ; let mut splits : Vec < & str > = Vec :: new ( ) ; for i in temp_splits { if ! i . is_empty ( ) { splits . push ( i ) ; } } if splits . is_empty ( ) { return false ; } // Get rid of non unicode characters let directory = directory . as_ref ( ) . to_string_lossy ( ) ; // Early checking if directory contains all parts needed by expression for split in & splits { if ! directory . contains ( split ) { return false ; } } let mut position_of_splits : Vec < usize > = Vec :: new ( ) ; // `git*` shouldn't be true for `/gitsfafasfs` if ! expression . starts_with ( '*' ) && directory . find ( & splits [ 0 ] ) . unwrap ( ) > 0 { return false ; } // `*home` shouldn't be true for `/homeowner` if ! expression . ends_with ( '*' ) && ! directory . ends_with ( splits . last ( ) . unwrap ( ) ) { return false ; } // At the end we check if parts between * are correctly positioned position_of_splits . push ( directory . find ( & splits [ 0 ] ) . unwrap ( ) ) ; let mut current_index : usize ; let mut found_index : usize ; for i in splits [ 1 .. ] . iter ( ) . enumerate ( ) { current_index = * position_of_splits . get ( i . 0 ) . unwrap ( ) + i . 1 . len ( ) ; found_index = match directory [ current_index .. ] . find ( i . 1 ) { Some ( t ) => t , None => return false , } ; position_of_splits . push ( found_index + current_index ) ; } true }
Function to check if directory match expression
Function to check if directory match expression
expression
&str
directory
impl AsRef<Path>
expression
&str
directory
impl AsRef<Path>