authorgravatar for aidenhaledev@gmail.comMrDmitry <aidenhaledev@gmail.com> 2024-01-25 22:03:21-05:00
committergravatar for aidenhaledev@gmail.comMrDmitry <aidenhaledev@gmail.com> 2024-01-26 13:33:17-05:00
log9ecbf533889d50d5a8eb1a36891a4a9b91a6a1f9
treee57369b98a6f8aeaafe4429be06cc907a0b65444
parent3e6f07e617707ddebab138d9d3208b69b43065eb

Minor formatting, removed duplicate test case


1 files changed, 17 insertions(+), 18 deletions(-)

lib/std/Build/Step/ConfigHeader.zig+17-18
......@@ -549,8 +549,8 @@ fn expand_variables_cmake(
549549 contents: []const u8,
550550 values: std.StringArrayHashMap(Value),
551551) ![]const u8 {
552 var content_buf = allocator.alloc(u8, 0) catch @panic("OOM");
553 errdefer allocator.free(content_buf);
552 var result = allocator.alloc(u8, 0) catch @panic("OOM");
553 errdefer allocator.free(result);
554554
555555 const valid_varname_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/_.+-";
556556 const open_var = "${";
......@@ -580,9 +580,9 @@ fn expand_variables_cmake(
580580 const key = contents[curr + 1 .. close_pos];
581581 const value = values.get(key) orelse .undef;
582582 const missing = contents[source_offset..curr];
583 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{}", .{ content_buf, missing, fmtValueCMake(value) });
584 allocator.free(content_buf);
585 content_buf = buf;
583 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{}", .{ result, missing, fmtValueCMake(value) });
584 allocator.free(result);
585 result = buf;
586586
587587 curr = close_pos;
588588 source_offset = close_pos + 1;
......@@ -597,15 +597,15 @@ fn expand_variables_cmake(
597597 break :blk;
598598 }
599599 const missing = contents[source_offset..curr];
600 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ content_buf, missing, open_var });
601 allocator.free(content_buf);
602 content_buf = buf;
600 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ result, missing, open_var });
601 allocator.free(result);
602 result = buf;
603603
604604 source_offset = curr + open_var.len;
605605 curr = next;
606606 try var_stack.append(Position{
607607 .source = curr,
608 .target = content_buf.len - open_var.len,
608 .target = result.len - open_var.len,
609609 });
610610
611611 continue :loop;
......@@ -621,13 +621,13 @@ fn expand_variables_cmake(
621621 }
622622 const missing = contents[source_offset..curr];
623623 const key_start = open_pos.target + open_var.len;
624 const key = try std.fmt.allocPrint(allocator, "{s}{s}", .{ content_buf[key_start..], missing });
624 const key = try std.fmt.allocPrint(allocator, "{s}{s}", .{ result[key_start..], missing });
625625 defer allocator.free(key);
626626
627627 const value = values.get(key) orelse .undef;
628 const buf = try std.fmt.allocPrint(allocator, "{s}{}", .{ content_buf[0..open_pos.target], fmtValueCMake(value) });
629 allocator.free(content_buf);
630 content_buf = buf;
628 const buf = try std.fmt.allocPrint(allocator, "{s}{}", .{ result[0..open_pos.target], fmtValueCMake(value) });
629 allocator.free(result);
630 result = buf;
631631
632632 source_offset = curr + 1;
633633
......@@ -646,12 +646,12 @@ fn expand_variables_cmake(
646646 }
647647
648648 if (source_offset != contents.len) {
649 const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ content_buf, contents[source_offset..] });
650 allocator.free(content_buf);
651 content_buf = buf;
649 const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ result, contents[source_offset..] });
650 allocator.free(result);
651 result = buf;
652652 }
653653
654 return content_buf;
654 return result;
655655}
656656
657657fn testReplaceVariables(
......@@ -681,7 +681,6 @@ test "expand_variables_cmake simple cases" {
681681
682682 // empty strings are preserved
683683 try testReplaceVariables(allocator, "", "", values);
684 try testReplaceVariables(allocator, "", "", values);
685684
686685 // line with misc content is preserved
687686 try testReplaceVariables(allocator, "no substitution", "no substitution", values);