refactor: add egc_chunk_col_pos function

This commit is contained in:
CJ van den Berg 2025-12-12 14:27:49 +01:00
parent 660449c1c0
commit 42ddbe5f2f
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 19 additions and 0 deletions

View file

@ -482,6 +482,21 @@ pub fn egc_chunk_width(self: *const Plane, chunk_: []const u8, abs_col_: usize,
return colcount;
}
pub fn egc_chunk_col_pos(self: *const Plane, chunk_: []const u8, abs_col_: usize, tab_width: usize, col: usize) usize {
var abs_col = abs_col_;
var chunk = chunk_;
var colcount: usize = 0;
var cols: c_int = 0;
while (chunk.len > 0 and colcount < col) {
const bytes = self.egc_length(chunk, &cols, abs_col, tab_width);
colcount += @intCast(cols);
abs_col += @intCast(cols);
if (chunk.len < bytes) break;
chunk = chunk[bytes..];
}
return chunk_.len - chunk.len;
}
pub fn egc_last(egcs: []const u8) []const u8 {
var iter = vaxis.unicode.graphemeIterator(egcs);
var last: []const u8 = egcs[0..0];

View file

@ -1749,6 +1749,10 @@ pub fn egc_chunk_width(chunk: []const u8, abs_col: usize, tab_width: usize) usiz
return plane().egc_chunk_width(chunk, abs_col, tab_width);
}
pub fn egc_chunk_col_pos(chunk: []const u8, abs_col: usize, tab_width: usize, col: usize) usize {
return plane().egc_chunk_col_pos(chunk, abs_col, tab_width, col);
}
pub fn egc_last(egcs: []const u8) []const u8 {
return renderer.Plane.egc_last(egcs);
}