You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
ndg/lib/ini/example/example.zig

23 lines
737 B
Zig

const std = @import("std");
const ini = @import("ini");
pub fn main() !void {
const file = try std.fs.cwd().openFile("example.ini", .{});
defer file.close();
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer if (gpa.deinit() != .ok) @panic("memory leaked");
var parser = ini.parse(gpa.allocator(), file.reader());
defer parser.deinit();
var writer = std.io.getStdOut().writer();
while (try parser.next()) |record| {
switch (record) {
.section => |heading| try writer.print("[{s}]\n", .{heading}),
.property => |kv| try writer.print("{s} = {s}\n", .{ kv.key, kv.value }),
.enumeration => |value| try writer.print("{s}\n", .{value}),
}
}
}