fn CpuinfoParser(comptime impl: anytype) type 429
430
431
432
433
434
435
436
437
438
439
440
441
442fn CpuinfoParser(comptime impl: anytype) type {
return struct {
fn parse(arch: Target.Cpu.Arch, reader: *Io.Reader) !?Target.Cpu {
var obj: impl = .{};
while (try reader.takeDelimiter('\n')) |line| {
const colon_pos = mem.findScalar(u8, line, ':') orelse continue;
const key = mem.trimEnd(u8, line[0..colon_pos], " \t");
const value = mem.trimStart(u8, line[colon_pos + 1 ..], " \t");
if (!try obj.line_hook(key, value)) break;
}
return obj.finalize(arch);
}
};
}
The generic implementation of a /proc/cpuinfo parser. For every line it invokes the line_hook method with the key and value strings as first and second parameters. Returning false from the hook function stops the iteration without raising an error. When all the lines have been analyzed the finalize method is called.