| 35 | // XXX How does this encode Windows UNC paths? |
| 36 | |
| 37 | std::vector<std::string> SplitAbstractPath(const std::string& path, char sep) { |
| 38 | std::vector<std::string> parts; |
| 39 | auto v = std::string_view(path); |
| 40 | // Strip trailing separator |
| 41 | if (v.length() > 0 && v.back() == sep) { |
| 42 | v = v.substr(0, v.length() - 1); |
| 43 | } |
| 44 | // Strip leading separator |
| 45 | if (v.length() > 0 && v.front() == sep) { |
| 46 | v = v.substr(1); |
| 47 | } |
| 48 | if (v.length() == 0) { |
| 49 | return parts; |
| 50 | } |
| 51 | |
| 52 | auto append_part = [&parts, &v](size_t start, size_t end) { |
| 53 | parts.emplace_back(v.substr(start, end - start)); |
| 54 | }; |
| 55 | |
| 56 | size_t start = 0; |
| 57 | while (true) { |
| 58 | size_t end = v.find_first_of(sep, start); |
| 59 | append_part(start, end); |
| 60 | if (end == std::string::npos) { |
| 61 | break; |
| 62 | } |
| 63 | start = end + 1; |
| 64 | } |
| 65 | return parts; |
| 66 | } |
| 67 | |
| 68 | std::string SliceAbstractPath(const std::string& s, int offset, int length, char sep) { |
| 69 | if (offset < 0 || length < 0) { |