feat: add string functions
This commit is contained in:
parent
2939c05b19
commit
e7059360a3
1 changed files with 21 additions and 1 deletions
22
src/main.zig
22
src/main.zig
|
@ -1,6 +1,10 @@
|
|||
const std = @import("std");
|
||||
const c = @import("nvim_c");
|
||||
|
||||
test {
|
||||
std.testing.refAllDeclsRecursive(@This());
|
||||
}
|
||||
|
||||
/// Convenient wrapper for nvim's Error
|
||||
pub const Error = struct {
|
||||
err: c.Error = .{ .type = c.kErrorTypeNone, .msg = null },
|
||||
|
@ -10,6 +14,7 @@ pub const Error = struct {
|
|||
c.kErrorTypeNone => {},
|
||||
c.kErrorTypeValidation => return error.NvimValidation,
|
||||
c.kErrorTypeException => return error.NvimException,
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +26,22 @@ pub const Error = struct {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn msg(self: Error) ?[:0]u8 {
|
||||
pub fn msg(self: Error) ?[*:0]u8 {
|
||||
return self.err.msg;
|
||||
}
|
||||
};
|
||||
|
||||
pub fn nvimString(data: []u8) c.String {
|
||||
return .{
|
||||
.data = data.ptr,
|
||||
.size = data.len,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn constNvimString(data: []const u8) c.String {
|
||||
return nvimString(@constCast(data));
|
||||
}
|
||||
|
||||
pub fn zigString(data: c.String) []u8 {
|
||||
return data.data[0..data.size];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue