last method

String last(
  1. int len
)

Gets the last len grapheme clusters of this string.

Uses the characters package to correctly handle multi-codepoint sequences such as emoji with skin-tone modifiers or ZWJ sequences.

Returns the full string if len is greater than the grapheme length.

Implementation

String last(int len) {
  if (isEmpty || len <= 0) return '';
  final Characters chars = characters;
  final int charLength = chars.length;
  if (len >= charLength) return this;
  // skip() avoids allocating a full List<String> for large strings
  return chars.skip(charLength - len).string;
}