Basics
Grapheme Clusters
Why one "user-perceived character" might be multiple code points.
Time Complexity
O(N)
Space Complexity
O(1)
Interactive Visualization
Technical Guide
Even code points don't always represent one visual character. A 'Grapheme Cluster' is what a user sees as a single character. For example, a family emoji is actually multiple emojis (Man, Woman, Girl, Boy) joined by invisible 'Zero Width Joiner' code points. Algorithms that reverse strings or delete characters must work at the Grapheme Cluster level to avoid corruption.
Logical Phases
- 1Combining a base character with skin tone modifiers.
- 2Joining independent characters with ZWJ (U+200D).
- 3Applying accent marks (Combining Diacritical Marks) to base letters.
- 4Parsing sequences to find logical visual boundaries.
Implementation
const cluster = 'nฬ'; // 'n' + accent
// length is 2, but it looks like 1.Expert Pitfalls
Splitting a string in the middle of a cluster, leaving a 'floating' accent or modifier.