summaryrefslogtreecommitdiff
path: root/src/display_width.zig
diff options
context:
space:
mode:
authorGravatar Jose Colon Rodriguez2024-02-18 09:20:19 -0400
committerGravatar Jose Colon Rodriguez2024-02-18 09:20:19 -0400
commitf913551d27e07f0a7c7e201ba3141fd3a6cbb47c (patch)
tree74bfe0fb0aa98d053b5ab76beec6fdc733026017 /src/display_width.zig
parentCode point and grapheme are now namespaces. (diff)
downloadzg-f913551d27e07f0a7c7e201ba3141fd3a6cbb47c.tar.gz
zg-f913551d27e07f0a7c7e201ba3141fd3a6cbb47c.tar.xz
zg-f913551d27e07f0a7c7e201ba3141fd3a6cbb47c.zip
Code point code is now a method not a field.
Diffstat (limited to 'src/display_width.zig')
-rw-r--r--src/display_width.zig7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/display_width.zig b/src/display_width.zig
index e52da38..7f39566 100644
--- a/src/display_width.zig
+++ b/src/display_width.zig
@@ -52,17 +52,18 @@ pub fn strWidth(str: []const u8) usize {
52 var giter = GraphemeIterator.init(str); 52 var giter = GraphemeIterator.init(str);
53 53
54 while (giter.next()) |gc| { 54 while (giter.next()) |gc| {
55 var cp_iter = CodePointIterator{ .bytes = str[gc.offset..][0..gc.len] }; 55 const gc_bytes = gc.bytes(str);
56 var cp_iter = CodePointIterator{ .bytes = gc_bytes };
56 var gc_total: isize = 0; 57 var gc_total: isize = 0;
57 58
58 while (cp_iter.next()) |cp| { 59 while (cp_iter.next()) |cp| {
59 var w = codePointWidth(cp.code); 60 var w = codePointWidth(cp.code(gc_bytes));
60 61
61 if (w != 0) { 62 if (w != 0) {
62 // Handle text emoji sequence. 63 // Handle text emoji sequence.
63 if (cp_iter.next()) |ncp| { 64 if (cp_iter.next()) |ncp| {
64 // emoji text sequence. 65 // emoji text sequence.
65 if (ncp.code == 0xFE0E) w = 1; 66 if (ncp.code(gc_bytes) == 0xFE0E) w = 1;
66 } 67 }
67 68
68 // Only adding width of first non-zero-width code point. 69 // Only adding width of first non-zero-width code point.