1 #include <pbd/shortpath.h>
7 short_path (const Glib::ustring& path, ustring::size_type target_characters)
9 ustring::size_type last_sep;
10 ustring::size_type len = path.length();
11 const char separator = '/';
13 if (len <= target_characters) {
17 if ((last_sep = path.find_last_of (separator)) == ustring::npos) {
19 /* just a filename, but its too long anyway */
21 if (target_characters > 3) {
22 return path.substr (0, target_characters - 3) + ustring ("...");
24 /* stupid caller, just hand back the whole thing */
29 if (len - last_sep >= target_characters) {
31 /* even the filename itself is too long */
33 if (target_characters > 3) {
34 return path.substr (last_sep+1, target_characters - 3) + ustring ("...");
36 /* stupid caller, just hand back the whole thing */
41 uint32_t so_far = (len - last_sep);
42 uint32_t space_for = target_characters - so_far;
46 res += path.substr (last_sep - space_for);
49 /* remove part of the end */
51 res += path.substr (last_sep - space_for, len - last_sep + space_for - 3);