///////////////////////////////////////////////////////////////////////////// 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
| 1088 | // Argument : TSTRING& strElem |
| 1089 | ///////////////////////////////////////////////////////////////////////////////// |
| 1090 | void 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 | //////////////////////////////////////////////////////////////////////////////////// |
no test coverage detected