components method

Iterable<Component> components()

Produces an iterator over the Components of the path.

Implementation

Iterable<Component> components() sync* {
  bool removeLast;
  // trailing slash does not matter
  if (_string.endsWith(separator)) {
    if (_string.length == 1) {
      yield RootDir(true);
      return;
    }
    removeLast = true;
  } else {
    removeLast = false;
  }
  final splits = _string.split(_oneOrMoreSlashes);
  if (removeLast) {
    splits.removeLast();
  }

  final iterator = splits.iterator;
  iterator.moveNext();
  var current = iterator.current;
  switch (current) {
    case "":
      yield const RootDir(true);
      break;
    case ".":
      yield const CurDir();
      break;
    case "..":
      yield const ParentDir();
      break;
    default:
      if (_regularPathComponent.hasMatch(current)) {
        yield Normal(current);
      } else {
        yield Prefix(current);
        if (_string.replaceFirst(current, "").startsWith(separator)) {
          yield const RootDir(true);
        }
      }
  }
  while (iterator.moveNext()) {
    current = iterator.current;
    switch (current) {
      case ".":
        yield const CurDir();
        break;
      case "..":
        yield const ParentDir();
        break;
      default:
        yield Normal(current);
    }
  }
}