diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-08-27 21:04:37 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-08-27 21:04:37 +0200 |
| commit | 28f47b8399c4f3c4a64921fb16e38e44e8ce749e (patch) | |
| tree | 53cde744130f2adf9c293fafde3c0a9c6a990d4b /src/Str.zig | |
first commit
Diffstat (limited to 'src/Str.zig')
| -rw-r--r-- | src/Str.zig | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Str.zig b/src/Str.zig new file mode 100644 index 0000000..eaca378 --- /dev/null +++ b/src/Str.zig @@ -0,0 +1,22 @@ + +const c = @import("c"); +const zpy = @import("root.zig"); + +const Self = @This(); + +object: zpy.Object, + + +pub fn asUtf8(self: *Self) zpy.Error![]const u8 { + var size: c.Py_ssize_t = undefined; + const string: [*]const u8 = c.PyUnicode_AsUTF8AndSize(self.object.ptr, &size); + + if (size == -1) return error.Exception; + + return string[0..@as(usize, @intCast(size))]; +} + +pub fn deinit(self: *Self) void { + self.object.decref(); + self.* = undefined; +} |