From 74be85ac145cc6de5d03348e07be8d982c2211cb Mon Sep 17 00:00:00 2001 From: Jose Colon Rodriguez Date: Thu, 28 Mar 2024 10:06:00 -0400 Subject: PropsData and errdefers for init fns --- src/NumericData.zig | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/NumericData.zig') diff --git a/src/NumericData.zig b/src/NumericData.zig index 210d623..28e8206 100644 --- a/src/NumericData.zig +++ b/src/NumericData.zig @@ -24,10 +24,12 @@ pub fn init(allocator: mem.Allocator) !Self { const stage_1_len: u16 = try reader.readInt(u16, endian); self.s1 = try allocator.alloc(u16, stage_1_len); + errdefer allocator.free(self.s1); for (0..stage_1_len) |i| self.s1[i] = try reader.readInt(u16, endian); const stage_2_len: u16 = try reader.readInt(u16, endian); self.s2 = try allocator.alloc(u8, stage_2_len); + errdefer allocator.free(self.s2); _ = try reader.readAll(self.s2); return self; @@ -38,11 +40,6 @@ pub fn deinit(self: *const Self) void { self.allocator.free(self.s2); } -/// True if `cp` is any numeric type. -pub fn isNumber(self: Self, cp: u21) bool { - return self.isNumeric(cp) or self.isDigit(cp) or self.isDecimal(cp); -} - /// True if `cp` is numeric. pub inline fn isNumeric(self: Self, cp: u21) bool { return self.s2[self.s1[cp >> 8] + (cp & 0xff)] & 1 == 1; @@ -62,13 +59,10 @@ test "isDecimal" { const self = try init(testing.allocator); defer self.deinit(); - try testing.expect(self.isNumber('\u{277f}')); - try testing.expect(self.isNumber('3')); try testing.expect(self.isNumeric('\u{277f}')); try testing.expect(self.isDigit('\u{2070}')); try testing.expect(self.isDecimal('3')); - try testing.expect(!self.isNumber('z')); try testing.expect(!self.isNumeric('1')); try testing.expect(!self.isDigit('2')); try testing.expect(!self.isDecimal('g')); -- cgit v1.2.3