Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ziglibs/ini
A teeny tiny ini parser
https://github.com/ziglibs/ini
ini ini-parser zig zig-package ziglang
Last synced: 3 months ago
JSON representation
A teeny tiny ini parser
- Host: GitHub
- URL: https://github.com/ziglibs/ini
- Owner: ziglibs
- License: mit
- Created: 2021-04-07T08:58:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-07-31T10:49:06.000Z (3 months ago)
- Last Synced: 2024-07-31T12:04:07.536Z (3 months ago)
- Topics: ini, ini-parser, zig, zig-package, ziglang
- Language: Zig
- Homepage:
- Size: 14.6 KB
- Stars: 21
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- awesome-zig - iniποΈA teeny tiny ini parser
README
# INI parser library
This is a very simple ini-parser library that provides:
- Raw record reading
- Leading/trailing whitespace removal
- comments based on `;` and `#`
- Zig API
- C API## Usage example
### Zig
```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 parser = ini.parse(std.testing.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}),
}
}
}
```### C
```c
#include#include
#includeint main() {
FILE * f = fopen("example.ini", "rb");
if(!f)
return 1;
struct ini_Parser parser;
ini_create_file(&parser, f);struct ini_Record record;
while(true)
{
enum ini_Error error = ini_next(&parser, &record);
if(error != INI_SUCCESS)
goto cleanup;
switch(record.type) {
case INI_RECORD_NUL: goto done;
case INI_RECORD_SECTION:
printf("[%s]\n", record.section);
break;
case INI_RECORD_PROPERTY:
printf("%s = %s\n", record.property.key, record.property.value);
break;
case INI_RECORD_ENUMERATION:
printf("%s\n", record.enumeration);
break;
}}
done:cleanup:
ini_destroy(&parser);
fclose(f);
return 0;
}
```