MCPcopy Create free account
hub / github.com/Snapchat/Valdi / withLastPathComponentRemoved

Method withLastPathComponentRemoved

valdi_core/src/valdi_core/cpp/Utils/URL.cpp:55–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55URL 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

Callers

nothing calls this directly

Calls 5

URLClass · 0.85
lastIndexOfMethod · 0.80
substringMethod · 0.80
valueMethod · 0.65
lengthMethod · 0.45

Tested by

no test coverage detected