Return the parts of the URI, split on the final "/" in the path. If there is no "/" in the path, the first part of the output is the scheme and host, and the second is the path. If the only "/" in the path is the first character, it is included in the first part of the output.
| 69 | // the second is the path. If the only "/" in the path is the first character, |
| 70 | // it is included in the first part of the output. |
| 71 | std::pair<StringPiece, StringPiece> SplitPath(StringPiece uri) { |
| 72 | StringPiece scheme, host, path; |
| 73 | ParseURI(uri, &scheme, &host, &path); |
| 74 | |
| 75 | auto pos = path.rfind('/'); |
| 76 | #ifdef PLATFORM_WINDOWS |
| 77 | if (pos == StringPiece::npos) pos = path.rfind('\\'); |
| 78 | #endif |
| 79 | // Handle the case with no '/' in 'path'. |
| 80 | if (pos == StringPiece::npos) |
| 81 | return std::make_pair(StringPiece(uri.begin(), host.end() - uri.begin()), |
| 82 | path); |
| 83 | |
| 84 | // Handle the case with a single leading '/' in 'path'. |
| 85 | if (pos == 0) |
| 86 | return std::make_pair( |
| 87 | StringPiece(uri.begin(), path.begin() + 1 - uri.begin()), |
| 88 | StringPiece(path.data() + 1, path.size() - 1)); |
| 89 | |
| 90 | return std::make_pair( |
| 91 | StringPiece(uri.begin(), path.begin() + pos - uri.begin()), |
| 92 | StringPiece(path.data() + pos + 1, path.size() - (pos + 1))); |
| 93 | } |
| 94 | |
| 95 | // Return the parts of the basename of path, split on the final ".". |
| 96 | // If there is no "." in the basename or "." is the final character in the |