summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sam Atman2025-05-01 21:45:59 -0400
committerGravatar Sam Atman2025-05-01 21:45:59 -0400
commit460b4077e73da7bbfae4b8b341e9025cebc02c50 (patch)
tree989cd2eae04b8f165580e3d3dae2edffd77f233f
parentProofreads (diff)
downloadzg-460b4077e73da7bbfae4b8b341e9025cebc02c50.tar.gz
zg-460b4077e73da7bbfae4b8b341e9025cebc02c50.tar.xz
zg-460b4077e73da7bbfae4b8b341e9025cebc02c50.zip
Remove inner setup from GeneralCategories
It was one `try` block away from only returning Allocator.Error, so now there's no need to filter errors in an outer `catch`.
-rw-r--r--README.md2
-rw-r--r--src/GeneralCategories.zig11
2 files changed, 2 insertions, 11 deletions
diff --git a/README.md b/README.md
index 56592ce..5b471b5 100644
--- a/README.md
+++ b/README.md
@@ -94,7 +94,7 @@ test "Code point iterator" {
94## Grapheme Clusters 94## Grapheme Clusters
95 95
96Many characters are composed from more than one code point. These are known as 96Many characters are composed from more than one code point. These are known as
97Grapheme Clusters and the `grapheme` module has a data structure to represent 97Grapheme Clusters, and the `Graphemes` module has a data structure to represent
98them, `Grapheme`, and an `Iterator` to iterate over them in a string. 98them, `Grapheme`, and an `Iterator` to iterate over them in a string.
99 99
100In your `build.zig`: 100In your `build.zig`:
diff --git a/src/GeneralCategories.zig b/src/GeneralCategories.zig
index 3e76d82..8c1b6a3 100644
--- a/src/GeneralCategories.zig
+++ b/src/GeneralCategories.zig
@@ -47,15 +47,6 @@ pub fn init(allocator: Allocator) Allocator.Error!GeneralCategories {
47} 47}
48 48
49pub fn setup(gencat: *GeneralCategories, allocator: Allocator) Allocator.Error!void { 49pub fn setup(gencat: *GeneralCategories, allocator: Allocator) Allocator.Error!void {
50 gencat.setupInner(allocator) catch |err| {
51 switch (err) {
52 error.OutOfMemory => |e| return e,
53 else => unreachable,
54 }
55 };
56}
57
58inline fn setupInner(gencat: *GeneralCategories, allocator: Allocator) !void {
59 const decompressor = compress.flate.inflate.decompressor; 50 const decompressor = compress.flate.inflate.decompressor;
60 const in_bytes = @embedFile("gencat"); 51 const in_bytes = @embedFile("gencat");
61 var in_fbs = std.io.fixedBufferStream(in_bytes); 52 var in_fbs = std.io.fixedBufferStream(in_bytes);
@@ -67,7 +58,7 @@ inline fn setupInner(gencat: *GeneralCategories, allocator: Allocator) !void {
67 const s1_len: u16 = reader.readInt(u16, endian) catch unreachable; 58 const s1_len: u16 = reader.readInt(u16, endian) catch unreachable;
68 gencat.s1 = try allocator.alloc(u16, s1_len); 59 gencat.s1 = try allocator.alloc(u16, s1_len);
69 errdefer allocator.free(gencat.s1); 60 errdefer allocator.free(gencat.s1);
70 for (0..s1_len) |i| gencat.s1[i] = try reader.readInt(u16, endian); 61 for (0..s1_len) |i| gencat.s1[i] = reader.readInt(u16, endian) catch unreachable;
71 62
72 const s2_len: u16 = reader.readInt(u16, endian) catch unreachable; 63 const s2_len: u16 = reader.readInt(u16, endian) catch unreachable;
73 gencat.s2 = try allocator.alloc(u5, s2_len); 64 gencat.s2 = try allocator.alloc(u5, s2_len);