fn split_command(s: &str) -> Option<VecDeque<String>> {
    let elements = s.split_whitespace();
    let mut final_elements = Vec::new();
    let mut buffer = Vec::new();
    let mut delimiter = '"';
    for e in elements {
        let e_str = e.to_string();
        if buffer.len() > 0 {
            if e_str.len() > 0 {
                if e_str.chars().last().unwrap() == delimiter {
                    buffer.push(e_str);
                    let new_str = buffer.join(" ");
                    if delimiter == '"' {
                        let new_str2 = START_DOUBLE_QUOTE.replace(&new_str, "");
                        let new_str3 = END_DOUBLE_QUOTE.replace(&new_str2, "");
                        final_elements.push(new_str3.to_string());
                    } else {
                        let new_str2 = START_SINGLE_QUOTE.replace(&new_str, "");
                        let new_str3 = END_SINGLE_QUOTE.replace(&new_str2, "");
                        final_elements.push(new_str3.to_string());
                    }
                    buffer.clear();
                } else {
                    buffer.push(e_str);
                }
            }
        } else if START_DOUBLE_QUOTE.is_match(&e_str) && !END_DOUBLE_QUOTE.is_match(&e_str) {
            buffer.push(e_str);
            delimiter = '"';
        } else if START_SINGLE_QUOTE.is_match(&e_str) && !END_SINGLE_QUOTE.is_match(&e_str) {
            buffer.push(e_str);
            delimiter = '\'';
        } else {
            if delimiter == '"' {
                let new_str2 = START_DOUBLE_QUOTE.replace(&e_str, "");
                let new_str3 = END_DOUBLE_QUOTE.replace(&new_str2, "");
                final_elements.push(new_str3.to_string());
            } else {
                let new_str2 = START_SINGLE_QUOTE.replace(&e_str, "");
                let new_str3 = END_SINGLE_QUOTE.replace(&new_str2, "");
                final_elements.push(new_str3.to_string());
            }
        }
    }
    if buffer.len() > 0 {
        return None;
    }

    let mut lst = VecDeque::new();
    for e in final_elements.iter() {
        if lst.len() == 0 {
            lst.push_back(e.to_string());
        } else {
            let back = lst.back().unwrap();
            if END_SLASH_EXTRA.is_match(back) {
                let back = lst.pop_back().unwrap();
                let back2 = END_SLASH.replace_all(&back, "");
                let back3 = format!("{} {}", back2, e);
                lst.push_back(back3);
            } else {
                lst.push_back(e.to_string());
            }
        }
    }
    return Some(lst);
}
/// Splits a string on whitespace, taking into account quoted values
/// (for both single-quotes and double-quotes).
Splits a string on whitespace, taking into account quoted values
(for both single-quotes and double-quotes).
Splits a string on whitespace taking into account quoted values ( for both single - quotes and double - quotes ) .
fn split_command(s: &str) -> Option<VecDeque<String>> {
    let elements = s.split_whitespace();
    let mut final_elements = Vec::new();
    let mut buffer = Vec::new();
    let mut delimiter = '"';
    for e in elements {
        let e_str = e.to_string();
        if buffer.len() > 0 {
            if e_str.len() > 0 {
                if e_str.chars().last().unwrap() == delimiter {
                    buffer.push(e_str);
                    let new_str = buffer.join(" ");
                    if delimiter == '"' {
                        let new_str2 = START_DOUBLE_QUOTE.replace(&new_str, "");
                        let new_str3 = END_DOUBLE_QUOTE.replace(&new_str2, "");
                        final_elements.push(new_str3.to_string());
                    } else {
                        let new_str2 = START_SINGLE_QUOTE.replace(&new_str, "");
                        let new_str3 = END_SINGLE_QUOTE.replace(&new_str2, "");
                        final_elements.push(new_str3.to_string());
                    }
                    buffer.clear();
                } else {
                    buffer.push(e_str);
                }
            }
        } else if START_DOUBLE_QUOTE.is_match(&e_str) && !END_DOUBLE_QUOTE.is_match(&e_str) {
            buffer.push(e_str);
            delimiter = '"';
        } else if START_SINGLE_QUOTE.is_match(&e_str) && !END_SINGLE_QUOTE.is_match(&e_str) {
            buffer.push(e_str);
            delimiter = '\'';
        } else {
            if delimiter == '"' {
                let new_str2 = START_DOUBLE_QUOTE.replace(&e_str, "");
                let new_str3 = END_DOUBLE_QUOTE.replace(&new_str2, "");
                final_elements.push(new_str3.to_string());
            } else {
                let new_str2 = START_SINGLE_QUOTE.replace(&e_str, "");
                let new_str3 = END_SINGLE_QUOTE.replace(&new_str2, "");
                final_elements.push(new_str3.to_string());
            }
        }
    }
    if buffer.len() > 0 {
        return None;
    }
    let mut lst = VecDeque::new();
    for e in final_elements.iter() {
        if lst.len() == 0 {
            lst.push_back(e.to_string());
        } else {
            let back = lst.back().unwrap();
            if END_SLASH_EXTRA.is_match(back) {
                let back = lst.pop_back().unwrap();
                let back2 = END_SLASH.replace_all(&back, "");
                let back3 = format!("{} {}", back2, e);
                lst.push_back(back3);
            } else {
                lst.push_back(e.to_string());
            }
        }
    }
    return Some(lst);
}
fn split_command ( s : & str ) -> Option < VecDeque < String > > { let elements = s . split_whitespace ( ) ; let mut final_elements = Vec :: new ( ) ; let mut buffer = Vec :: new ( ) ; let mut delimiter = '"' ; for e in elements { let e_str = e . to_string ( ) ; if buffer . len ( ) > 0 { if e_str . len ( ) > 0 { if e_str . chars ( ) . last ( ) . unwrap ( ) == delimiter { buffer . push ( e_str ) ; let new_str = buffer . join ( " " ) ; if delimiter == '"' { let new_str2 = START_DOUBLE_QUOTE . replace ( & new_str , " " ) ; let new_str3 = END_DOUBLE_QUOTE . replace ( & new_str2 , " " ) ; final_elements . push ( new_str3 . to_string ( ) ) ; } else { let new_str2 = START_SINGLE_QUOTE . replace ( & new_str , " " ) ; let new_str3 = END_SINGLE_QUOTE . replace ( & new_str2 , " " ) ; final_elements . push ( new_str3 . to_string ( ) ) ; } buffer . clear ( ) ; } else { buffer . push ( e_str ) ; } } } else if START_DOUBLE_QUOTE . is_match ( & e_str ) && ! END_DOUBLE_QUOTE . is_match ( & e_str ) { buffer . push ( e_str ) ; delimiter = '"' ; } else if START_SINGLE_QUOTE . is_match ( & e_str ) && ! END_SINGLE_QUOTE . is_match ( & e_str ) { buffer . push ( e_str ) ; delimiter = '\'' ; } else { if delimiter == '"' { let new_str2 = START_DOUBLE_QUOTE . replace ( & e_str , " " ) ; let new_str3 = END_DOUBLE_QUOTE . replace ( & new_str2 , " " ) ; final_elements . push ( new_str3 . to_string ( ) ) ; } else { let new_str2 = START_SINGLE_QUOTE . replace ( & e_str , " " ) ; let new_str3 = END_SINGLE_QUOTE . replace ( & new_str2 , " " ) ; final_elements . push ( new_str3 . to_string ( ) ) ; } } } if buffer . len ( ) > 0 { return None ; } let mut lst = VecDeque :: new ( ) ; for e in final_elements . iter ( ) { if lst . len ( ) == 0 { lst . push_back ( e . to_string ( ) ) ; } else { let back = lst . back ( ) . unwrap ( ) ; if END_SLASH_EXTRA . is_match ( back ) { let back = lst . pop_back ( ) . unwrap ( ) ; let back2 = END_SLASH . replace_all ( & back , " " ) ; let back3 = format ! ( " " back2 e ) ; lst . push_back ( back3 ) ; } else { lst . push_back ( e . to_string ( ) ) ; } } } return Some ( lst ) ; }
Splits a string on whitespace, taking into account quoted values
(for both single-quotes and double-quotes).
Splits a string on whitespace taking into account quoted values ( for both single - quotes and double - quotes ) .
s
&str