Remove last component from the (normalized) path: Say /A/B/C/ -> /A/B/ Notice that /A/ is modified to / and returns true.
| 357 | // Say /A/B/C/ -> /A/B/ |
| 358 | // Notice that /A/ is modified to / and returns true. |
| 359 | static bool RemoveLastComponent(butil::StringPiece* path) { |
| 360 | if (path->empty()) { |
| 361 | return false; |
| 362 | } |
| 363 | if (path->back() == '/') { |
| 364 | path->remove_suffix(1); |
| 365 | } |
| 366 | size_t slash_pos = path->rfind('/'); |
| 367 | if (slash_pos == std::string::npos) { |
| 368 | return false; |
| 369 | } |
| 370 | path->remove_suffix(path->size() - slash_pos - 1); // keep the slash |
| 371 | return true; |
| 372 | } |
| 373 | |
| 374 | // Normalized as /A/B/C/ |
| 375 | static std::string NormalizeSlashes(const butil::StringPiece& path) { |
no test coverage detected