capitalizeSentences method

  1. @useResult
String capitalizeSentences()

Capitalizes the first letter after sentence boundaries (start or after . ).

Implementation

@useResult
String capitalizeSentences() {
  if (isEmpty) return this;
  final RegExp re = RegExp(r'(^|\.\s+)([a-z])');
  return replaceAllMapped(
    re,
    (Match m) {
      final prefixGroup = m[1];
      final letterGroup = m[2];
      return '${prefixGroup ?? ''}${(letterGroup ?? '').toUpperCase()}';
    },
  );
}