getRepeatableLetter method

  1. @useResult
String getRepeatableLetter()

Returns the first character uppercased for use as a repeatable index.

If the first character is a Latin letter (A-Z), returns it uppercased; otherwise returns the first character as-is.

Implementation

@useResult
String getRepeatableLetter() {
  if (isEmpty) {
    return '';
  }

  final String trimmed = trim();
  if (trimmed.isEmpty) {
    return '';
  }

  final String first = String.fromCharCode(trimmed.runes.first);
  final String upper = first.toUpperCase();
  final int code = upper.codeUnitAt(0);
  if (code >= _asciiUpperA && code <= _asciiUpperZ) {
    return upper;
  }

  return first;
}