| 2492 | } |
| 2493 | |
| 2494 | std::string popPath(const std::string& path) { |
| 2495 | int i = path.size() - 1; |
| 2496 | // Skip over any trailing separators |
| 2497 | while (i >= 0 && path[i] == CANONICAL_PATH_SEPARATOR) { |
| 2498 | --i; |
| 2499 | } |
| 2500 | // Skip over non separators |
| 2501 | while (i >= 0 && path[i] != CANONICAL_PATH_SEPARATOR) { |
| 2502 | --i; |
| 2503 | } |
| 2504 | // Skip over trailing separators again |
| 2505 | bool foundSeparator = false; |
| 2506 | while (i >= 0 && path[i] == CANONICAL_PATH_SEPARATOR) { |
| 2507 | --i; |
| 2508 | foundSeparator = true; |
| 2509 | } |
| 2510 | |
| 2511 | if (foundSeparator) { |
| 2512 | ++i; |
| 2513 | } else { |
| 2514 | // If absolute then we popped off the only path component so return "/" |
| 2515 | if (!path.empty() && path.front() == CANONICAL_PATH_SEPARATOR) { |
| 2516 | return "/"; |
| 2517 | } |
| 2518 | } |
| 2519 | return path.substr(0, i + 1); |
| 2520 | } |
| 2521 | |
| 2522 | std::string abspath(std::string const& path_, bool resolveLinks, bool mustExist) { |
| 2523 | if (path_.empty()) { |