talira

characters

Unicode grapheme-cluster-aware strings for Dart

open sourceBSD-3-Clausefree

characters is a Dart package from the Dart team that views a string as a sequence of user-perceived characters (Unicode extended grapheme clusters) instead of UTF-16 code units. Its Characters class gives access to each character, and a CharacterRange moves back and forth between them, so taking the first letter or truncating text keeps emoji and combining marks whole. It follows Unicode 16.0.0.

Problems it solves

  • an emoji gets cut in half when I truncate a string in Flutter
  • count the characters a user sees in a Dart string
  • get the first letter of a name that starts with an emoji

Features

  • strings as sequences of grapheme clusters
  • CharacterRange to move between characters
  • based on Unicode 16.0.0