pub fn parse(cmd: &str) -> Result<Vec<String>, Error> {
    let mut args: Vec<String> = Vec::new();
    let mut arg: String = String::new();
    let mut slash: usize = 0;
    let mut quote = false;
    let mut data = false;
    for c in cmd.chars() {
        match c {
            ' ' | '\t' | '\n' | '\r' => {
                arg = add_slashes(
                    arg,
                    if quote && ((slash % 2) == 0) {
                        slash / 2
                    } else {
                        slash
                    },
                );
                slash = 0;
                if quote {
                    arg.push(c);
                    data = true;
                } else if data {
                    args.push(arg);
                    arg = String::new();
                    data = false;
                }
            }
            '\\' => {
                slash += 1;
                data = true;
            }
            '"' => {
                arg = add_slashes(arg, slash / 2);
                if (slash & 1) == 0 {
                    quote = !quote;
                } else {
                    arg.push(c);
                }
                slash = 0;
                data = true;
            }
            _ => {
                arg = add_slashes(
                    arg,
                    if quote && ((slash % 2) == 0) {
                        slash / 2
                    } else {
                        slash
                    },
                );
                slash = 0;
                arg.push(c);
                data = true;
            }
        }
    }
    arg = add_slashes(
        arg,
        if quote && ((slash % 2) == 0) {
            slash / 2
        } else {
            slash
        },
    );
    if data {
        args.push(arg);
    }
    Ok(args)
}
// Parsing command line arguments from singe line.
// See also: http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
Parsing command line arguments from singe line.
Parsing command line arguments from singe line .
pub fn parse(cmd: &str) -> Result<Vec<String>, Error> {
    let mut args: Vec<String> = Vec::new();
    let mut arg: String = String::new();
    let mut slash: usize = 0;
    let mut quote = false;
    let mut data = false;
    for c in cmd.chars() {
        match c {
            ' ' | '\t' | '\n' | '\r' => {
                arg = add_slashes(
                    arg,
                    if quote && ((slash % 2) == 0) {
                        slash / 2
                    } else {
                        slash
                    },
                );
                slash = 0;
                if quote {
                    arg.push(c);
                    data = true;
                } else if data {
                    args.push(arg);
                    arg = String::new();
                    data = false;
                }
            }
            '\\' => {
                slash += 1;
                data = true;
            }
            '"' => {
                arg = add_slashes(arg, slash / 2);
                if (slash & 1) == 0 {
                    quote = !quote;
                } else {
                    arg.push(c);
                }
                slash = 0;
                data = true;
            }
            _ => {
                arg = add_slashes(
                    arg,
                    if quote && ((slash % 2) == 0) {
                        slash / 2
                    } else {
                        slash
                    },
                );
                slash = 0;
                arg.push(c);
                data = true;
            }
        }
    }
    arg = add_slashes(
        arg,
        if quote && ((slash % 2) == 0) {
            slash / 2
        } else {
            slash
        },
    );
    if data {
        args.push(arg);
    }
    Ok(args)
}
pub fn parse ( cmd : & str ) -> Result < Vec < String > , Error > { let mut args : Vec < String > = Vec :: new ( ) ; let mut arg : String = String :: new ( ) ; let mut slash : usize = 0 ; let mut quote = false ; let mut data = false ; for c in cmd . chars ( ) { match c { ' ' | '\t' | '\n' | '\r' => { arg = add_slashes ( arg , if quote && ( ( slash % 2 ) == 0 ) { slash / 2 } else { slash } , ) ; slash = 0 ; if quote { arg . push ( c ) ; data = true ; } else if data { args . push ( arg ) ; arg = String :: new ( ) ; data = false ; } } '\\' => { slash += 1 ; data = true ; } '"' => { arg = add_slashes ( arg , slash / 2 ) ; if ( slash & 1 ) == 0 { quote = ! quote ; } else { arg . push ( c ) ; } slash = 0 ; data = true ; } _ => { arg = add_slashes ( arg , if quote && ( ( slash % 2 ) == 0 ) { slash / 2 } else { slash } , ) ; slash = 0 ; arg . push ( c ) ; data = true ; } } } arg = add_slashes ( arg , if quote && ( ( slash % 2 ) == 0 ) { slash / 2 } else { slash } , ) ; if data { args . push ( arg ) ; } Ok ( args ) }
Parsing command line arguments from singe line.
Parsing command line arguments from singe line .
cmd
&str
cmd
&str