mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
Ref T455, utility file functions
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <QIODevice>
|
||||
#include <QList>
|
||||
#include <QLockFile>
|
||||
#include <QRegularExpression>
|
||||
#include <QTextStream>
|
||||
#include <QtGlobal>
|
||||
#include <QMap>
|
||||
@@ -129,6 +130,42 @@ namespace BlackMisc
|
||||
return path.left(path.lastIndexOf('/'));
|
||||
}
|
||||
|
||||
QString CFileUtils::stripFirstSlashPart(const QString &path)
|
||||
{
|
||||
QString p = normalizeFilePathToQtStandard(path);
|
||||
int i = p.indexOf('/');
|
||||
if (i < 0) { return p; }
|
||||
if ((i + 1) >= path.length()) { return QStringLiteral(""); }
|
||||
return path.mid(i + 1);
|
||||
}
|
||||
|
||||
QStringList CFileUtils::stripFirstSlashParts(const QStringList &paths)
|
||||
{
|
||||
QStringList stripped;
|
||||
for (const QString &path : paths)
|
||||
{
|
||||
stripped.push_back(stripFileFromPath(path));
|
||||
}
|
||||
return stripped;
|
||||
}
|
||||
|
||||
QString CFileUtils::stripLeadingSlashOrDriveLetter(const QString &path)
|
||||
{
|
||||
thread_local const QRegularExpression re("^\\/+|^[a-zA-Z]:\\/*");
|
||||
QString p(path);
|
||||
return p.replace(re, "");
|
||||
}
|
||||
|
||||
QStringList CFileUtils::stripLeadingSlashOrDriveLetters(const QStringList &paths)
|
||||
{
|
||||
QStringList stripped;
|
||||
for (const QString &path : paths)
|
||||
{
|
||||
stripped.push_back(stripLeadingSlashOrDriveLetter(path));
|
||||
}
|
||||
return stripped;
|
||||
}
|
||||
|
||||
QString CFileUtils::lastPathSegment(const QString &path)
|
||||
{
|
||||
if (path.isEmpty()) { return QStringLiteral(""); }
|
||||
|
||||
@@ -85,6 +85,18 @@ namespace BlackMisc
|
||||
//! Strip file from path a/b/c.json a/b, return path
|
||||
static QString stripFileFromPath(const QString &path);
|
||||
|
||||
//! Strip first slash part "/a/b" => "a/b", "h:/foo" => foo
|
||||
static QString stripFirstSlashPart(const QString &path);
|
||||
|
||||
//! Strip first slash part "/a/b" => "a/b", "h:/foo" => foo
|
||||
static QStringList stripFirstSlashParts(const QStringList &paths);
|
||||
|
||||
//! Strip leading slash or drive letter "/a/b" => "a/b" "H:/Foo" => "Foo"
|
||||
static QString stripLeadingSlashOrDriveLetter(const QString &path);
|
||||
|
||||
//! Strip first slash part "/a/b" => "a/b", "h:/foo" => foo
|
||||
static QStringList stripLeadingSlashOrDriveLetters(const QStringList &paths);
|
||||
|
||||
//! Last path segment a/b/c => c
|
||||
static QString lastPathSegment(const QString &path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user