Fix last_index after variable substitution

Iterative passes should start at the end of the previous substitution
This commit is contained in:
MrDmitry 2024-01-21 03:16:09 -05:00
parent 2e7d28dd0d
commit 2dfec13ef0

View File

@ -537,7 +537,7 @@ fn replace_variables(
switch (value) { switch (value) {
.boolean => |b| { .boolean => |b| {
const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, @intFromBool(b), endline }); const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, @intFromBool(b), endline });
last_index = start_index + 1; last_index = prefix_index + 1;
allocator.free(content_buf); allocator.free(content_buf);
content_buf = buf; content_buf = buf;
@ -546,14 +546,14 @@ fn replace_variables(
const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, i, endline }); const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, i, endline });
const isNegative = i < 0; const isNegative = i < 0;
const digits = (if (0 < i) std.math.log10(@abs(i)) else 0) + 1; const digits = (if (0 < i) std.math.log10(@abs(i)) else 0) + 1;
last_index = start_index + @intFromBool(isNegative) + digits + 1; last_index = prefix_index + @intFromBool(isNegative) + digits;
allocator.free(content_buf); allocator.free(content_buf);
content_buf = buf; content_buf = buf;
}, },
.string, .ident => |x| { .string, .ident => |x| {
const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ beginline, x, endline }); const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ beginline, x, endline });
last_index = start_index + x.len + 1; last_index = prefix_index + x.len;
allocator.free(content_buf); allocator.free(content_buf);
content_buf = buf; content_buf = buf;
@ -561,7 +561,7 @@ fn replace_variables(
else => { else => {
const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ beginline, endline }); const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ beginline, endline });
last_index = start_index + 1; last_index = prefix_index;
allocator.free(content_buf); allocator.free(content_buf);
content_buf = buf; content_buf = buf;