toTrainCase method

String toTrainCase()

Convert string to train case.

Implementation

String toTrainCase() {
  if (this == null) {
    throw ArgumentError('string: $this');
  }
  return this!.splitMapJoin(RegExp(r'[_\s]+'),
      onMatch: (match) => match.group(0)!.toUpperCase(),
      onNonMatch: (nonMatch) =>
          nonMatch[0].toUpperCase() +
          nonMatch.substring(1).replaceAllMapped(RegExp(r'[A-Z]'),
              (match) => '-${match.group(0)!.toUpperCase()}'));
}