Returns the parent of a path, i.e., everything that precedes the last separator or null if at root. @return the parent of a path or null if at root.
()
| 292 | * @return the parent of a path or <code>null</code> if at root. |
| 293 | */ |
| 294 | public FsPath getParent() { |
| 295 | final String path = uri.getPath(); |
| 296 | final int lastSlash = path.lastIndexOf('/'); |
| 297 | final int start = hasWindowsDrive(path, true) ? 3 : 0; |
| 298 | if ((path.length() == start) |
| 299 | || // empty path |
| 300 | (lastSlash == start && path.length() == start + 1)) { // at root |
| 301 | return null; |
| 302 | } |
| 303 | String parent; |
| 304 | if (lastSlash == -1) { |
| 305 | parent = CUR_DIR; |
| 306 | } else { |
| 307 | final int end = hasWindowsDrive(path, true) ? 3 : 0; |
| 308 | parent = path.substring(0, lastSlash == end ? end + 1 : lastSlash); |
| 309 | } |
| 310 | return new FsPath(uri.getScheme(), uri.getAuthority(), parent); |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public String toString() { |