* @return the last two segments of @p document's path or an empty string in case of failure. */
| 42 | * @return the last two segments of @p document's path or an empty string in case of failure. |
| 43 | */ |
| 44 | QString documentDirAndFilename(const Sublime::Document* document) |
| 45 | { |
| 46 | auto* const urlDocument = qobject_cast<const Sublime::UrlDocument*>(document); |
| 47 | if (!urlDocument) { |
| 48 | return QString{}; |
| 49 | } |
| 50 | const auto path = urlDocument->url().path(); |
| 51 | |
| 52 | const auto lastSlashIndex = path.lastIndexOf(QLatin1Char{'/'}); |
| 53 | if (lastSlashIndex <= 0) { |
| 54 | return path; // either no slash in path or a single slash is the first symbol of path |
| 55 | } |
| 56 | |
| 57 | const auto penultimateSlashIndex = path.lastIndexOf(QLatin1Char{'/'}, lastSlashIndex - 1); |
| 58 | // If there is only one slash in the path, penultimateSlashIndex equals -1 and we correctly return the whole path. |
| 59 | return path.mid(penultimateSlashIndex + 1); |
| 60 | } |
| 61 | |
| 62 | struct ActionInsertionPoint |
| 63 | { |
no test coverage detected