using System.Globalization; namespace Terminal.Gui.Drawing; /// /// Provides utility methods for enumerating Unicode grapheme clusters (user-perceived characters) /// in a string. A grapheme cluster may consist of one or more values, /// including combining marks or zero-width joiner (ZWJ) sequences such as emoji family groups. /// /// /// /// This helper uses to enumerate /// text elements according to the Unicode Standard Annex #29 (UAX #29) rules for /// extended grapheme clusters. /// /// /// On legacy Windows consoles (e.g., cmd.exe, conhost.exe), complex grapheme /// sequences such as ZWJ emoji or combining marks may not render correctly, even though /// the underlying string data is valid. /// /// /// For most accurate visual rendering, prefer modern terminals such as Windows Terminal /// or Linux-based terminals with full Unicode and font support. /// /// public static class GraphemeHelper { /// /// Enumerates extended grapheme clusters from a string. /// Handles surrogate pairs, combining marks, and basic ZWJ sequences. /// Safe for legacy consoles; memory representation is correct. /// public static IEnumerable GetGraphemes (string text) { if (string.IsNullOrEmpty (text)) { yield break; } TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator (text); while (enumerator.MoveNext ()) { string element = enumerator.GetTextElement (); yield return element; } } }