diff options
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/main.zig b/src/main.zig index 3e65c7b..e7c0828 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -3,7 +3,9 @@ const std = @import("std"); | |||
| 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; | 5 | // const codePointWidth = @import("ziglyph").display_width.codePointWidth; |
| 6 | const codePointWidth = @import("display_width").codePointWidth; | 6 | // const codePointWidth = @import("display_width").codePointWidth; |
| 7 | // const strWidth = @import("ziglyph").display_width.strWidth; | ||
| 8 | const strWidth = @import("display_width").strWidth; | ||
| 7 | const CodePointIterator = @import("CodePoint").CodePointIterator; | 9 | const CodePointIterator = @import("CodePoint").CodePointIterator; |
| 8 | 10 | ||
| 9 | pub fn main() !void { | 11 | pub fn main() !void { |
| @@ -14,14 +16,16 @@ pub fn main() !void { | |||
| 14 | const input = try std.fs.cwd().readFileAlloc(allocator, "lang_mix.txt", std.math.maxInt(u32)); | 16 | const input = try std.fs.cwd().readFileAlloc(allocator, "lang_mix.txt", std.math.maxInt(u32)); |
| 15 | defer allocator.free(input); | 17 | defer allocator.free(input); |
| 16 | 18 | ||
| 17 | var result: isize = 0; | 19 | var result: usize = 0; |
| 18 | // var iter = GraphemeIterator.init(input); | 20 | // var iter = GraphemeIterator.init(input); |
| 19 | var iter = CodePointIterator{ .bytes = input }; | 21 | // var iter = CodePointIterator{ .bytes = input }; |
| 22 | var iter = std.mem.splitScalar(u8, input, '\n'); | ||
| 20 | 23 | ||
| 21 | var timer = try std.time.Timer.start(); | 24 | var timer = try std.time.Timer.start(); |
| 22 | 25 | ||
| 23 | // for (0..50) |_| { | 26 | // for (0..50) |_| { |
| 24 | while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); | 27 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); |
| 28 | while (iter.next()) |line| result += strWidth(line); | ||
| 25 | // iter.cp_iter.i = 0; | 29 | // iter.cp_iter.i = 0; |
| 26 | // } | 30 | // } |
| 27 | 31 | ||