diff options
| author | 2024-02-12 10:51:34 -0400 | |
|---|---|---|
| committer | 2024-02-12 10:51:34 -0400 | |
| commit | bfb31cbc33716220b42bb398471840a4fbed0d89 (patch) | |
| tree | 3f3614621f34f066bd192ce93d3f82810205e5ca /src/Grapheme.zig | |
| parent | Created Trie (diff) | |
| download | zg-bfb31cbc33716220b42bb398471840a4fbed0d89.tar.gz zg-bfb31cbc33716220b42bb398471840a4fbed0d89.tar.xz zg-bfb31cbc33716220b42bb398471840a4fbed0d89.zip | |
Using Trie super slow
Diffstat (limited to 'src/Grapheme.zig')
| -rw-r--r-- | src/Grapheme.zig | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/Grapheme.zig b/src/Grapheme.zig index a8a7638..73f6d57 100644 --- a/src/Grapheme.zig +++ b/src/Grapheme.zig | |||
| @@ -1,13 +1,15 @@ | |||
| 1 | //! `Grapheme` represents a Unicode grapheme cluster by its length and offset in the source bytes. | 1 | //! `Grapheme` represents a Unicode grapheme cluster by its length and offset in the source bytes. |
| 2 | 2 | ||
| 3 | const std = @import("std"); | 3 | const std = @import("std"); |
| 4 | const mem = std.mem; | ||
| 4 | const unicode = std.unicode; | 5 | const unicode = std.unicode; |
| 5 | 6 | ||
| 6 | const CodePoint = @import("ziglyph").CodePoint; | 7 | const CodePoint = @import("ziglyph").CodePoint; |
| 7 | const CodePointIterator = CodePoint.CodePointIterator; | 8 | const CodePointIterator = CodePoint.CodePointIterator; |
| 8 | const emoji = @import("ziglyph").emoji; | 9 | const emoji = @import("ziglyph").emoji; |
| 9 | 10 | ||
| 10 | const gbp = @import("gbp"); | 11 | // const gbp = @import("gbp"); |
| 12 | const gbp = @import("gbp.zig"); | ||
| 11 | 13 | ||
| 12 | pub const Grapheme = @This(); | 14 | pub const Grapheme = @This(); |
| 13 | 15 | ||
| @@ -32,7 +34,8 @@ pub const GraphemeIterator = struct { | |||
| 32 | const Self = @This(); | 34 | const Self = @This(); |
| 33 | 35 | ||
| 34 | /// Assumes `src` is valid UTF-8. | 36 | /// Assumes `src` is valid UTF-8. |
| 35 | pub fn init(str: []const u8) Self { | 37 | pub fn init(allocator: mem.Allocator, str: []const u8) !Self { |
| 38 | try gbp.init(allocator); | ||
| 36 | var self = Self{ .cp_iter = CodePointIterator{ .bytes = str } }; | 39 | var self = Self{ .cp_iter = CodePointIterator{ .bytes = str } }; |
| 37 | self.buf[1] = self.cp_iter.next(); | 40 | self.buf[1] = self.cp_iter.next(); |
| 38 | 41 | ||