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-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F63917%2Fhead;p=ceph.git src/common: add helper to prepend "..." to trimmed paths Signed-off-by: Rishabh Dave --- diff --git a/src/common/strescape.h b/src/common/strescape.h index 9bf27fc3494b..412fd1f6f7eb 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