partition method

List<String> partition(
  1. Pattern pattern, [
  2. int start = 0
])

Splits the string at the first occurrence of pattern.

Returns a list containing the part before the separator, the separator itself, and the part after the separator. If the pattern is not found, return a list with this string followed by two empty strings.

Implementation

List<String> partition(Pattern pattern, [int start = 0]) {
  final i = indexOf(pattern, start);
  if (i == -1) return [this, '', ''];
  final j = pattern is String
      ? i + pattern.length
      : pattern.matchAsPrefix(this, i)!.end;
  return [substring(0, i), substring(i, j), substring(j)];
}