toTitleCaseWord function

String toTitleCaseWord(
  1. String word
)

Converts word to strict ASCII title-case.

The result has an uppercase first letter and lowercase remaining letters.

Implementation

String toTitleCaseWord(String word) {
  if (word.isEmpty) {
    return word;
  }

  final String lower = word.toLowerCase();
  if (lower.length == 1) {
    return lower.toUpperCase();
  }

  return '${lower[0].toUpperCase()}${lower.substring(1)}';
}