| ... | @@ -282,7 +282,6 @@ pub const ArgIteratorWindows = struct { | ... | @@ -282,7 +282,6 @@ pub const ArgIteratorWindows = struct { |
| 282 | index: usize, | 282 | index: usize, |
| 283 | cmd_line: [*]const u8, | 283 | cmd_line: [*]const u8, |
| 284 | in_quote: bool, | 284 | in_quote: bool, |
| 285 | quote_count: usize, | | |
| 286 | seen_quote_count: usize, | 285 | seen_quote_count: usize, |
| 287 | | 286 | |
| 288 | pub const NextError = error{OutOfMemory}; | 287 | pub const NextError = error{OutOfMemory}; |
| ... | @@ -296,7 +295,6 @@ pub const ArgIteratorWindows = struct { | ... | @@ -296,7 +295,6 @@ pub const ArgIteratorWindows = struct { |
| 296 | .index = 0, | 295 | .index = 0, |
| 297 | .cmd_line = cmd_line, | 296 | .cmd_line = cmd_line, |
| 298 | .in_quote = false, | 297 | .in_quote = false, |
| 299 | .quote_count = countQuotes(cmd_line), | | |
| 300 | .seen_quote_count = 0, | 298 | .seen_quote_count = 0, |
| 301 | }; | 299 | }; |
| 302 | } | 300 | } |
| ... | @@ -342,7 +340,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -342,7 +340,7 @@ pub const ArgIteratorWindows = struct { |
| 342 | backslash_count += 1; | 340 | backslash_count += 1; |
| 343 | }, | 341 | }, |
| 344 | ' ', '\t' => { | 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 | return true; | 344 | return true; |
| 347 | } | 345 | } |
| 348 | backslash_count = 0; | 346 | backslash_count = 0; |
| ... | @@ -371,9 +369,6 @@ pub const ArgIteratorWindows = struct { | ... | @@ -371,9 +369,6 @@ pub const ArgIteratorWindows = struct { |
| 371 | | 369 | |
| 372 | if (quote_is_real) { | 370 | if (quote_is_real) { |
| 373 | self.seen_quote_count += 1; | 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 | } else { | 372 | } else { |
| 378 | try buf.append('"'); | 373 | try buf.append('"'); |
| 379 | } | 374 | } |
| ... | @@ -384,7 +379,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -384,7 +379,7 @@ pub const ArgIteratorWindows = struct { |
| 384 | ' ', '\t' => { | 379 | ' ', '\t' => { |
| 385 | try self.emitBackslashes(&buf, backslash_count); | 380 | try self.emitBackslashes(&buf, backslash_count); |
| 386 | backslash_count = 0; | 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 | try buf.append(byte); | 383 | try buf.append(byte); |
| 389 | } else { | 384 | } else { |
| 390 | return buf.toOwnedSlice(); | 385 | return buf.toOwnedSlice(); |
| ... | @@ -405,26 +400,6 @@ pub const ArgIteratorWindows = struct { | ... | @@ -405,26 +400,6 @@ pub const ArgIteratorWindows = struct { |
| 405 | try buf.append('\\'); | 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 | pub const ArgIterator = struct { | 405 | pub const ArgIterator = struct { |
| ... | @@ -578,7 +553,7 @@ test "windows arg parsing" { | ... | @@ -578,7 +553,7 @@ test "windows arg parsing" { |
| 578 | testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" }); | 553 | testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" }); |
| 579 | testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" }); | 554 | testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" }); |
| 580 | testWindowsCmdLine("a\\\\\\\\\"b c\" d e", &[_][]const u8{ "a\\\\b c", "d", "e" }); | 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 | testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{ | 558 | testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{ |
| 584 | ".\\..\\zig-cache\\build", | 559 | ".\\..\\zig-cache\\build", |