fix watchlist loading
This commit is contained in:
parent
1f9f90357f
commit
afcc24be5e
1 changed files with 9 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
const std = @import("std");
|
||||
const zfin = @import("../root.zig");
|
||||
const srf = @import("srf");
|
||||
pub const fmt = @import("../format.zig");
|
||||
|
||||
// ── Default CLI colors (match TUI default Monokai theme) ─────
|
||||
|
|
@ -319,20 +320,22 @@ pub fn buildPortfolioData(
|
|||
|
||||
// ── Watchlist loading ────────────────────────────────────────
|
||||
|
||||
/// Load a watchlist file using the library's SRF deserializer.
|
||||
/// Load a watchlist SRF file containing symbol records.
|
||||
/// Returns owned symbol strings. Returns null if file missing or empty.
|
||||
pub fn loadWatchlist(allocator: std.mem.Allocator, path: []const u8) ?[][]const u8 {
|
||||
const file_data = std.fs.cwd().readFileAlloc(allocator, path, 1024 * 1024) catch return null;
|
||||
defer allocator.free(file_data);
|
||||
|
||||
var portfolio = zfin.cache.deserializePortfolio(allocator, file_data) catch return null;
|
||||
defer portfolio.deinit();
|
||||
const WatchEntry = struct { symbol: []const u8 };
|
||||
|
||||
if (portfolio.lots.len == 0) return null;
|
||||
var reader = std.Io.Reader.fixed(file_data);
|
||||
var it = srf.iterator(&reader, allocator, .{ .alloc_strings = false }) catch return null;
|
||||
defer it.deinit();
|
||||
|
||||
var syms: std.ArrayList([]const u8) = .empty;
|
||||
for (portfolio.lots) |lot| {
|
||||
const duped = allocator.dupe(u8, lot.symbol) catch continue;
|
||||
while (it.next() catch null) |fields| {
|
||||
const entry = fields.to(WatchEntry) catch continue;
|
||||
const duped = allocator.dupe(u8, entry.symbol) catch continue;
|
||||
syms.append(allocator, duped) catch {
|
||||
allocator.free(duped);
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue