fn parse_lp_cmd_line<S: IsWtf8Buf>(
    lp_cmd_line: &[u16],
) -> Vec<S> {
    const BACKSLASH: u16 = '\\' as u16;
    const QUOTE: u16 = '"' as u16;
    const TAB: u16 = '\t' as u16;
    const SPACE: u16 = ' ' as u16;

    let mut ret_val = Vec::new();
    if lp_cmd_line[0] == 0 {
        // NOTE: Here, CommandLineToArgvW would produce the current executable name, as
        //       given by GetModuleFileNameW.
        //
        //       For our purposes, it makes more sense to treat this the same way we would
        //       treat a string consisting entirely of whitespace.
        ret_val.push(S::from_str(""));
        return ret_val;
    }
    let mut cmd_line = {
        let mut end = 0;
        while lp_cmd_line[end] != 0 {
            end += 1;
        }
        &lp_cmd_line[..end]
    };
    // The executable name at the beginning is special.
    cmd_line = match cmd_line[0] {
        // The executable name ends at the next quote mark,
        // no matter what.
        QUOTE => {
            let args = {
                let mut cut = cmd_line[1..].splitn(2, |&c| c == QUOTE);
                if let Some(exe) = cut.next() {
                    ret_val.push(S::from_wide(exe));
                }
                cut.next()
            };
            if let Some(args) = args {
                args
            } else {
                return ret_val;
            }
        }
        // Implement quirk: when they say whitespace here,
        // they include the entire ASCII control plane:
        // "However, if lpCmdLine starts with any amount of whitespace, CommandLineToArgvW
        // will consider the first argument to be an empty string. Excess whitespace at the
        // end of lpCmdLine is ignored."
        0..=SPACE => {
            ret_val.push(S::from_str(""));
            &cmd_line[1..]
        },
        // The executable name ends at the next whitespace,
        // no matter what.
        _ => {
            let args = {
                let mut cut = cmd_line.splitn(2, |&c| c > 0 && c <= SPACE);
                if let Some(exe) = cut.next() {
                    ret_val.push(S::from_wide(exe));
                }
                cut.next()
            };
            if let Some(args) = args {
                args
            } else {
                return ret_val;
            }
        }
    };
    let mut cur = Vec::new();
    let mut in_quotes = false;
    let mut was_in_quotes = false;
    let mut backslash_count: usize = 0;
    for &c in cmd_line {
        match c {
            // backslash
            BACKSLASH => {
                backslash_count += 1;
                was_in_quotes = false;
            },
            QUOTE if backslash_count % 2 == 0 => {
                cur.extend(iter::repeat(b'\\' as u16).take(backslash_count / 2));
                backslash_count = 0;
                if was_in_quotes {
                    cur.push('"' as u16);
                    was_in_quotes = false;
                } else {
                    was_in_quotes = in_quotes;
                    in_quotes = !in_quotes;
                }
            }
            QUOTE if backslash_count % 2 != 0 => {
                cur.extend(iter::repeat(b'\\' as u16).take(backslash_count / 2));
                backslash_count = 0;
                was_in_quotes = false;
                cur.push(b'"' as u16);
            }
            SPACE | TAB if !in_quotes => {
                cur.extend(iter::repeat(b'\\' as u16).take(backslash_count));
                if !cur.is_empty() || was_in_quotes {
                    ret_val.push(S::from_wide(&cur[..]));
                    cur.truncate(0);
                }
                backslash_count = 0;
                was_in_quotes = false;
            }
            _ => {
                cur.extend(iter::repeat(b'\\' as u16).take(backslash_count));
                backslash_count = 0;
                was_in_quotes = false;
                cur.push(c);
            }
        }
    }
    cur.extend(iter::repeat(b'\\' as u16).take(backslash_count));
    // include empty quoted strings at the end of the arguments list
    if !cur.is_empty() || was_in_quotes || in_quotes {
        ret_val.push(S::from_wide(&cur[..]));
    }
    ret_val
}
/// Implements the Windows command-line argument parsing algorithm.
///
/// Microsoft's documentation for the Windows CLI argument format can be found at
/// <https://docs.microsoft.com/en-us/previous-versions//17w5ykft(v=vs.85)>.
///
/// Windows includes a function to do this in shell32.dll,
/// but linking with that DLL causes the process to be registered as a GUI application.
/// GUI applications add a bunch of overhead, even if no windows are drawn. See
/// <https://randomascii.wordpress.com/2018/12/03/a-not-called-function-can-cause-a-5x-slowdown/>.
Implements the Windows command-line argument parsing algorithm.
Microsoft's documentation for the Windows CLI argument format can be found at
.

Windows includes a function to do this in shell32.dll,
but linking with that DLL causes the process to be registered as a GUI application.
GUI applications add a bunch of overhead, even if no windows are drawn. See
.
Implements the Windows command - line argument parsing algorithm . Microsoft ' s documentation for the Windows CLI argument format can be found at . Windows includes a function to do this in shell32 . dll but linking with that DLL causes the process to be registered as a GUI application . GUI applications add a bunch of overhead even if no windows are drawn . See .
fn parse_lp_cmd_line<S: IsWtf8Buf>(
    lp_cmd_line: &[u16],
) -> Vec<S> {
    const BACKSLASH: u16 = '\\' as u16;
    const QUOTE: u16 = '"' as u16;
    const TAB: u16 = '\t' as u16;
    const SPACE: u16 = ' ' as u16;
    let mut ret_val = Vec::new();
    if lp_cmd_line[0] == 0 {
        // NOTE: Here, CommandLineToArgvW would produce the current executable name, as
        //       given by GetModuleFileNameW.
        //
        //       For our purposes, it makes more sense to treat this the same way we would
        //       treat a string consisting entirely of whitespace.
        ret_val.push(S::from_str(""));
        return ret_val;
    }
    let mut cmd_line = {
        let mut end = 0;
        while lp_cmd_line[end] != 0 {
            end += 1;
        }
        &lp_cmd_line[..end]
    };
    // The executable name at the beginning is special.
    cmd_line = match cmd_line[0] {
        // The executable name ends at the next quote mark,
        // no matter what.
        QUOTE => {
            let args = {
                let mut cut = cmd_line[1..].splitn(2, |&c| c == QUOTE);
                if let Some(exe) = cut.next() {
                    ret_val.push(S::from_wide(exe));
                }
                cut.next()
            };
            if let Some(args) = args {
                args
            } else {
                return ret_val;
            }
        }
        // Implement quirk: when they say whitespace here,
        // they include the entire ASCII control plane:
        // "However, if lpCmdLine starts with any amount of whitespace, CommandLineToArgvW
        // will consider the first argument to be an empty string. Excess whitespace at the
        // end of lpCmdLine is ignored."
        0..=SPACE => {
            ret_val.push(S::from_str(""));
            &cmd_line[1..]
        },
        // The executable name ends at the next whitespace,
        // no matter what.
        _ => {
            let args = {
                let mut cut = cmd_line.splitn(2, |&c| c > 0 && c <= SPACE);
                if let Some(exe) = cut.next() {
                    ret_val.push(S::from_wide(exe));
                }
                cut.next()
            };
            if let Some(args) = args {
                args
            } else {
                return ret_val;
            }
        }
    };
    let mut cur = Vec::new();
    let mut in_quotes = false;
    let mut was_in_quotes = false;
    let mut backslash_count: usize = 0;
    for &c in cmd_line {
        match c {
            // backslash
            BACKSLASH => {
                backslash_count += 1;
                was_in_quotes = false;
            },
            QUOTE if backslash_count % 2 == 0 => {
                cur.extend(iter::repeat(b'\\' as u16).take(backslash_count / 2));
                backslash_count = 0;
                if was_in_quotes {
                    cur.push('"' as u16);
                    was_in_quotes = false;
                } else {
                    was_in_quotes = in_quotes;
                    in_quotes = !in_quotes;
                }
            }
            QUOTE if backslash_count % 2 != 0 => {
                cur.extend(iter::repeat(b'\\' as u16).take(backslash_count / 2));
                backslash_count = 0;
                was_in_quotes = false;
                cur.push(b'"' as u16);
            }
            SPACE | TAB if !in_quotes => {
                cur.extend(iter::repeat(b'\\' as u16).take(backslash_count));
                if !cur.is_empty() || was_in_quotes {
                    ret_val.push(S::from_wide(&cur[..]));
                    cur.truncate(0);
                }
                backslash_count = 0;
                was_in_quotes = false;
            }
            _ => {
                cur.extend(iter::repeat(b'\\' as u16).take(backslash_count));
                backslash_count = 0;
                was_in_quotes = false;
                cur.push(c);
            }
        }
    }
    cur.extend(iter::repeat(b'\\' as u16).take(backslash_count));
    // include empty quoted strings at the end of the arguments list
    if !cur.is_empty() || was_in_quotes || in_quotes {
        ret_val.push(S::from_wide(&cur[..]));
    }
    ret_val
}
fn parse_lp_cmd_line < S : IsWtf8Buf > ( lp_cmd_line : & [ u16 ] , ) -> Vec < S > { const BACKSLASH : u16 = '\\' as u16 ; const QUOTE : u16 = '"' as u16 ; const TAB : u16 = '\t' as u16 ; const SPACE : u16 = ' ' as u16 ; let mut ret_val = Vec :: new ( ) ; if lp_cmd_line [ 0 ] == 0 { // NOTE: Here, CommandLineToArgvW would produce the current executable name, as //       given by GetModuleFileNameW. // //       For our purposes, it makes more sense to treat this the same way we would //       treat a string consisting entirely of whitespace. ret_val . push ( S :: from_str ( " " ) ) ; return ret_val ; } let mut cmd_line = { let mut end = 0 ; while lp_cmd_line [ end ] != 0 { end += 1 ; } & lp_cmd_line [ .. end ] } ; // The executable name at the beginning is special. cmd_line = match cmd_line [ 0 ] { // The executable name ends at the next quote mark, // no matter what. QUOTE => { let args = { let mut cut = cmd_line [ 1 .. ] . splitn ( 2 , | & c | c == QUOTE ) ; if let Some ( exe ) = cut . next ( ) { ret_val . push ( S :: from_wide ( exe ) ) ; } cut . next ( ) } ; if let Some ( args ) = args { args } else { return ret_val ; } } // Implement quirk: when they say whitespace here, // they include the entire ASCII control plane: // "However, if lpCmdLine starts with any amount of whitespace, CommandLineToArgvW // will consider the first argument to be an empty string. Excess whitespace at the // end of lpCmdLine is ignored." 0 ..= SPACE => { ret_val . push ( S :: from_str ( " " ) ) ; & cmd_line [ 1 .. ] } , // The executable name ends at the next whitespace, // no matter what. _ => { let args = { let mut cut = cmd_line . splitn ( 2 , | & c | c > 0 && c <= SPACE ) ; if let Some ( exe ) = cut . next ( ) { ret_val . push ( S :: from_wide ( exe ) ) ; } cut . next ( ) } ; if let Some ( args ) = args { args } else { return ret_val ; } } } ; let mut cur = Vec :: new ( ) ; let mut in_quotes = false ; let mut was_in_quotes = false ; let mut backslash_count : usize = 0 ; for & c in cmd_line { match c { // backslash BACKSLASH => { backslash_count += 1 ; was_in_quotes = false ; } , QUOTE if backslash_count % 2 == 0 => { cur . extend ( iter :: repeat ( b'\\' as u16 ) . take ( backslash_count / 2 ) ) ; backslash_count = 0 ; if was_in_quotes { cur . push ( '"' as u16 ) ; was_in_quotes = false ; } else { was_in_quotes = in_quotes ; in_quotes = ! in_quotes ; } } QUOTE if backslash_count % 2 != 0 => { cur . extend ( iter :: repeat ( b'\\' as u16 ) . take ( backslash_count / 2 ) ) ; backslash_count = 0 ; was_in_quotes = false ; cur . push ( b'"' as u16 ) ; } SPACE | TAB if ! in_quotes => { cur . extend ( iter :: repeat ( b'\\' as u16 ) . take ( backslash_count ) ) ; if ! cur . is_empty ( ) || was_in_quotes { ret_val . push ( S :: from_wide ( & cur [ .. ] ) ) ; cur . truncate ( 0 ) ; } backslash_count = 0 ; was_in_quotes = false ; } _ => { cur . extend ( iter :: repeat ( b'\\' as u16 ) . take ( backslash_count ) ) ; backslash_count = 0 ; was_in_quotes = false ; cur . push ( c ) ; } } } cur . extend ( iter :: repeat ( b'\\' as u16 ) . take ( backslash_count ) ) ; // include empty quoted strings at the end of the arguments list if ! cur . is_empty ( ) || was_in_quotes || in_quotes { ret_val . push ( S :: from_wide ( & cur [ .. ] ) ) ; } ret_val }
Implements the Windows command-line argument parsing algorithm.
Implements the Windows command - line argument parsing algorithm .
lp_cmd_line
&[u16]
lp_cmd_line
&[u16]