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

Function elidedPathLeft

kdevplatform/language/backgroundparser/backgroundparser.cpp:56–73  ·  view source on GitHub ↗

* Elides string in @p path, e.g. "VEEERY/LONG/PATH" -> ".../LONG/PATH" * - probably much faster than QFontMetrics::elidedText() * - we do not need a widget context * - takes path separators into account * * @p width Maximum number of characters * * TODO: Move to kdevutil? */

Source from the content-addressed store, hash-verified

54 * TODO: Move to kdevutil?
55 */
56QString elidedPathLeft(const QString& path, int width)
57{
58 const QLatin1String placeholder("...");
59
60 if (path.size() <= width) {
61 return path;
62 }
63
64 int start = (path.size() - width) + placeholder.size();
65 int pos = path.indexOf(QDir::separator(), start);
66 if (pos == -1) {
67 pos = start; // no separator => just cut off the path at the beginning
68 }
69 Q_ASSERT(path.size() - pos >= 0 && path.size() - pos <= width);
70
71 const auto elidedText = QStringView{path}.last(path.size() - pos);
72 return placeholder + elidedText;
73}
74
75/**
76 * @return true if @p url is non-empty, valid and has a clean path, false otherwise.

Callers 1

Calls 3

sizeMethod · 0.45
indexOfMethod · 0.45
lastMethod · 0.45

Tested by

no test coverage detected