removeSuffix method

String removeSuffix(
  1. Pattern pattern
)

If the string ends with the suffix pattern returns this String with the suffix removed, otherwise return this.

Implementation

String removeSuffix(Pattern pattern) {
  if (pattern is String && endsWith(pattern)) {
    return substring(0, length - pattern.length);
  }
  final end = lastIndexOf(pattern);
  if (end == -1) return this;
  final match = pattern.matchAsPrefix(this, end)!;
  if (match.end < length) return this;
  return substring(0, end);
}