diff options
| author | MrDmitry <aidenhaledev@gmail.com> | 2024-01-25 22:03:21 -0500 |
|---|---|---|
| committer | MrDmitry <aidenhaledev@gmail.com> | 2024-01-26 13:33:17 -0500 |
| commit | 9ecbf533889d50d5a8eb1a36891a4a9b91a6a1f9 (patch) | |
| tree | e57369b98a6f8aeaafe4429be06cc907a0b65444 /lib/std/Build/Step/ConfigHeader.zig | |
| parent | 3e6f07e617707ddebab138d9d3208b69b43065eb (diff) | |
| download | zig-9ecbf533889d50d5a8eb1a36891a4a9b91a6a1f9.tar.gz zig-9ecbf533889d50d5a8eb1a36891a4a9b91a6a1f9.zip | |
Minor formatting, removed duplicate test case
Diffstat (limited to 'lib/std/Build/Step/ConfigHeader.zig')
| -rw-r--r-- | lib/std/Build/Step/ConfigHeader.zig | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index f1d03d2361..a2a55158a7 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -549,8 +549,8 @@ fn expand_variables_cmake( contents: []const u8, values: std.StringArrayHashMap(Value), ) ![]const u8 { - var content_buf = allocator.alloc(u8, 0) catch @panic("OOM"); - errdefer allocator.free(content_buf); + var result = allocator.alloc(u8, 0) catch @panic("OOM"); + errdefer allocator.free(result); const valid_varname_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/_.+-"; const open_var = "${"; @@ -580,9 +580,9 @@ fn expand_variables_cmake( const key = contents[curr + 1 .. close_pos]; const value = values.get(key) orelse .undef; const missing = contents[source_offset..curr]; - const buf = try std.fmt.allocPrint(allocator, "{s}{s}{}", .{ content_buf, missing, fmtValueCMake(value) }); - allocator.free(content_buf); - content_buf = buf; + const buf = try std.fmt.allocPrint(allocator, "{s}{s}{}", .{ result, missing, fmtValueCMake(value) }); + allocator.free(result); + result = buf; curr = close_pos; source_offset = close_pos + 1; @@ -597,15 +597,15 @@ fn expand_variables_cmake( break :blk; } const missing = contents[source_offset..curr]; - const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ content_buf, missing, open_var }); - allocator.free(content_buf); - content_buf = buf; + const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ result, missing, open_var }); + allocator.free(result); + result = buf; source_offset = curr + open_var.len; curr = next; try var_stack.append(Position{ .source = curr, - .target = content_buf.len - open_var.len, + .target = result.len - open_var.len, }); continue :loop; @@ -621,13 +621,13 @@ fn expand_variables_cmake( } const missing = contents[source_offset..curr]; const key_start = open_pos.target + open_var.len; - const key = try std.fmt.allocPrint(allocator, "{s}{s}", .{ content_buf[key_start..], missing }); + const key = try std.fmt.allocPrint(allocator, "{s}{s}", .{ result[key_start..], missing }); defer allocator.free(key); const value = values.get(key) orelse .undef; - const buf = try std.fmt.allocPrint(allocator, "{s}{}", .{ content_buf[0..open_pos.target], fmtValueCMake(value) }); - allocator.free(content_buf); - content_buf = buf; + const buf = try std.fmt.allocPrint(allocator, "{s}{}", .{ result[0..open_pos.target], fmtValueCMake(value) }); + allocator.free(result); + result = buf; source_offset = curr + 1; @@ -646,12 +646,12 @@ fn expand_variables_cmake( } if (source_offset != contents.len) { - const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ content_buf, contents[source_offset..] }); - allocator.free(content_buf); - content_buf = buf; + const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ result, contents[source_offset..] }); + allocator.free(result); + result = buf; } - return content_buf; + return result; } fn testReplaceVariables( @@ -681,7 +681,6 @@ test "expand_variables_cmake simple cases" { // empty strings are preserved try testReplaceVariables(allocator, "", "", values); - try testReplaceVariables(allocator, "", "", values); // line with misc content is preserved try testReplaceVariables(allocator, "no substitution", "no substitution", values); |
