mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 01:33:07 -07:00
Replace single-character string with character literal
Also remove unnecessary dynamic allocation.
This commit is contained in:
parent
7e3cf99bb9
commit
0217d5b4c0
32 changed files with 96 additions and 96 deletions
|
@ -78,14 +78,14 @@ QString Utils::Fs::fromNativePath(const QString &path)
|
|||
QString Utils::Fs::fileExtension(const QString &filename)
|
||||
{
|
||||
QString ext = QString(filename).remove(QB_EXT);
|
||||
const int pointIndex = ext.lastIndexOf(".");
|
||||
const int pointIndex = ext.lastIndexOf('.');
|
||||
return (pointIndex >= 0) ? ext.mid(pointIndex + 1) : QString();
|
||||
}
|
||||
|
||||
QString Utils::Fs::fileName(const QString &filePath)
|
||||
{
|
||||
QString path = fromNativePath(filePath);
|
||||
const int slashIndex = path.lastIndexOf("/");
|
||||
const int slashIndex = path.lastIndexOf('/');
|
||||
if (slashIndex == -1)
|
||||
return path;
|
||||
return path.mid(slashIndex + 1);
|
||||
|
@ -94,7 +94,7 @@ QString Utils::Fs::fileName(const QString &filePath)
|
|||
QString Utils::Fs::folderName(const QString &filePath)
|
||||
{
|
||||
QString path = fromNativePath(filePath);
|
||||
const int slashIndex = path.lastIndexOf("/");
|
||||
const int slashIndex = path.lastIndexOf('/');
|
||||
if (slashIndex == -1)
|
||||
return path;
|
||||
return path.left(slashIndex);
|
||||
|
@ -121,13 +121,13 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
|
|||
};
|
||||
|
||||
// travel from the deepest folder and remove anything unwanted on the way out.
|
||||
QStringList dirList(path + "/"); // get all sub directories paths
|
||||
QStringList dirList(path + '/'); // get all sub directories paths
|
||||
QDirIterator iter(path, (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories);
|
||||
while (iter.hasNext())
|
||||
dirList << iter.next() + "/";
|
||||
dirList << iter.next() + '/';
|
||||
// sort descending by directory depth
|
||||
std::sort(dirList.begin(), dirList.end()
|
||||
, [](const QString &l, const QString &r) { return l.count("/") > r.count("/"); });
|
||||
, [](const QString &l, const QString &r) { return l.count('/') > r.count('/'); });
|
||||
|
||||
for (const QString &p : qAsConst(dirList)) {
|
||||
// remove unwanted files
|
||||
|
@ -139,7 +139,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
|
|||
QDir dir(p);
|
||||
QStringList tmpFileList = dir.entryList(QDir::Files);
|
||||
for (const QString &f : tmpFileList) {
|
||||
if (f.endsWith("~"))
|
||||
if (f.endsWith('~'))
|
||||
forceRemove(p + f);
|
||||
}
|
||||
|
||||
|
@ -246,9 +246,9 @@ qint64 Utils::Fs::freeDiskSpaceOnPath(const QString &path)
|
|||
QString Utils::Fs::branchPath(const QString &filePath, QString *removed)
|
||||
{
|
||||
QString ret = fromNativePath(filePath);
|
||||
if (ret.endsWith("/"))
|
||||
if (ret.endsWith('/'))
|
||||
ret.chop(1);
|
||||
const int slashIndex = ret.lastIndexOf("/");
|
||||
const int slashIndex = ret.lastIndexOf('/');
|
||||
if (slashIndex >= 0) {
|
||||
if (removed)
|
||||
*removed = ret.mid(slashIndex + 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue