#Can we read the length of a utf8 string without encoding/decoding?

1 messages · Page 1 of 1 (latest)

elfin quartz
#

I am looking through std.unicode and I cant see a simpple way to do a strlen on an array of u8, except for perhaps to write my own code to iterate over an array or convert the string. Am I missing something simple? How do you get the real length of a string?

#

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().....
forest kraken
#

std.unicode.utf8CountCodepoints

elfin quartz
#

Oh, thanks. I thought that meant count the length of the next character.

left pumice