@@ -42,31 +42,33 @@ fn quote_arg(arg string) string {
4242 }
4343}
4444
45- // windows_quote_arg applies the backslash-and-quote rules Windows uses when it
46- // rebuilds argv from a command line. Wrapping in quotes is not enough on its own: a
47- // trailing backslash would escape the closing quote, so `C:\work space\` has to come
48- // out as `"C:\work space\\"` or it swallows the argument after it. This is the same
49- // escaping `os.Process` does in vlib/os/process_windows.c.v.
50- fn windows_quote_arg (arg string ) string {
51- mut out := '"'
52- mut pending_backslashes := 0
53- for c in arg {
54- if c == `\\ ` {
55- pending_backslashes++
56- continue
57- }
58- if c == `"` {
59- // Each backslash run before a quote is doubled, and the quote escaped.
60- out + = '\\ ' .repeat (pending_backslashes * 2 + 1 ) + '"'
45+ $if windows {
46+ // windows_quote_arg applies the backslash-and-quote rules Windows uses when it
47+ // rebuilds argv from a command line. Wrapping in quotes is not enough on its own: a
48+ // trailing backslash would escape the closing quote, so `C:\work space\` has to come
49+ // out as `"C:\work space\\"` or it swallows the argument after it. This is the same
50+ // escaping `os.Process` does in vlib/os/process_windows.c.v.
51+ fn windows_quote_arg (arg string ) string {
52+ mut out := '"'
53+ mut pending_backslashes := 0
54+ for c in arg {
55+ if c == `\\ ` {
56+ pending_backslashes++
57+ continue
58+ }
59+ if c == `"` {
60+ // Each backslash run before a quote is doubled, and the quote escaped.
61+ out + = '\\ ' .repeat (pending_backslashes * 2 + 1 ) + '"'
62+ pending_backslashes = 0
63+ continue
64+ }
65+ out + = '\\ ' .repeat (pending_backslashes) + c.ascii_str ()
6166 pending_backslashes = 0
62- continue
6367 }
64- out + = '\\ ' .repeat (pending_backslashes) + c.ascii_str ()
65- pending_backslashes = 0
68+ // The run that ends the argument is doubled, so none of it escapes the closing quote.
69+ out + = '\\ ' .repeat (pending_backslashes * 2 ) + '"'
70+ return out
6671 }
67- // The run that ends the argument is doubled, so none of it escapes the closing quote.
68- out + = '\\ ' .repeat (pending_backslashes * 2 ) + '"'
69- return out
7072}
7173
7274// seconds_to_duration converts a fractional number of seconds, as given on the
0 commit comments