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 const RootDir(false);
      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(false);
      break;
    case ".":
      yield const CurDir();
      break;
    case "..":
      yield const ParentDir();
      break;
    default:
      yield Normal(current);
  }
  while (iterator.moveNext()) {
    current = iterator.current;
    switch (current) {
      case ".":
        yield CurDir();
        break;
      case "..":
        yield ParentDir();
        break;
      default:
        yield Normal(current);
    }
  }
}