rename method

PathUri rename(
  1. String name
)

Renames the last path segment and returns a new path URI.

Implementation

PathUri rename(String name) {
  if (name.contains('/')) {
    throw Exception('Path names must not contain /');
  }

  return PathUri(
    isAbsolute: isAbsolute,
    isDirectory: isDirectory,
    pathSegments: pathSegments.isNotEmpty
        ? pathSegments.rebuild(
            (b) => b
              ..removeLast()
              ..add(name),
          )
        : BuiltList(),
  );
}