diff options
| author | 2024-02-26 12:24:42 -0400 | |
|---|---|---|
| committer | 2024-02-26 12:24:42 -0400 | |
| commit | 836a4b6e63ac4bd7beb406cb20edf23f0bd342a9 (patch) | |
| tree | 5f806a29594a9cb227aaa4d131209e10ff25aeee /src/main.zig | |
| parent | Replaced ccc_map with table. 20ms faster (diff) | |
| download | zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.tar.gz zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.tar.xz zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.zip | |
Using separate data struct model.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig index 946ae01..57db05b 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -1,29 +1,47 @@ | |||
| 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 Data = @import("grapheme").Data; |
| 5 | // const GraphemeIterator = @import("grapheme").Iterator; | ||
| 6 | |||
| 5 | // const codePointWidth = @import("ziglyph").display_width.codePointWidth; | 7 | // const codePointWidth = @import("ziglyph").display_width.codePointWidth; |
| 6 | // const codePointWidth = @import("display_width").codePointWidth; | ||
| 7 | // const strWidth = @import("ziglyph").display_width.strWidth; | 8 | // const strWidth = @import("ziglyph").display_width.strWidth; |
| 9 | // const Data = @import("display_width").Data; | ||
| 10 | // const codePointWidth = @import("display_width").codePointWidth; | ||
| 8 | // const strWidth = @import("display_width").strWidth; | 11 | // const strWidth = @import("display_width").strWidth; |
| 9 | // const CodePointIterator = @import("CodePoint").CodePointIterator; | 12 | |
| 13 | // const CodePointIterator = @import("ziglyph").CodePointIterator; | ||
| 14 | // const CodePointIterator = @import("code_point").Iterator; | ||
| 15 | |||
| 10 | // const ascii = @import("ascii"); | 16 | // const ascii = @import("ascii"); |
| 11 | // const ascii = std.ascii; | 17 | // const ascii = std.ascii; |
| 18 | |||
| 12 | // const norm = @import("ziglyph").Normalizer; | 19 | // const norm = @import("ziglyph").Normalizer; |
| 20 | const Data = @import("Normalizer").Data; | ||
| 13 | const norm = @import("Normalizer"); | 21 | const norm = @import("Normalizer"); |
| 14 | 22 | ||
| 15 | pub fn main() !void { | 23 | pub fn main() !void { |
| 24 | var args_iter = std.process.args(); | ||
| 25 | _ = args_iter.skip(); | ||
| 26 | const in_path = args_iter.next() orelse return error.MissingArg; | ||
| 27 | |||
| 16 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 28 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 17 | defer _ = gpa.deinit(); | 29 | defer _ = gpa.deinit(); |
| 18 | const allocator = gpa.allocator(); | 30 | const allocator = gpa.allocator(); |
| 19 | 31 | ||
| 20 | const input = try std.fs.cwd().readFileAlloc(allocator, "data/lang_mix.txt", std.math.maxInt(u32)); | 32 | const input = try std.fs.cwd().readFileAlloc(allocator, in_path, std.math.maxInt(u32)); |
| 21 | defer allocator.free(input); | 33 | defer allocator.free(input); |
| 22 | 34 | ||
| 23 | var n = try norm.init(allocator); | 35 | var data = try Data.init(allocator); |
| 36 | defer data.deinit(); | ||
| 37 | |||
| 38 | var n = try norm.init(allocator, &data); | ||
| 24 | defer n.deinit(); | 39 | defer n.deinit(); |
| 40 | // var n = try norm.init(allocator); | ||
| 41 | // defer n.deinit(); | ||
| 25 | 42 | ||
| 26 | // var iter = GraphemeIterator.init(input); | 43 | // var iter = GraphemeIterator.init(input, &data); |
| 44 | // defer iter.deinit(); | ||
| 27 | // var iter = CodePointIterator{ .bytes = input }; | 45 | // var iter = CodePointIterator{ .bytes = input }; |
| 28 | var iter = std.mem.splitScalar(u8, input, '\n'); | 46 | var iter = std.mem.splitScalar(u8, input, '\n'); |
| 29 | 47 | ||
| @@ -33,7 +51,7 @@ pub fn main() !void { | |||
| 33 | 51 | ||
| 34 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); | 52 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); |
| 35 | // while (iter.next()) |_| result += 1; | 53 | // while (iter.next()) |_| result += 1; |
| 36 | // while (iter.next()) |line| result += strWidth(line); | 54 | // while (iter.next()) |line| result += strWidth(line, &data); |
| 37 | while (iter.next()) |line| { | 55 | while (iter.next()) |line| { |
| 38 | var nfc = try n.nfc(allocator, line); | 56 | var nfc = try n.nfc(allocator, line); |
| 39 | result += nfc.slice.len; | 57 | result += nfc.slice.len; |