fix: paths working on windows

This commit is contained in:
Vallahor 2022-05-25 14:35:27 -03:00 committed by Andrew Kelley
parent 7b11c23da6
commit cadee07ef4

View File

@ -292,10 +292,27 @@ const DocData = struct {
if (options.whitespace) |*ws| ws.indent_level += 1;
while (it.next()) |kv| : (idx += 1) {
if (options.whitespace) |ws| try ws.outputIndent(w);
try w.print("\"{s}\": {d}", .{
kv.key_ptr.*.sub_file_path,
kv.value_ptr.*,
});
const builtin = @import("builtin");
if (builtin.target.os.tag == .windows) {
try w.print("\"", .{});
for (kv.key_ptr.*.sub_file_path) |c| {
if (c == '\\') {
try w.print("\\", .{});
try w.print("\\", .{});
} else {
try w.print("{c}", .{c});
}
}
try w.print("\"", .{});
try w.print(": {d}", .{
kv.value_ptr.*,
});
} else {
try w.print("\"{s}\": {d}", .{
kv.key_ptr.*.sub_file_path,
kv.value_ptr.*,
});
}
if (idx != self.data.count() - 1) try w.writeByte(',');
try w.writeByte('\n');
}