fn expand_quotes(argv: Vec<String>) -> Result<Vec<String>, ArgumentError> {
    let mut words = vec![];

    for word in argv {
        let mut expanded = String::new();
        let mut chars = word.chars();

        let mut is_single_quote = false;
        let mut is_double_quote = false;

        while let Some(c) = chars.next() {
            match c {
                '\'' => {
                    if !is_double_quote {
                        is_single_quote = !is_single_quote;
                    } else {
                        expanded.push(c);
                    }
                }
                '"' => {
                    if !is_single_quote {
                        is_double_quote = !is_double_quote;
                    } else {
                        expanded.push(c);
                    }
                }
                '\\' => {
                    if let Some(c) = chars.next() {
                        if matches!(c, '"' | '\'' | ' ' | '~') {
                            expanded.push(c);
                        } else {
                            return Err(ArgumentError::InvalidEscape(c));
                        }
                    } else {
                        return Err(ArgumentError::UnexpectedEndOfLine);
                    }
                }
                _ => expanded.push(c),
            }
        }

        if is_single_quote {
            return Err(ArgumentError::UnterminatedSequence('\''));
        } else if is_double_quote {
            return Err(ArgumentError::UnterminatedSequence('\"'));
        } else {
            words.push(expanded);
        }
    }

    Ok(words)
}
/// Remove all non-escaped strings.
Remove all non-escaped strings.
Remove all non - escaped strings .
fn expand_quotes(argv: Vec<String>) -> Result<Vec<String>, ArgumentError> {
    let mut words = vec![];
    for word in argv {
        let mut expanded = String::new();
        let mut chars = word.chars();
        let mut is_single_quote = false;
        let mut is_double_quote = false;
        while let Some(c) = chars.next() {
            match c {
                '\'' => {
                    if !is_double_quote {
                        is_single_quote = !is_single_quote;
                    } else {
                        expanded.push(c);
                    }
                }
                '"' => {
                    if !is_single_quote {
                        is_double_quote = !is_double_quote;
                    } else {
                        expanded.push(c);
                    }
                }
                '\\' => {
                    if let Some(c) = chars.next() {
                        if matches!(c, '"' | '\'' | ' ' | '~') {
                            expanded.push(c);
                        } else {
                            return Err(ArgumentError::InvalidEscape(c));
                        }
                    } else {
                        return Err(ArgumentError::UnexpectedEndOfLine);
                    }
                }
                _ => expanded.push(c),
            }
        }
        if is_single_quote {
            return Err(ArgumentError::UnterminatedSequence('\''));
        } else if is_double_quote {
            return Err(ArgumentError::UnterminatedSequence('\"'));
        } else {
            words.push(expanded);
        }
    }
    Ok(words)
}
fn expand_quotes ( argv : Vec < String > ) -> Result < Vec < String > , ArgumentError > { let mut words = vec ! [ ] ; for word in argv { let mut expanded = String :: new ( ) ; let mut chars = word . chars ( ) ; let mut is_single_quote = false ; let mut is_double_quote = false ; while let Some ( c ) = chars . next ( ) { match c { '\'' => { if ! is_double_quote { is_single_quote = ! is_single_quote ; } else { expanded . push ( c ) ; } } '"' => { if ! is_single_quote { is_double_quote = ! is_double_quote ; } else { expanded . push ( c ) ; } } '\\' => { if let Some ( c ) = chars . next ( ) { if matches ! ( c '"' '\'' ' ' '~' ) { expanded . push ( c ) ; } else { return Err ( ArgumentError :: InvalidEscape ( c ) ) ; } } else { return Err ( ArgumentError :: UnexpectedEndOfLine ) ; } } _ => expanded . push ( c ) , } } if is_single_quote { return Err ( ArgumentError :: UnterminatedSequence ( '\'' ) ) ; } else if is_double_quote { return Err ( ArgumentError :: UnterminatedSequence ( '\"' ) ) ; } else { words . push ( expanded ) ; } } Ok ( words ) }
Remove all non-escaped strings.
Remove all non - escaped strings .
argv
Vec<String>