MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / util_RemoveLastPathElement

Function util_RemoveLastPathElement

src/core/unixfsservices.cpp:1090–1114  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////// Function name : util_RemoveLastPathElement Description : effectively pops off a path element from the end, except for the root dir, where it does nothing it removes any slashes before and after the element ///root//foo/ -> leaves "///root" ("foo" is strElem) ///root -> leaves "" ("root" is str

Source from the content-addressed store, hash-verified

1088// Argument : TSTRING& strElem
1089/////////////////////////////////////////////////////////////////////////////////
1090void util_RemoveLastPathElement(TSTRING& strPath, TSTRING& strElem)
1091{
1092
1093 // remove all trailing separators
1094 util_RemoveTrailingSeps(strPath);
1095
1096 // find the last separator
1097 TSTRING::size_type lastSep = strPath.rfind(TW_SLASH);
1098
1099 // if separator was found, take all chars after it
1100 if (lastSep != TSTRING::npos)
1101 {
1102 strElem = strPath.substr(lastSep + 1);
1103 strPath.resize(lastSep + 1);
1104 }
1105 else // no seps in name, take whole string
1106 {
1107 // last element
1108 strElem = strPath;
1109 strPath.erase();
1110 }
1111
1112 // remove all trailing separators
1113 util_RemoveTrailingSeps(strPath);
1114}
1115
1116
1117////////////////////////////////////////////////////////////////////////////////////

Callers 1

FullPathMethod · 0.85

Calls 2

util_RemoveTrailingSepsFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected