| 53 | } |
| 54 | |
| 55 | URL URL::withLastPathComponentRemoved() const { |
| 56 | // If path is empty or has no slashes, we can't remove a component |
| 57 | auto lastSlashPos = _path.lastIndexOf('/'); |
| 58 | if (!lastSlashPos) { |
| 59 | return *this; |
| 60 | } |
| 61 | |
| 62 | // If path ends with slash, find the previous slash (to avoid empty last component) |
| 63 | if (lastSlashPos.value() == _path.length() - 1) { |
| 64 | auto prevSlashPos = _path.substring(0, lastSlashPos.value()).lastIndexOf('/'); |
| 65 | if (prevSlashPos) { |
| 66 | lastSlashPos = prevSlashPos; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return URL(_scheme.substring(0), _path.substring(0, lastSlashPos.value())); |
| 71 | } |
| 72 | |
| 73 | } // namespace Valdi |
nothing calls this directly
no test coverage detected