MCPcopy Create free account
hub / github.com/apache/brpc / RemoveLastComponent

Function RemoveLastComponent

src/brpc/restful.cpp:359–372  ·  view source on GitHub ↗

Remove last component from the (normalized) path: Say /A/B/C/ -> /A/B/ Notice that /A/ is modified to / and returns true.

Source from the content-addressed store, hash-verified

357// Say /A/B/C/ -> /A/B/
358// Notice that /A/ is modified to / and returns true.
359static 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/
375static std::string NormalizeSlashes(const butil::StringPiece& path) {

Callers 1

FindMethodPropertyMethod · 0.85

Calls 5

remove_suffixMethod · 0.80
rfindMethod · 0.80
emptyMethod · 0.45
backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected