From f913551d27e07f0a7c7e201ba3141fd3a6cbb47c Mon Sep 17 00:00:00 2001 From: Jose Colon Rodriguez Date: Sun, 18 Feb 2024 09:20:19 -0400 Subject: Code point code is now a method not a field. --- src/Grapheme.zig | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/Grapheme.zig') diff --git a/src/Grapheme.zig b/src/Grapheme.zig index f013aba..6981753 100644 --- a/src/Grapheme.zig +++ b/src/Grapheme.zig @@ -1,7 +1,6 @@ const std = @import("std"); const unicode = std.unicode; -const CodePoint = @import("code_point").CodePoint; const CodePointIterator = @import("code_point").Iterator; const gbp = @import("gbp"); @@ -17,6 +16,13 @@ pub const Grapheme = struct { } }; +// We need the code as a u21. +const CodePoint = struct { + code: u21, + len: u3, + offset: u32, +}; + /// `Iterator` iterates a sting of UTF-8 encoded bytes one grapheme cluster at-a-time. pub const Iterator = struct { buf: [2]?CodePoint = .{ null, null }, @@ -33,7 +39,13 @@ pub const Iterator = struct { fn advance(self: *Self) void { self.buf[0] = self.buf[1]; - self.buf[1] = self.cp_iter.next(); + + const maybe_cp = self.cp_iter.next(); + self.buf[1] = if (maybe_cp) |cp| .{ + .code = cp.code(self.cp_iter.bytes), + .len = cp.len, + .offset = cp.offset, + } else null; } pub fn next(self: *Self) ?Grapheme { -- cgit v1.2.3