isZeroWidthGrapheme function
Returns true if the grapheme cluster represents a zero-width character (non-spacing marks, format controls, zero-width spaces, or soft hyphens).
Implementation
bool isZeroWidthGrapheme(String grapheme) {
final len = grapheme.length;
if (len == 0) return true;
if (len == 1) {
final cu = grapheme.codeUnitAt(0);
return isZeroWidthCodePoint(cu);
}
// If the cluster starts with a zero-width code point and contains no visible base char
final cu0 = grapheme.codeUnitAt(0);
if (isZeroWidthCodePoint(cu0)) {
for (var i = 1; i < len; i++) {
if (!isZeroWidthCodePoint(grapheme.codeUnitAt(i))) return false;
}
return true;
}
return false;
}