Vixen
02b45cc4
csharp
public static class GraphemeBreaker

Where one user-perceived character ends and the next begins.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

A grapheme cluster is what a person means by "a character", and it is very often not one code point: é may be two, a flag is two, a family emoji with skin tones is eleven, and a Devanagari conjunct is however many the orthography needs. Everything a text editor does in units of "characters" — arrow keys, backspace, selection, the count in a character-limited field — is wrong unless it is done in these.

UAX#29's rules over the generated property tables. Most are a decision about two adjacent code points; two are not, and those are where implementations go wrong. GB12/GB13 pairs regional indicators, so four of them are two flags rather than a flag and two halves. GB9c holds an indic conjunct together across its virama, which needs to know what has been seen since the last consonant and needs a property that lives in a different UCD file from all the others.

Written against the conformance suite rather than against a reading of the specification. The two are not the same thing, and the suite is the arbiter.

Methods (5)

  • public static void Collect(ReadOnlySpan<char> text, List<int> boundaries)

    Collects every cluster boundary in a string.

  • public static List<int> Boundaries(string text)

    Every cluster boundary in a string.

  • public static bool IsBoundary(ReadOnlySpan<char> text, int index)

    Whether a cluster ends immediately before a position.

  • public static (int Start, int End) ClusterAt(ReadOnlySpan<char> text, int index)

    The cluster containing a position.

  • public static int Count(ReadOnlySpan<char> text)

    How many clusters a string has.

Used by (12)

  • BidiAlgorithmVixen.Ui.Text
  • CaretTestsVixen.Ui.Text.Tests
  • FontRegistryVixen.Ui
  • LineBreakRunVixen.Ui.Text
  • LineBreakerVixen.Ui.Text
  • LineWrapperVixen.Ui.Text
  • SegmentationTestsVixen.Ui.Text.Tests
  • ShapedTextVixen.Ui.Text
  • TextFieldVixen.Ui.Controls
  • TextItemizerVixen.Ui.Text
  • UnicodeConformanceVixen.Ui.Text.Tests
  • WordBreakerVixen.Ui.Text