]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
src/common: add helper to prepend "..." to trimmed paths
authorRishabh Dave <ridave@redhat.com>
Wed, 1 Oct 2025 19:21:20 +0000 (00:51 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 1 Oct 2025 20:15:31 +0000 (01:45 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/common/strescape.h

index 9bf27fc3494b0aa5dab7fed09aeeff7f2e0f6bd2..412fd1f6f7eb9622216cd1abb483321fb0b14fe0 100644 (file)
@@ -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