authorgravatar for carter.sande@duodecima.technologyCarter Sande <carter.sande@duodecima.technology> 2020-06-22 02:53:14-07:00
committergravatar for carter.sande@duodecima.technologyCarter Sande <carter.sande@duodecima.technology> 2020-06-22 03:03:30-07:00
log7cb41a415a6eca7d13980a62ee5727b4adcad8b0
treecbe3affdbc5b7c1a664e3601d4f2abcf22adff6e
parent8faa85ac19e1bbbe962d69b283c94526e35f5338

ArgIteratorWindows: simplify quote state tracking


1 files changed, 6 insertions(+), 8 deletions(-)

lib/std/process.zig+6-8
......@@ -281,8 +281,6 @@ pub const ArgIteratorWasi = struct {
281281pub const ArgIteratorWindows = struct {
282282 index: usize,
283283 cmd_line: [*]const u8,
284 in_quote: bool,
285 seen_quote_count: usize,
286284
287285 pub const NextError = error{OutOfMemory};
288286
......@@ -294,8 +292,6 @@ pub const ArgIteratorWindows = struct {
294292 return ArgIteratorWindows{
295293 .index = 0,
296294 .cmd_line = cmd_line,
297 .in_quote = false,
298 .seen_quote_count = 0,
299295 };
300296 }
301297
......@@ -326,6 +322,7 @@ pub const ArgIteratorWindows = struct {
326322 }
327323
328324 var backslash_count: usize = 0;
325 var in_quote = false;
329326 while (true) : (self.index += 1) {
330327 const byte = self.cmd_line[self.index];
331328 switch (byte) {
......@@ -333,14 +330,14 @@ pub const ArgIteratorWindows = struct {
333330 '"' => {
334331 const quote_is_real = backslash_count % 2 == 0;
335332 if (quote_is_real) {
336 self.seen_quote_count += 1;
333 in_quote = !in_quote;
337334 }
338335 },
339336 '\\' => {
340337 backslash_count += 1;
341338 },
342339 ' ', '\t' => {
343 if (self.seen_quote_count % 2 == 0) {
340 if (!in_quote) {
344341 return true;
345342 }
346343 backslash_count = 0;
......@@ -358,6 +355,7 @@ pub const ArgIteratorWindows = struct {
358355 defer buf.deinit();
359356
360357 var backslash_count: usize = 0;
358 var in_quote = false;
361359 while (true) : (self.index += 1) {
362360 const byte = self.cmd_line[self.index];
363361 switch (byte) {
......@@ -368,7 +366,7 @@ pub const ArgIteratorWindows = struct {
368366 backslash_count = 0;
369367
370368 if (quote_is_real) {
371 self.seen_quote_count += 1;
369 in_quote = !in_quote;
372370 } else {
373371 try buf.append('"');
374372 }
......@@ -379,7 +377,7 @@ pub const ArgIteratorWindows = struct {
379377 ' ', '\t' => {
380378 try self.emitBackslashes(&buf, backslash_count);
381379 backslash_count = 0;
382 if (self.seen_quote_count % 2 == 1) {
380 if (in_quote) {
383381 try buf.append(byte);
384382 } else {
385383 return buf.toOwnedSlice();