String::Grapheme
Grapheme represents a Unicode grapheme cluster, which describes the smallest
functional unit of a writing system. This is also called a user-perceived character.
In the latin alphabet, most graphemes consist of a single Unicode codepoint
(equivalent to Char). But a grapheme can also consist of a sequence of codepoints,
which combine into a single unit.
For example, the string "e\u0301" consists of two characters, the latin small letter e
and the combining acute accent ´. Together, they form a single grapheme: é.
That same grapheme could alternatively be described in a single codepoint, \u00E9 (latin small letter e with acute).
But the combinatory possibilities are far bigger than the amount of directly
available codepoints.
"e\u0301".size # => 2
"é".size # => 1
"e\u0301".grapheme_size # => 1
"é".grapheme_size # => 1
This combination of codepoints is common in some non-latin scripts. It's also
often used with emojis to create customized combination. For example, the
thumbs up sign 👍 (U+1F44D) combined with an emoji modifier such as
U+1F3FC assign a colour to the emoji.
Instances of this type can be acquired via String#each_grapheme or String#graphemes.
The algorithm to determine boundaries between grapheme clusters is specified in the Unicode Standard Annex #29.