| 322 | } |
| 323 | |
| 324 | static 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 |
| 361 | static QVarLengthArray<QString, 16> splitPath(const QString& source) |
no test coverage detected