एल्गोरिदम

Grapheme Cluster Boundary

Rules (UAX#29) for determining where one user-perceived character ends and another begins. Critical for cursor movement, text selection, and correctly counting 'characters' in UI.

What is Grapheme Cluster Boundary (Grapheme Break)?

A grapheme cluster boundary is a position in a Unicode text string where one user-perceived character ends and the next begins. The rules that determine these positions are defined in Unicode Standard Annex #29 (UAX#29), titled Unicode Text Segmentation. The concept matters wherever software needs to move a text cursor, measure string length in visible characters, or break text at line wraps.

The term grapheme cluster distinguishes between code points (the atomic integer values Unicode assigns to each character) and the actual glyphs a user perceives. A single user-perceived character such as the letter é may be encoded as one code point (U+00E9, precomposed) or as two code points — e (U+0065) followed by the combining acute accent (U+0301). Both representations should be treated as a single grapheme cluster with a single boundary on each side.

Extended vs Legacy Grapheme Clusters

UAX#29 defines two types of grapheme clusters:

  • Legacy grapheme clusters — a simpler, older definition that always breaks before a spacing combining mark. This can produce incorrect results for some scripts.
  • Extended grapheme clusters — the modern, recommended definition. It handles Hangul syllable sequences, emoji modifier sequences, emoji ZWJ sequences, and regional indicator pairs correctly.

Almost all modern implementations use extended grapheme clusters. The distinction matters when you need to precisely count how many "characters" a user sees.

Boundary Rules by Script

Hangul syllables are a classic example where grapheme break rules are non-trivial. A Korean syllable like is composed of a leading jamo (ᄀ, U+1100), a vowel jamo (ᅡ, U+1161), and a trailing jamo (ᆨ, U+11A8). UAX#29 defines specific rules so that these three code points form a single grapheme cluster.

Emoji sequences add further complexity. The flag emoji for France 🇫🇷 is encoded as two Regional Indicator Symbol Letters — F (U+1F1EB) and R (U+1F1F7). UAX#29 keeps these paired as one cluster. Similarly, 👨‍👩‍👧 is a family ZWJ sequence of five code points joined by Zero Width Joiner (U+200D), forming one cluster.

Combining marks in scripts like Devanagari, Arabic, and Thai can stack multiple diacritics onto a base character. All combining marks that follow a base code point without an intervening boundary are included in the same grapheme cluster.

Cursor Movement Implications

When a user presses the arrow key in a text editor, the cursor should move by one grapheme cluster, not one code point. Moving by code points would leave the cursor stranded inside a multi-code-point grapheme, causing partial deletions and display artifacts. Platforms implement this via ICU's BreakIterator, Swift's String.Index, or Rust's unicode-segmentation crate.

# Python: count grapheme clusters (requires third-party library)
import grapheme
text = "\u0065\u0301"   # e + combining acute accent
len(text)               # 2 code points
grapheme.length(text)   # 1 grapheme cluster

Quick Facts

Property Value
Defining standard Unicode Standard Annex #29 (UAX#29)
Two cluster types Legacy grapheme clusters, Extended grapheme clusters
Recommended type Extended grapheme clusters
Complex scripts Hangul (jamo sequences), Indic (virama clusters)
Emoji cases Regional indicators, ZWJ sequences, modifier sequences
Key use cases Cursor movement, string length, line breaking
Implementation ICU BreakIterator, Intl.Segmenter (JS), unicode-segmentation (Rust)

संबंधित शब्द

एल्गोरिदम में और

Case Folding

Mapping characters to a common case form for case-insensitive comparison. More comprehensive …

NFC (Canonical Composition)

Normalization Form C: canonically decompose करें फिर recompose करें, सबसे छोटा रूप …

NFD (Canonical Decomposition)

Normalization Form D: बिना recomposing के पूरी तरह decompose करें। macOS HFS+ …

NFKC (Compatibility Composition)

Normalization Form KC: compatibility decomposition फिर canonical composition। दृश्य रूप से समान …

NFKD (Compatibility Decomposition)

Normalization Form KD: बिना recomposing के compatibility decomposition। सबसे आक्रामक normalization, सबसे …

String Comparison

Comparing Unicode strings requires normalization (NFC/NFD) and optionally collation (locale-aware sorting). Binary …

द्विदिशीय एल्गोरिदम

मिश्रित-दिशा पाठ (जैसे, English + Arabic) में वर्णों के प्रदर्शन क्रम को …

पंक्ति विराम एल्गोरिदम

यह निर्धारित करने के नियम कि पाठ कहाँ अगली पंक्ति में wrap …

पाठ विभाजन

पाठ में सीमाएँ खोजने के लिए algorithms: grapheme cluster, शब्द, और वाक्य …

वाक्य सीमा

Unicode नियमों के अनुसार वाक्यों के बीच की स्थिति। periods पर विभाजन …