From 42ca3576049192754be02f6aac054cf95ba17d1b Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Mon, 26 Jun 2023 08:23:05 +0200 Subject: [PATCH] std.Build: omit newline from last line --- lib/std/Build/Step/ConfigHeader.zig | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index 3d4ed628cc..a697d7eda8 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -303,10 +303,7 @@ fn render_cmake( var line_index: u32 = 0; var line_it = std.mem.splitScalar(u8, contents, '\n'); while (line_it.next()) |raw_line| : (line_index += 1) { - // if we reached the end of the buffer there is nothing worth doing anymore - if (line_it.index == line_it.buffer.len) { - continue; - } + const last_line = line_it.index == line_it.buffer.len; const first_pass = replace_variables(allocator, raw_line, values, "@", "@") catch @panic("Failed to substitute"); const line = replace_variables(allocator, first_pass, values, "${", "}") catch @panic("Failed to substitute"); @@ -316,7 +313,9 @@ fn render_cmake( if (!std.mem.startsWith(u8, line, "#")) { try output.appendSlice(line); - try output.appendSlice("\n"); + if (!last_line) { + try output.appendSlice("\n"); + } continue; } var it = std.mem.tokenizeAny(u8, line[1..], " \t\r"); @@ -325,7 +324,9 @@ fn render_cmake( !std.mem.eql(u8, cmakedefine, "cmakedefine01")) { try output.appendSlice(line); - try output.appendSlice("\n"); + if (!last_line) { + try output.appendSlice("\n"); + } continue; }