diff options
| author | 2025-04-30 15:59:56 -0400 | |
|---|---|---|
| committer | 2025-04-30 15:59:56 -0400 | |
| commit | 3a6cfa885697b5fecf0473b602dc38a0af0d3f7d (patch) | |
| tree | 64eacca86ec8302bf966e4731e125243067d8ba9 /src | |
| parent | Rest of the Renamings (diff) | |
| download | zg-3a6cfa885697b5fecf0473b602dc38a0af0d3f7d.tar.gz zg-3a6cfa885697b5fecf0473b602dc38a0af0d3f7d.tar.xz zg-3a6cfa885697b5fecf0473b602dc38a0af0d3f7d.zip | |
Update README.md to new API
Diffstat (limited to 'src')
| -rw-r--r-- | src/DisplayWidth.zig | 20 |
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 | ||
| 14 | const Graphemes = @import("Graphemes"); | 14 | const Graphemes = @import("Graphemes"); |
| 15 | 15 | ||
| 16 | g_data: Graphemes, | 16 | graphemes: Graphemes, |
| 17 | s1: []u16 = undefined, | 17 | s1: []u16 = undefined, |
| 18 | s2: []i4 = undefined, | 18 | s2: []i4 = undefined, |
| 19 | owns_gdata: bool, | 19 | owns_graphemes: bool, |
| 20 | 20 | ||
| 21 | const DisplayWidth = @This(); | 21 | const 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 | ||
| 35 | pub fn initWithGraphemeData(allocator: mem.Allocator, g_data: Graphemes) mem.Allocator.Error!DisplayWidth { | 35 | pub 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 { | |||
| 67 | pub fn deinit(dw: *const DisplayWidth, allocator: mem.Allocator) void { | 67 | pub 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) }; |