2024-04-29 20:01:04 +02:00
|
|
|
const std = @import("std");
|
|
|
|
const grapheme = @import("grapheme");
|
2024-04-29 21:00:08 +02:00
|
|
|
const DisplayWidth = @import("DisplayWidth");
|
2024-04-29 20:01:04 +02:00
|
|
|
|
|
|
|
/// A thin wrapper around zg data
|
|
|
|
const Unicode = @This();
|
|
|
|
|
|
|
|
grapheme_data: grapheme.GraphemeData,
|
2024-04-29 21:00:08 +02:00
|
|
|
width_data: DisplayWidth.DisplayWidthData,
|
2024-04-29 20:01:04 +02:00
|
|
|
|
|
|
|
/// initialize all unicode data vaxis may possibly need
|
|
|
|
pub fn init(alloc: std.mem.Allocator) !Unicode {
|
|
|
|
return .{
|
2024-04-29 21:00:08 +02:00
|
|
|
.grapheme_data = try grapheme.GraphemeData.init(alloc),
|
|
|
|
.width_data = try DisplayWidth.DisplayWidthData.init(alloc),
|
2024-04-29 20:01:04 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// free all data
|
2024-04-29 21:00:08 +02:00
|
|
|
pub fn deinit(self: *const Unicode) void {
|
2024-04-29 20:01:04 +02:00
|
|
|
self.grapheme_data.deinit();
|
2024-04-29 21:00:08 +02:00
|
|
|
self.width_data.deinit();
|
2024-04-29 20:01:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// creates a grapheme iterator based on str
|
|
|
|
pub fn graphemeIterator(self: *const Unicode, str: []const u8) grapheme.Iterator {
|
|
|
|
return grapheme.Iterator.init(str, &self.grapheme_data);
|
|
|
|
}
|