mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-07 05:31:25 -07:00
parent
e1abcc684a
commit
4ca6de2b54
55 changed files with 485 additions and 472 deletions
|
@ -38,6 +38,8 @@
|
|||
#include <QMimeDatabase>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "base/global.h"
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
const Qt::CaseSensitivity CASE_SENSITIVITY = Qt::CaseInsensitive;
|
||||
#else
|
||||
|
@ -74,11 +76,11 @@ bool Path::isValid() const
|
|||
return false;
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
const QRegularExpression regex {QLatin1String("[:?\"*<>|]")};
|
||||
const QRegularExpression regex {u"[:?\"*<>|]"_qs};
|
||||
#elif defined(Q_OS_MACOS)
|
||||
const QRegularExpression regex {QLatin1String("[\\0:]")};
|
||||
const QRegularExpression regex {u"[\\0:]"_qs};
|
||||
#else
|
||||
const QRegularExpression regex {QLatin1String("[\\0]")};
|
||||
const QRegularExpression regex {u"[\\0]"_qs};
|
||||
#endif
|
||||
return !m_pathStr.contains(regex);
|
||||
}
|
||||
|
@ -105,24 +107,24 @@ bool Path::exists() const
|
|||
|
||||
Path Path::rootItem() const
|
||||
{
|
||||
const int slashIndex = m_pathStr.indexOf(QLatin1Char('/'));
|
||||
const int slashIndex = m_pathStr.indexOf(u'/');
|
||||
if (slashIndex < 0)
|
||||
return *this;
|
||||
|
||||
if (slashIndex == 0) // *nix absolute path
|
||||
return createUnchecked(QLatin1String("/"));
|
||||
return createUnchecked(u"/"_qs);
|
||||
|
||||
return createUnchecked(m_pathStr.left(slashIndex));
|
||||
}
|
||||
|
||||
Path Path::parentPath() const
|
||||
{
|
||||
const int slashIndex = m_pathStr.lastIndexOf(QLatin1Char('/'));
|
||||
const int slashIndex = m_pathStr.lastIndexOf(u'/');
|
||||
if (slashIndex == -1)
|
||||
return {};
|
||||
|
||||
if (slashIndex == 0) // *nix absolute path
|
||||
return (m_pathStr.size() == 1) ? Path() : createUnchecked(QLatin1String("/"));
|
||||
return (m_pathStr.size() == 1) ? Path() : createUnchecked(u"/"_qs);
|
||||
|
||||
return createUnchecked(m_pathStr.left(slashIndex));
|
||||
}
|
||||
|
@ -140,17 +142,17 @@ QString Path::extension() const
|
|||
{
|
||||
const QString suffix = QMimeDatabase().suffixForFileName(m_pathStr);
|
||||
if (!suffix.isEmpty())
|
||||
return (QLatin1String(".") + suffix);
|
||||
return (u"." + suffix);
|
||||
|
||||
const int slashIndex = m_pathStr.lastIndexOf(QLatin1Char('/'));
|
||||
const int slashIndex = m_pathStr.lastIndexOf(u'/');
|
||||
const auto filename = QStringView(m_pathStr).mid(slashIndex + 1);
|
||||
const int dotIndex = filename.lastIndexOf(QLatin1Char('.'), -2);
|
||||
const int dotIndex = filename.lastIndexOf(u'.', -2);
|
||||
return ((dotIndex == -1) ? QString() : filename.mid(dotIndex).toString());
|
||||
}
|
||||
|
||||
bool Path::hasExtension(const QString &ext) const
|
||||
{
|
||||
Q_ASSERT(ext.startsWith(QLatin1Char('.')) && (ext.size() >= 2));
|
||||
Q_ASSERT(ext.startsWith(u'.') && (ext.size() >= 2));
|
||||
|
||||
return m_pathStr.endsWith(ext, Qt::CaseInsensitive);
|
||||
}
|
||||
|
@ -160,7 +162,7 @@ bool Path::hasAncestor(const Path &other) const
|
|||
if (other.isEmpty() || (m_pathStr.size() <= other.m_pathStr.size()))
|
||||
return false;
|
||||
|
||||
return (m_pathStr[other.m_pathStr.size()] == QLatin1Char('/'))
|
||||
return (m_pathStr[other.m_pathStr.size()] == u'/')
|
||||
&& m_pathStr.startsWith(other.m_pathStr, CASE_SENSITIVITY);
|
||||
}
|
||||
|
||||
|
@ -300,7 +302,7 @@ Path operator/(const Path &lhs, const Path &rhs)
|
|||
if (lhs.isEmpty())
|
||||
return rhs;
|
||||
|
||||
return Path(lhs.m_pathStr + QLatin1Char('/') + rhs.m_pathStr);
|
||||
return Path(lhs.m_pathStr + u'/' + rhs.m_pathStr);
|
||||
}
|
||||
|
||||
Path operator+(const Path &lhs, const QString &rhs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue