| ... | ... | @@ -282,7 +282,6 @@ pub const ArgIteratorWindows = struct { |
| 282 | 282 | index: usize, |
| 283 | 283 | cmd_line: [*]const u8, |
| 284 | 284 | in_quote: bool, |
| 285 | | quote_count: usize, |
| 286 | 285 | seen_quote_count: usize, |
| 287 | 286 | |
| 288 | 287 | pub const NextError = error{OutOfMemory}; |
| ... | ... | @@ -296,7 +295,6 @@ pub const ArgIteratorWindows = struct { |
| 296 | 295 | .index = 0, |
| 297 | 296 | .cmd_line = cmd_line, |
| 298 | 297 | .in_quote = false, |
| 299 | | .quote_count = countQuotes(cmd_line), |
| 300 | 298 | .seen_quote_count = 0, |
| 301 | 299 | }; |
| 302 | 300 | } |
| ... | ... | @@ -342,7 +340,7 @@ pub const ArgIteratorWindows = struct { |
| 342 | 340 | backslash_count += 1; |
| 343 | 341 | }, |
| 344 | 342 | ' ', '\t' => { |
| 345 | | if (self.seen_quote_count % 2 == 0 or self.seen_quote_count == self.quote_count) { |
| 343 | if (self.seen_quote_count % 2 == 0) { |
| 346 | 344 | return true; |
| 347 | 345 | } |
| 348 | 346 | backslash_count = 0; |
| ... | ... | @@ -371,9 +369,6 @@ pub const ArgIteratorWindows = struct { |
| 371 | 369 | |
| 372 | 370 | if (quote_is_real) { |
| 373 | 371 | self.seen_quote_count += 1; |
| 374 | | if (self.seen_quote_count == self.quote_count and self.seen_quote_count % 2 == 1) { |
| 375 | | try buf.append('"'); |
| 376 | | } |
| 377 | 372 | } else { |
| 378 | 373 | try buf.append('"'); |
| 379 | 374 | } |
| ... | ... | @@ -384,7 +379,7 @@ pub const ArgIteratorWindows = struct { |
| 384 | 379 | ' ', '\t' => { |
| 385 | 380 | try self.emitBackslashes(&buf, backslash_count); |
| 386 | 381 | backslash_count = 0; |
| 387 | | if (self.seen_quote_count % 2 == 1 and self.seen_quote_count != self.quote_count) { |
| 382 | if (self.seen_quote_count % 2 == 1) { |
| 388 | 383 | try buf.append(byte); |
| 389 | 384 | } else { |
| 390 | 385 | return buf.toOwnedSlice(); |
| ... | ... | @@ -405,26 +400,6 @@ pub const ArgIteratorWindows = struct { |
| 405 | 400 | try buf.append('\\'); |
| 406 | 401 | } |
| 407 | 402 | } |
| 408 | | |
| 409 | | fn countQuotes(cmd_line: [*]const u8) usize { |
| 410 | | var result: usize = 0; |
| 411 | | var backslash_count: usize = 0; |
| 412 | | var index: usize = 0; |
| 413 | | while (true) : (index += 1) { |
| 414 | | const byte = cmd_line[index]; |
| 415 | | switch (byte) { |
| 416 | | 0 => return result, |
| 417 | | '\\' => backslash_count += 1, |
| 418 | | '"' => { |
| 419 | | result += 1 - (backslash_count % 2); |
| 420 | | backslash_count = 0; |
| 421 | | }, |
| 422 | | else => { |
| 423 | | backslash_count = 0; |
| 424 | | }, |
| 425 | | } |
| 426 | | } |
| 427 | | } |
| 428 | 403 | }; |
| 429 | 404 | |
| 430 | 405 | pub const ArgIterator = struct { |
| ... | ... | @@ -578,7 +553,7 @@ test "windows arg parsing" { |
| 578 | 553 | testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" }); |
| 579 | 554 | testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" }); |
| 580 | 555 | testWindowsCmdLine("a\\\\\\\\\"b c\" d e", &[_][]const u8{ "a\\\\b c", "d", "e" }); |
| 581 | | testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "\"d", "f" }); |
| 556 | testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "d f" }); |
| 582 | 557 | |
| 583 | 558 | testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{ |
| 584 | 559 | ".\\..\\zig-cache\\build", |