--------------------------------- FileUtil::GetAbsolutePath Gets the absolute path relative to the executable - returns false if none where found
| 304 | // Gets the absolute path relative to the executable - returns false if none where found |
| 305 | // |
| 306 | bool FileUtil::RemoveRelativePath(std::string& path) |
| 307 | { |
| 308 | // get the first '/.' sequence |
| 309 | size_t closestIdx = std::numeric_limits<size_t>::max(); |
| 310 | for (char const token : pathDelimiters) |
| 311 | { |
| 312 | size_t index = path.find(std::string(1, token) + std::string(".")); |
| 313 | if (index != std::string::npos && index < closestIdx) |
| 314 | { |
| 315 | closestIdx = index; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // if none is found our work is done |
| 320 | if (closestIdx > path.size()) |
| 321 | { |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | // otherwise we check if we are referring to this directory or the parent directory |
| 326 | size_t preCut = closestIdx; |
| 327 | size_t postCut = closestIdx + 1; |
| 328 | if (closestIdx + 2 < path.size() && path[closestIdx + 2] == '.') |
| 329 | { |
| 330 | // we have a parentDir |
| 331 | postCut++; |
| 332 | |
| 333 | // find the index of the previous ("parent") delim |
| 334 | size_t lastDelim = 0u; |
| 335 | for (char const token : pathDelimiters) |
| 336 | { |
| 337 | size_t index = path.rfind(token, preCut - 1); |
| 338 | if (index != std::string::npos && index > lastDelim) |
| 339 | { |
| 340 | lastDelim = index; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | // Check we found a parent directory |
| 345 | if (lastDelim == 0u || lastDelim >= preCut - 1) |
| 346 | { |
| 347 | LOG("FileUtil::RemoveRelativePath > expected to find a parent directory to cut", LogLevel::Error); |
| 348 | return false; |
| 349 | } |
| 350 | |
| 351 | preCut = lastDelim; |
| 352 | } |
| 353 | |
| 354 | path = path.substr(0, preCut) + path.substr(postCut + 1); |
| 355 | |
| 356 | return true; |
| 357 | } |
| 358 | |
| 359 | //--------------------------------- |
| 360 | // FileUtil::SplitFirstDirectory |
nothing calls this directly
no outgoing calls
no test coverage detected