Improved string concat to avoid "//" in paths

This commit is contained in:
Klaus Basan
2019-06-29 03:40:20 +02:00
committed by Mat Sutcliffe
parent fa8eed1611
commit 458daa4532
2 changed files with 10 additions and 3 deletions

View File

@@ -26,6 +26,7 @@
#include <QtGlobal>
#include <QMap>
#include <algorithm>
#include <QStringBuilder>
using namespace BlackConfig;
using namespace BlackMisc::Math;
@@ -115,7 +116,13 @@ namespace BlackMisc
{
if (path1.isEmpty()) { return QDir::cleanPath(path2); }
if (path2.isEmpty()) { return QDir::cleanPath(path1); }
return QDir::cleanPath(path1 + QChar('/') + path2);
if (path1.endsWith('/'))
{
// avoid double /
if (path2.startsWith('/')) { return QDir::cleanPath(path1 % path2.mid(1)); }
return QDir::cleanPath(path1 % path2);
}
return QDir::cleanPath(path1 % QChar('/') % path2);
}
QString CFileUtils::appendFilePathsAndFixUnc(const QString &path1, const QString &path2)

View File

@@ -53,8 +53,8 @@ namespace BlackMisc
QString CUrl::appendPath(const QString &pathToAppend)
{
QString p(getPath());
p = p.append("/").append(pathToAppend.trimmed()).replace("//", "/");
if (pathToAppend.isEmpty()) { return m_path; }
const QString p = CFileUtils::appendFilePaths(this->getPath(), pathToAppend);
this->setPath(p);
return m_path;
}