| 178 | } |
| 179 | } |
| 180 | std::string_view RemoveTrailingSlash(std::string_view key, bool preserve_root) { |
| 181 | if (preserve_root && key.size() == 1) { |
| 182 | // If the user gives us "/" then don't return "" |
| 183 | return key; |
| 184 | } |
| 185 | #ifdef _WIN32 |
| 186 | if (preserve_root && key.size() == 3 && key[1] == ':' && key[0] != '/') { |
| 187 | // If the user gives us C:/ then don't return C: |
| 188 | return key; |
| 189 | } |
| 190 | #endif |
| 191 | while (!key.empty() && key.back() == kSep) { |
| 192 | key.remove_suffix(1); |
| 193 | } |
| 194 | return key; |
| 195 | } |
| 196 | |
| 197 | std::string_view RemoveLeadingSlash(std::string_view key) { |
| 198 | while (!key.empty() && key.front() == kSep) { |