From: Rishabh Dave Date: Wed, 1 Oct 2025 19:21:20 +0000 (+0530) Subject: src/common: add helper to prepend "..." to trimmed paths X-Git-Tag: testing/wip-jcollin-testing-20251016.055245-squid^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1b0103d1be7bd2fa0ce26c7a54212dd1ef0a5927;p=ceph-ci.git src/common: add helper to prepend "..." to trimmed paths Signed-off-by: Rishabh Dave (cherry picked from commit c38a9138ba8294ab1243cf03ad0c8b0df4901967) --- diff --git a/src/common/strescape.h b/src/common/strescape.h index 9bf27fc3494..412fd1f6f7e 100644 --- a/src/common/strescape.h +++ b/src/common/strescape.h @@ -34,4 +34,21 @@ inline std::string binstrprint(std::string_view sv, size_t maxlen=0) return s; } +inline std::string get_trimmed_path_str(const std::string& path) +{ + // index of '/' before 10th component (count from end of the path). + size_t n = 0; + + for (int i = 1; i <= 10; ++i) { + n = path.rfind("/", n - 1); + if (n == std::string::npos) { + // path doesn't contain 10 components, return path as it is. + return path; + break; + } + } + + return std::string("..." + path.substr(n, -1)); +} + #endif