Skip to main content

Utf_16_Span.to_grapheme_span

to_grapheme_span

Group: Conversions

Documentation

Returns a span of extended grapheme clusters which is the closest approximation of this span of code units. The resulting span is extended in such a way that every code unit that was contained by the original span is also contained in a new span. Since some grapheme clusters consist of multiple code units, after the span was extended it may also contain code units which were not contained inside of the original span.

Examples

Convert a codepoint span to graphemes and back.

text = 'a\u301e\u302o\u303' span = Utf_16_Span.Value (Range 1 5) text # The span contains the units [\u301, e, \u302, o]. extended = span.to_grapheme_span extended == Span.Value (Range 0 3) text # The span is extended to the whole string since it contained code units from every grapheme cluster. extended.to_utf_16_span == Utf_16_Span.Value (Range 0 6) text