dmxWords function

List<String> dmxWords(
  1. String name
)

The words in name, in order — the reading every casing here is built on.

Runs of capitals stay together, so parseHTTPResponse is parse | HTTP | Response rather than one word per letter. _, -, , and $ separate; so does a lower-to-upper transition.

Mirrors casing::words.

Implementation

List<String> dmxWords(String name) {
  const separators = ['_', '-', ' ', r'$'];
  final characters = name.split('');
  final words = <String>[];
  final word = StringBuffer();
  for (var index = 0; index < characters.length; index++) {
    final character = characters[index];
    if (separators.contains(character)) {
      if (word.isNotEmpty) {
        words.add(word.toString());
        word.clear();
      }
      continue;
    }
    final previous = index == 0 ? '' : characters[index - 1];
    final next = index + 1 < characters.length ? characters[index + 1] : '';
    final startsWord = _isUpper(character) &&
        word.isNotEmpty &&
        (_isLower(previous) || _isDigit(previous) || _isLower(next));
    if (startsWord) {
      words.add(word.toString());
      word.clear();
    }
    word.write(character);
  }
  if (word.isNotEmpty) {
    words.add(word.toString());
  }
  return words;
}