#Can we read the length of a utf8 string without encoding/decoding?
1 messages · Page 1 of 1 (latest)
i.e. I can see we can make a view with an iterator? Do we then iterate and count, or is there a built in way to count items off an iterator?
const view = try unicode.Utf8View.init(w.items[start..w.items.len]);
view.iterator().....
std.unicode.utf8CountCodepoints
Oh, thanks. I thought that meant count the length of the next character.
note that 'length' is something of a nebulous concept when working with unicode
if you want the number of grapheme clusters then you'll need to look outside of zig's standard library (one library i'm aware of: https://codeberg.org/atman/zg)