Something went wrong. Try again.
Convert CSV banking statements to hledger journals
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071const std = @import("std");
const Diagnostic = @This();const Writer = std.Io.Writer;
/// Human-readable. Wording and ordering are not a stable interface/// (M1-CLI-008); the structured fields below are.message: []const u8,
/// A CSV path relative to `inputPath` using '/' separators, or a/// configuration file (M1-DIAG-001, M1-DIAG-002).file: ?[]const u8 = null,
/// Zero-based CSV record ordinal, counting skipped and header records/// (M1-DIAG-001).physical_row: ?usize = null,
/// Dotted configuration key path (M1-DIAG-002).key_path: ?[]const u8 = null,
/// Position within a configuration file, when one was reported/// (M1-YAML-010).line_col: ?LineCol = null,
/// The approved journal of a historical pair; `file` holds its CSV/// (M1-DIAG-003).journal: ?[]const u8 = null,
/// Zero-based indices of the differing transaction and posting/// (M1-DIAG-003).transaction: ?usize = null,posting: ?usize = null,
/// One-based position, as libyaml reports it (M1-YAML-010).pub const LineCol = struct { column: usize, line: usize,};
pub fn format(self: Diagnostic, writer: *Writer) Writer.Error!void { if (self.file) |file| { try writer.writeAll(file);
// M1-DIAG-003: the pair, when this is a historical difference. if (self.journal) |journal| { try writer.print(" <-> {s}", .{journal}); }
// M1-DIAG-001: the physical row. if (self.physical_row) |row| { try writer.print(":{d}", .{row}); } // M1-DIAG-002: the configuration key. if (self.key_path) |path| { if (path.len > 0) try writer.print(" [{s}]", .{path}); } if (self.line_col) |at| { try writer.print(" ({d}:{d})", .{ at.line, at.column }); } if (self.transaction) |index| { try writer.print(" transaction {d}", .{index}); if (self.posting) |posting| { try writer.print(" posting {d}", .{posting}); } } try writer.writeAll(": "); } try writer.writeAll(self.message); try writer.writeAll("\n");}