So, challenge to the #gnome #gtk #vala wizards out there: is this the best we can do to count Unicode glyphs in a string (equivalent of string.characters.count in Swift) or is there a more performant way I don’t know about?
(It’s fast enough for my needs but not ideal by any means.)
https://ar.al/2021/10/31/how-to-count-unicode-glyphs-in-vala-using-gtk/
never used Vala personally but curious if `char_count()` may do what you are looking for. It appears `length()` returns the number of bytes.
@bmallred Nope, sadly char_count does not take grapheme clusters into consideration. Did try :)
@aral good to know!
@aral Unicode does not have a concept of glyph, so it's an incorrect question to ask.
In all cases, one has to look at what one actually needs, and decide on the solution based on that. Sometimes it's bytes, sometimes it's unicode codepoints, sometimes it's grapheme clusters, or could could be something entirely different.