--------------------------------- FileUtil::ExtractPath Extract the path from a path with file name
| 144 | // Extract the path from a path with file name |
| 145 | // |
| 146 | std::string FileUtil::ExtractPath(std::string const& fileName) |
| 147 | { |
| 148 | // Get the last path delimiter |
| 149 | size_t closestIdx = 0u; |
| 150 | for (char const token : pathDelimiters) |
| 151 | { |
| 152 | size_t index = fileName.rfind(token); |
| 153 | if (index != std::string::npos && index > closestIdx) |
| 154 | { |
| 155 | closestIdx = index; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // if the closest "delimiter is not an actual delimiter", the file has no path attached |
| 160 | if (std::find(pathDelimiters.cbegin(), pathDelimiters.cend(), fileName[closestIdx]) == pathDelimiters.cend()) |
| 161 | { |
| 162 | return ""; |
| 163 | } |
| 164 | |
| 165 | return fileName.substr(0, closestIdx + 1); |
| 166 | } |
| 167 | |
| 168 | //--------------------------------- |
| 169 | // FileUtil::ExtractName |
nothing calls this directly
no outgoing calls
no test coverage detected