Persian text and grapheme boundaries
Quick answer
A visible text unit can consist of multiple Unicode scalar values. Persian combining marks, zero-width non-joiners and other Unicode features make byte counts and scalar counts insufficient for tasks like cursor movement or truncating visible text.
Text segmentation and normalization
Extended grapheme clusters approximate user-perceived characters according to Unicode segmentation rules. The standard library exposes bytes and scalar values, not full grapheme segmentation. For production segmentation use a Unicode-aware library with a verified version. Normalization is another operation: it handles certain equivalent Unicode sequences, not all visually similar letters. Preserve meaningful Persian half-spaces unless the task specifically defines another policy.
fn main() { let text = "e\u{301}"; println!("{} {}", text.len(), text.chars().count()); println!("equal: {}", text == "é");}Expected stdout (not executed):
3 2equal: falseThe decomposed accent uses two scalars, usually displayed as one grapheme; equality compares the actual sequences.
fn main() { let text = "می\u{200c}روم"; println!("scalars: {}", text.chars().count()); println!("half-space: {}", text.contains('\u{200c}'));}Expected stdout (not executed):
scalars: 6half-space: trueThe non-joiner is a scalar with a meaningful shaping role; it is not an ordinary space.
Common mistake
Do not claim that deleting all invisible code points or replacing all similar-looking Persian and Arabic letters is Unicode normalization.
Try it yourself
Compare the scalar counts of "میروم" and "می\u{200c}روم"; explain why neither count measures rendered width.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Persian text and grapheme boundaries — practice quiz
Choose one answer per question, then review the explanation.
Does counting Unicode scalars fully implement grapheme segmentation?
Should a text processor remove Persian half-spaces by default?
Does Unicode normalization automatically make all visually similar letters identical?