A visible character is not a string length
I was writing the code that compares input with the reference in a personal app where Japanese speakers practice typing short Korean phrases. This package is that logic, extracted in August 2026.
The problem was counting characters. Dart's String.length counts UTF-16 code units, and runes counts code points. Neither matches what a person sees as one character. The emoji 👩🏽💻, with a skin tone and a zero-width joiner, looks like one character but is several code points. 가 can be written either as one precomposed syllable or as the consonant ᄀ followed by the vowel ᅡ.
Before comparing, the package normalizes both strings to NFC and splits them into extended grapheme clusters, the units people see as characters. Segmentation uses the Dart team's characters package, and normalization uses unorm_dart.
Fixing even the order of normalization, whitespace, and punctuation
Grading runs in this order: NFC normalization, whitespace handling, terminal punctuation, grapheme segmentation, then edit distance. The order never changes. For example, comparing "안녕. " with trimmed whitespace and ignored terminal punctuation removes the trailing space first, then the period.
I chose NFC over NFKC. NFKC folds compatibility forms, such as full-width and half-width letters, half-width kana, or ① and 1, into one character. That would accept characters typed with different keystrokes as correct, which is wrong for grading.
The set of whitespace characters is a fixed list of code points instead of whatever the runtime's trim does, so the result does not change between languages with different whitespace definitions. When terminal punctuation is ignored, only one trailing ., !, ?, 。, !, or ? is removed. For 정말?!, only the last ! goes, so the writer's ?! is not ignored as a whole.
Grading
final result = gradeTyping(
reference: 'Practice makes progress',
input: 'Practice makes progres',
policy: TypingGradingPolicy.exact,
activeElapsed: const Duration(seconds: 30),
);
result.accuracyPercent; // 95.6
result.charactersPerMinute; // 44.0
result.comparison.deletionCount; // 1Equal after NFC
// precomposed 가 vs. ᄀ + ᅡ
final comparison = compareNormalizedGraphemes(
reference: '\uAC00',
input: '\u1100\u1161',
);
comparison.editDistance; // 0