MCPcopy Create free account
hub / github.com/apple/foundationdb / popPath

Function popPath

fdbmonitor/fdbmonitor.cpp:318–344  ·  view source on GitHub ↗

Removes the last component from a path string (if possible) and returns the result with one trailing separator.

Source from the content-addressed store, hash-verified

316
317// Removes the last component from a path string (if possible) and returns the result with one trailing separator.
318std::string popPath(const std::string& path) {
319 int i = path.size() - 1;
320 // Skip over any trailing separators
321 while (i >= 0 && path[i] == CANONICAL_PATH_SEPARATOR) {
322 --i;
323 }
324 // Skip over non separators
325 while (i >= 0 && path[i] != CANONICAL_PATH_SEPARATOR) {
326 --i;
327 }
328 // Skip over trailing separators again
329 bool foundSeparator = false;
330 while (i >= 0 && path[i] == CANONICAL_PATH_SEPARATOR) {
331 --i;
332 foundSeparator = true;
333 }
334
335 if (foundSeparator) {
336 ++i;
337 } else {
338 // If absolute then we popped off the only path component so return "/"
339 if (!path.empty() && path.front() == CANONICAL_PATH_SEPARATOR) {
340 return "/";
341 }
342 }
343 return path.substr(0, i + 1);
344}
345
346std::string abspath(std::string const& path, bool resolveLinks = true) {
347 if (path.empty()) {

Callers 4

abspathFunction · 0.70
parentDirectoryFunction · 0.70
getDefaultLibraryPathMethod · 0.50
processStartMethod · 0.50

Calls 4

frontMethod · 0.80
substrMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected