nearMiss method

String nearMiss({
  1. required String rendered,
  2. required String common,
  3. required String? yours,
  4. required String theirs,
})

A rendered string that is nearly the one asked for.

The refusal is the one position that can notice: it holds the wanted string and the candidates, and neither string shows the difference to anyone staring at it — a narrow no-break space before AM/PM, a curly apostrophe, a non-breaking hyphen. So the character is named rather than printed, and the offered target is the prefix that is known to match.

Implementation

String nearMiss({
  required String rendered,
  required String common,
  required String? yours,
  required String theirs,
}) {
  var at = yours == null
      ? 'yours ends and the rendered one continues with $theirs'
      : 'yours has $yours and the rendered one has $theirs';
  return 'No exact match, but "$rendered" is on screen and differs from '
      'yours at character ${common.length}: $at. Target it with '
      '`{"containing": ${jsonEncode(common)}}`, or copy the rendered string.';
}