So, challenge to the 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.)

· · Web · 3 · 2 · 3


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 a sign of a great programming language is when it makes the easy things hard!

@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.

Sign in to participate in the conversation
Aral’s Mastodon

This is my personal Mastodon.