diff options
| author | 2024-02-16 19:36:19 -0400 | |
|---|---|---|
| committer | 2024-02-16 19:36:19 -0400 | |
| commit | 4b7dfe149422efa848e62a791b5ca73c2065480b (patch) | |
| tree | 10cfa9ba79245d6a7489cb32a34fdace3c6eedfb /src/main.zig | |
| parent | build.zig module reorg (diff) | |
| download | zg-4b7dfe149422efa848e62a791b5ca73c2065480b.tar.gz zg-4b7dfe149422efa848e62a791b5ca73c2065480b.tar.xz zg-4b7dfe149422efa848e62a791b5ca73c2065480b.zip | |
display_width with table
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main.zig b/src/main.zig index fe49300..3e65c7b 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -1,7 +1,10 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | // const GraphemeIterator = @import("ziglyph").GraphemeIterator; | 3 | // const GraphemeIterator = @import("ziglyph").GraphemeIterator; |
| 4 | const GraphemeIterator = @import("Grapheme").GraphemeIterator; | 4 | // const GraphemeIterator = @import("Grapheme").GraphemeIterator; |
| 5 | // const codePointWidth = @import("ziglyph").display_width.codePointWidth; | ||
| 6 | const codePointWidth = @import("display_width").codePointWidth; | ||
| 7 | const CodePointIterator = @import("CodePoint").CodePointIterator; | ||
| 5 | 8 | ||
| 6 | pub fn main() !void { | 9 | pub fn main() !void { |
| 7 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 10 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| @@ -11,14 +14,15 @@ pub fn main() !void { | |||
| 11 | const input = try std.fs.cwd().readFileAlloc(allocator, "lang_mix.txt", std.math.maxInt(u32)); | 14 | const input = try std.fs.cwd().readFileAlloc(allocator, "lang_mix.txt", std.math.maxInt(u32)); |
| 12 | defer allocator.free(input); | 15 | defer allocator.free(input); |
| 13 | 16 | ||
| 14 | var result: usize = 0; | 17 | var result: isize = 0; |
| 15 | var iter = GraphemeIterator.init(input); | 18 | // var iter = GraphemeIterator.init(input); |
| 19 | var iter = CodePointIterator{ .bytes = input }; | ||
| 16 | 20 | ||
| 17 | var timer = try std.time.Timer.start(); | 21 | var timer = try std.time.Timer.start(); |
| 18 | 22 | ||
| 19 | // for (0..50) |_| { | 23 | // for (0..50) |_| { |
| 20 | while (iter.next()) |_| result += 1; | 24 | while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); |
| 21 | iter.cp_iter.i = 0; | 25 | // iter.cp_iter.i = 0; |
| 22 | // } | 26 | // } |
| 23 | 27 | ||
| 24 | std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); | 28 | std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); |