Skip to content

Commit c38a913

Browse files
src/common: add helper to prepend "..." to trimmed paths
Signed-off-by: Rishabh Dave <[email protected]>
1 parent 10e4ccb commit c38a913

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/common/strescape.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,21 @@ inline std::string binstrprint(std::string_view sv, size_t maxlen=0)
3434
return s;
3535
}
3636

37+
inline std::string get_trimmed_path_str(const std::string& path)
38+
{
39+
// index of '/' before 10th component (count from end of the path).
40+
size_t n = 0;
41+
42+
for (int i = 1; i <= 10; ++i) {
43+
n = path.rfind("/", n - 1);
44+
if (n == std::string::npos) {
45+
// path doesn't contain 10 components, return path as it is.
46+
return path;
47+
break;
48+
}
49+
}
50+
51+
return std::string("..." + path.substr(n, -1));
52+
}
53+
3754
#endif

0 commit comments

Comments
 (0)