last method

  1. @useResult
String last(
  1. int len
)

Returns 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

@useResult
String last(int len) {
  if (isEmpty || len <= 0) {
    return '';
  }

  final Characters chars = characters;
  final int charLength = chars.length;
  if (len >= charLength) {
    return this;
  }

  return chars.skip(charLength - len).string;
}