Back to API Reference
Class
TextMeasure
static
Measures and truncates text by TextLengthUnit. Truncation cuts only on a codepoint or grapheme boundary, so it never splits a surrogate pair, a multi-byte codepoint, or a grapheme cluster.
public static int Count(ReadOnlySpan<char> text, TextLengthUnit unit)Length of text in unit.
public static int Count(ITextDocument document, TextLengthUnit unit)Length of the whole document in unit. Measures the document SOURCE — in a markup-bearing field hidden tag characters count too; keep limits and counters on plain fields, or accept that they measure source, not the visible projection. For the per-keystroke grapheme path prefer GraphemeCountCache.
public static int CountRange(ITextDocument document, int startCodepoint, int codepointCount, TextLengthUnit unit)Length of the document's codepoint range [startCodepoint, startCodepoint + codepointCount) in unit.
public static int TruncatedCharLength(ReadOnlySpan<char> text, int budget, TextLengthUnit unit)Char count of the longest prefix of text whose length in unit is at most budget, cut on a boundary. Pass the result to Substring.
