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(...@@ -549,8 +549,8 @@ fn expand_variables_cmake(
549 contents: []const u8,549 contents: []const u8,
550 values: std.StringArrayHashMap(Value),550 values: std.StringArrayHashMap(Value),
551) ![]const u8 {551) ![]const u8 {
552 var content_buf = allocator.alloc(u8, 0) catch @panic("OOM");552 var result = allocator.alloc(u8, 0) catch @panic("OOM");
553 errdefer allocator.free(content_buf);553 errdefer allocator.free(result);
554554
555 const valid_varname_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/_.+-";555 const valid_varname_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/_.+-";
556 const open_var = "${";556 const open_var = "${";
...@@ -580,9 +580,9 @@ fn expand_variables_cmake(...@@ -580,9 +580,9 @@ fn expand_variables_cmake(
580 const key = contents[curr + 1 .. close_pos];580 const key = contents[curr + 1 .. close_pos];
581 const value = values.get(key) orelse .undef;581 const value = values.get(key) orelse .undef;
582 const missing = contents[source_offset..curr];582 const missing = contents[source_offset..curr];
583 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{}", .{ content_buf, missing, fmtValueCMake(value) });583 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{}", .{ result, missing, fmtValueCMake(value) });
584 allocator.free(content_buf);584 allocator.free(result);
585 content_buf = buf;585 result = buf;
586586
587 curr = close_pos;587 curr = close_pos;
588 source_offset = close_pos + 1;588 source_offset = close_pos + 1;
...@@ -597,15 +597,15 @@ fn expand_variables_cmake(...@@ -597,15 +597,15 @@ fn expand_variables_cmake(
597 break :blk;597 break :blk;
598 }598 }
599 const missing = contents[source_offset..curr];599 const missing = contents[source_offset..curr];
600 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ content_buf, missing, open_var });600 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ result, missing, open_var });
601 allocator.free(content_buf);601 allocator.free(result);
602 content_buf = buf;602 result = buf;
603603
604 source_offset = curr + open_var.len;604 source_offset = curr + open_var.len;
605 curr = next;605 curr = next;
606 try var_stack.append(Position{606 try var_stack.append(Position{
607 .source = curr,607 .source = curr,
608 .target = content_buf.len - open_var.len,608 .target = result.len - open_var.len,
609 });609 });
610610
611 continue :loop;611 continue :loop;
...@@ -621,13 +621,13 @@ fn expand_variables_cmake(...@@ -621,13 +621,13 @@ fn expand_variables_cmake(
621 }621 }
622 const missing = contents[source_offset..curr];622 const missing = contents[source_offset..curr];
623 const key_start = open_pos.target + open_var.len;623 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 });
625 defer allocator.free(key);625 defer allocator.free(key);
626626
627 const value = values.get(key) orelse .undef;627 const value = values.get(key) orelse .undef;
628 const buf = try std.fmt.allocPrint(allocator, "{s}{}", .{ content_buf[0..open_pos.target], fmtValueCMake(value) });628 const buf = try std.fmt.allocPrint(allocator, "{s}{}", .{ result[0..open_pos.target], fmtValueCMake(value) });
629 allocator.free(content_buf);629 allocator.free(result);
630 content_buf = buf;630 result = buf;
631631
632 source_offset = curr + 1;632 source_offset = curr + 1;
633633
...@@ -646,12 +646,12 @@ fn expand_variables_cmake(...@@ -646,12 +646,12 @@ fn expand_variables_cmake(
646 }646 }
647647
648 if (source_offset != contents.len) {648 if (source_offset != contents.len) {
649 const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ content_buf, contents[source_offset..] });649 const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ result, contents[source_offset..] });
650 allocator.free(content_buf);650 allocator.free(result);
651 content_buf = buf;651 result = buf;
652 }652 }
653653
654 return content_buf;654 return result;
655}655}
656656
657fn testReplaceVariables(657fn testReplaceVariables(
...@@ -681,7 +681,6 @@ test "expand_variables_cmake simple cases" {...@@ -681,7 +681,6 @@ test "expand_variables_cmake simple cases" {
681681
682 // empty strings are preserved682 // empty strings are preserved
683 try testReplaceVariables(allocator, "", "", values);683 try testReplaceVariables(allocator, "", "", values);
684 try testReplaceVariables(allocator, "", "", values);
685684
686 // line with misc content is preserved685 // line with misc content is preserved
687 try testReplaceVariables(allocator, "no substitution", "no substitution", values);686 try testReplaceVariables(allocator, "no substitution", "no substitution", values);