summaryrefslogtreecommitdiff
path: root/src/DisplayWidth.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/DisplayWidth.zig')
-rw-r--r--src/DisplayWidth.zig20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/DisplayWidth.zig b/src/DisplayWidth.zig
index 11ec59e..c0d6d96 100644
--- a/src/DisplayWidth.zig
+++ b/src/DisplayWidth.zig
@@ -13,10 +13,10 @@ pub const DisplayWidthData = @import("DisplayWidthData");
13 13
14const Graphemes = @import("Graphemes"); 14const Graphemes = @import("Graphemes");
15 15
16g_data: Graphemes, 16graphemes: Graphemes,
17s1: []u16 = undefined, 17s1: []u16 = undefined,
18s2: []i4 = undefined, 18s2: []i4 = undefined,
19owns_gdata: bool, 19owns_graphemes: bool,
20 20
21const DisplayWidth = @This(); 21const DisplayWidth = @This();
22 22
@@ -26,16 +26,16 @@ pub fn init(allocator: mem.Allocator) mem.Allocator.Error!DisplayWidth {
26 allocator.free(dw.s1); 26 allocator.free(dw.s1);
27 allocator.free(dw.s2); 27 allocator.free(dw.s2);
28 } 28 }
29 dw.owns_gdata = true; 29 dw.owns_graphemes = true;
30 dw.g_data = try Graphemes.init(allocator); 30 dw.graphemes = try Graphemes.init(allocator);
31 errdefer dw.g_data.deinit(allocator); 31 errdefer dw.graphemes.deinit(allocator);
32 return dw; 32 return dw;
33} 33}
34 34
35pub fn initWithGraphemeData(allocator: mem.Allocator, g_data: Graphemes) mem.Allocator.Error!DisplayWidth { 35pub fn initWithGraphemes(allocator: mem.Allocator, graphemes: Graphemes) mem.Allocator.Error!DisplayWidth {
36 var dw = try DisplayWidth.setup(allocator); 36 var dw = try DisplayWidth.setup(allocator);
37 dw.g_data = g_data; 37 dw.graphemes = graphemes;
38 dw.owns_gdata = false; 38 dw.owns_graphemes = false;
39 return dw; 39 return dw;
40} 40}
41 41
@@ -67,7 +67,7 @@ fn setup(allocator: mem.Allocator) mem.Allocator.Error!DisplayWidth {
67pub fn deinit(dw: *const DisplayWidth, allocator: mem.Allocator) void { 67pub fn deinit(dw: *const DisplayWidth, allocator: mem.Allocator) void {
68 allocator.free(dw.s1); 68 allocator.free(dw.s1);
69 allocator.free(dw.s2); 69 allocator.free(dw.s2);
70 if (dw.owns_gdata) dw.g_data.deinit(allocator); 70 if (dw.owns_graphemes) dw.graphemes.deinit(allocator);
71} 71}
72 72
73/// codePointWidth returns the number of cells `cp` requires when rendered 73/// codePointWidth returns the number of cells `cp` requires when rendered
@@ -119,7 +119,7 @@ pub fn strWidth(dw: DisplayWidth, str: []const u8) usize {
119 return @intCast(@max(0, total)); 119 return @intCast(@max(0, total));
120 } 120 }
121 121
122 var giter = dw.g_data.iterator(str); 122 var giter = dw.graphemes.iterator(str);
123 123
124 while (giter.next()) |gc| { 124 while (giter.next()) |gc| {
125 var cp_iter = CodePointIterator{ .bytes = gc.bytes(str) }; 125 var cp_iter = CodePointIterator{ .bytes = gc.bytes(str) };