summaryrefslogtreecommitdiff
path: root/src/Grapheme.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Grapheme.zig')
-rw-r--r--src/Grapheme.zig16
1 files changed, 2 insertions, 14 deletions
diff --git a/src/Grapheme.zig b/src/Grapheme.zig
index 6981753..f013aba 100644
--- a/src/Grapheme.zig
+++ b/src/Grapheme.zig
@@ -1,6 +1,7 @@
1const std = @import("std"); 1const std = @import("std");
2const unicode = std.unicode; 2const unicode = std.unicode;
3 3
4const CodePoint = @import("code_point").CodePoint;
4const CodePointIterator = @import("code_point").Iterator; 5const CodePointIterator = @import("code_point").Iterator;
5const gbp = @import("gbp"); 6const gbp = @import("gbp");
6 7
@@ -16,13 +17,6 @@ pub const Grapheme = struct {
16 } 17 }
17}; 18};
18 19
19// We need the code as a u21.
20const CodePoint = struct {
21 code: u21,
22 len: u3,
23 offset: u32,
24};
25
26/// `Iterator` iterates a sting of UTF-8 encoded bytes one grapheme cluster at-a-time. 20/// `Iterator` iterates a sting of UTF-8 encoded bytes one grapheme cluster at-a-time.
27pub const Iterator = struct { 21pub const Iterator = struct {
28 buf: [2]?CodePoint = .{ null, null }, 22 buf: [2]?CodePoint = .{ null, null },
@@ -39,13 +33,7 @@ pub const Iterator = struct {
39 33
40 fn advance(self: *Self) void { 34 fn advance(self: *Self) void {
41 self.buf[0] = self.buf[1]; 35 self.buf[0] = self.buf[1];
42 36 self.buf[1] = self.cp_iter.next();
43 const maybe_cp = self.cp_iter.next();
44 self.buf[1] = if (maybe_cp) |cp| .{
45 .code = cp.code(self.cp_iter.bytes),
46 .len = cp.len,
47 .offset = cp.offset,
48 } else null;
49 } 37 }
50 38
51 pub fn next(self: *Self) ?Grapheme { 39 pub fn next(self: *Self) ?Grapheme {