4 ms·
Does Go provide functions for iterating grapheme by grapheme?
by dbaupp 13y ago
Does Go provide functions for iterating grapheme by grapheme?
- MBCook 13y agoThat's the purpose of the Rune type, I believe. When you iterate over text, it gives you one character at a time, not a fixed number of bytes.
- pjscott 13y agoThat's iteration by code point, not by grapheme. For example, the grapheme 'ä' may be represented as two code points: an 'a' and a combining diaeresis. http://en.wikipedia.org/wiki/Code_point http://en.wikipedia.org/wiki/Code_point http://en.wikipedia.org/wiki/Grapheme http://en.wikipedia.org/wiki/Grapheme
- cynwoody 13y agoThat's being worked on†. It hasn't made it into the standard package library as far as I know. E.g., there are two ways to write Cañyon City. You can write the ñ as U+00F1 or as an ascii lower-case n followed by a combining tilde (U+0303). The first case results in a single rune, and the second in two runes. Example††. You need additional logic in order to normalize to a canonical representation and realize that the two strings are actually the same. Also, if you are displaying the string, you need to account for the fact that, although the two strings have different byte and rune lengths, they take up exactly the same number of pixels on your display medium. †http://blog.golang.org/normalization http://blog.golang.org/normalization ††http://play.golang.org/p/XJPydELZ6s http://play.golang.org/p/XJPydELZ6s
- coldtea 13y ago>E.g., there are two ways to write Cañyon City. You can write the ñ as U+00F1 or as an ascii lower-case n followed by a combining tilde (U+0303). The first case results in a single rune, and the second in two runes. Example††. You need additional logic in order to normalize to a canonical representation and realize that the two strings are actually the same. Who thought that having two ways to go about this was a good idea in the first place?