mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 02:35:38 +08:00
Ref T455, utility file functions
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QLockFile>
|
#include <QLockFile>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
@@ -129,6 +130,42 @@ namespace BlackMisc
|
|||||||
return path.left(path.lastIndexOf('/'));
|
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)
|
QString CFileUtils::lastPathSegment(const QString &path)
|
||||||
{
|
{
|
||||||
if (path.isEmpty()) { return QStringLiteral(""); }
|
if (path.isEmpty()) { return QStringLiteral(""); }
|
||||||
|
|||||||
@@ -85,6 +85,18 @@ namespace BlackMisc
|
|||||||
//! Strip file from path a/b/c.json a/b, return path
|
//! Strip file from path a/b/c.json a/b, return path
|
||||||
static QString stripFileFromPath(const QString &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
|
//! Last path segment a/b/c => c
|
||||||
static QString lastPathSegment(const QString &path);
|
static QString lastPathSegment(const QString &path);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user