refactor: add Cursor char_at, char_left/_right, test_left/_right functions
This commit is contained in:
parent
3db11a43c9
commit
bb53ba0fc1
1 changed files with 29 additions and 0 deletions
|
|
@ -193,10 +193,39 @@ pub fn egc_at(self: *const Self, root: Buffer.Root, metrics: Metrics) error{NotF
|
|||
return root.egc_at(self.row, self.col, metrics);
|
||||
}
|
||||
|
||||
pub fn char_at(self: *const Self, root: Buffer.Root, metrics: Metrics) []const u8 {
|
||||
const char, _, _ = root.egc_at(self.row, self.col, metrics) catch return &.{};
|
||||
return char;
|
||||
}
|
||||
|
||||
pub fn char_left(self: *const Self, root: Buffer.Root, metrics: Metrics) []const u8 {
|
||||
var tmp = self.*;
|
||||
tmp.move_left(root, metrics) catch return &.{};
|
||||
return tmp.char_at(root, metrics);
|
||||
}
|
||||
|
||||
pub fn char_right(self: *const Self, root: Buffer.Root, metrics: Metrics) []const u8 {
|
||||
var tmp = self.*;
|
||||
tmp.move_right(root, metrics) catch return &.{};
|
||||
return tmp.char_at(root, metrics);
|
||||
}
|
||||
|
||||
pub fn test_at(self: *const Self, root: Buffer.Root, pred: *const fn (c: []const u8) bool, metrics: Metrics) bool {
|
||||
return root.test_at(pred, self.row, self.col, metrics);
|
||||
}
|
||||
|
||||
pub fn test_left(self: *const Self, root: Buffer.Root, pred: *const fn (c: []const u8) bool, metrics: Metrics) bool {
|
||||
var tmp = self.*;
|
||||
tmp.move_left(root, metrics) catch return false;
|
||||
return root.test_at(pred, tmp.row, tmp.col, metrics);
|
||||
}
|
||||
|
||||
pub fn test_right(self: *const Self, root: Buffer.Root, pred: *const fn (c: []const u8) bool, metrics: Metrics) bool {
|
||||
var tmp = self.*;
|
||||
tmp.move_right(root, metrics) catch return false;
|
||||
return root.test_at(pred, tmp.row, tmp.col, metrics);
|
||||
}
|
||||
|
||||
pub fn write(self: *const Self, writer: *std.Io.Writer) !void {
|
||||
try cbor.writeValue(writer, .{
|
||||
self.row,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue