parent method

UnixPath? parent()

Returns the Path without its final component, if there is one. This means it returns Some("")/"" for relative paths with one component. Returns None/null if the path terminates in a root or prefix, or if it’s the empty string.

Implementation

UnixPath? parent() {
  final comps = components().toList();
  if (comps.length == 1) {
    switch (comps.first) {
      case RootDir():
        return null;
      case Prefix():
        unreachable("Prefixes are not possible for Unix");
      case ParentDir():
      case CurDir():
      case Normal():
        return UnixPath("");
    }
  }
  if (comps.length > 1) {
    comps.removeLast();
  } else {
    return null;
  }
  return _joinUnixComponents(comps);
}