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

Function cleanPath

kdevplatform/util/path.cpp:324–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324static void cleanPath(QVector<QString>* data, const bool isRemote)
325{
326 if (data->isEmpty()) {
327 return;
328 }
329 const int startOffset = isRemote ? 1 : 0;
330
331 auto it = data->begin() + startOffset;
332 while (it != data->end()) {
333 if (*it == QLatin1String("..")) {
334 // The path of a Path is always absolute. So we replicate standard
335 // operating system command line behaviors of the command `cd ..` below.
336 if (it == (data->begin() + startOffset)) {
337 // Running `cd ..` in the root directory in Bash keeps the root directory current (no change).
338 it = data->erase(it);
339 } else {
340 if (isWindowsDriveLetter(*(it - 1))) {
341 // Running `cd ..` in the root directory of a drive in Windows cmd
342 // keeps the drive root directory current (no change).
343 it = data->erase(it);
344 } else {
345 // *it represents `cd ..` from *(it - 1) => remove both segments to simplify
346 it = data->erase(it - 1, it + 1);
347 }
348 }
349 } else if (*it == QLatin1String(".")) {
350 it = data->erase(it);
351 } else {
352 ++it;
353 }
354 }
355 if (data->count() == startOffset) {
356 data->append(QString());
357 }
358}
359
360// Optimized QString::split code for the specific Path use-case
361static QVarLengthArray<QString, 16> splitPath(const QString& source)

Callers 15

addPathMethod · 0.85
mapToBuildMethod · 0.85
resolveIncludePathMethod · 0.85
urlForFileModelMethod · 0.85
searchInPathMethod · 0.85
shortNativePathMethod · 0.85
resolvePathMethod · 0.85
parentDirMethod · 0.85
fromUserInputMethod · 0.85

Calls 7

isWindowsDriveLetterFunction · 0.85
QStringClass · 0.70
isEmptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
countMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected