MCPcopy Create free account
hub / github.com/KDE/kdevelop / documentDirAndFilename

Function documentDirAndFilename

kdevplatform/sublime/container.cpp:44–60  ·  view source on GitHub ↗

* @return the last two segments of @p document's path or an empty string in case of failure. */

Source from the content-addressed store, hash-verified

42 * @return the last two segments of @p document's path or an empty string in case of failure.
43 */
44QString 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
62struct ActionInsertionPoint
63{

Callers 1

Calls 3

midMethod · 0.80
pathMethod · 0.45
urlMethod · 0.45

Tested by

no test coverage detected