1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QFILESYSTEMENTRY_P_H
6#define QFILESYSTEMENTRY_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/private/qglobal_p.h>
20#include <QtCore/qstring.h>
21#include <QtCore/qbytearray.h>
22
23QT_BEGIN_NAMESPACE
24
25class QFileSystemEntry
26{
27public:
28
29#ifndef Q_OS_WIN
30 typedef QByteArray NativePath;
31#else
32 typedef QString NativePath;
33#endif
34 struct FromNativePath{};
35 struct FromInternalPath{};
36
37 Q_AUTOTEST_EXPORT QFileSystemEntry();
38 Q_AUTOTEST_EXPORT explicit QFileSystemEntry(const QString &filePath);
39
40 Q_AUTOTEST_EXPORT QFileSystemEntry(const QString &filePath, FromInternalPath dummy);
41 Q_AUTOTEST_EXPORT QFileSystemEntry(const NativePath &nativeFilePath, FromNativePath dummy);
42 Q_AUTOTEST_EXPORT QFileSystemEntry(const QString &filePath, const NativePath &nativeFilePath);
43
44 Q_AUTOTEST_EXPORT QString filePath() const;
45 Q_AUTOTEST_EXPORT QString fileName() const;
46 Q_AUTOTEST_EXPORT QString path() const;
47 Q_AUTOTEST_EXPORT NativePath nativeFilePath() const;
48 Q_AUTOTEST_EXPORT QString baseName() const;
49 Q_AUTOTEST_EXPORT QString completeBaseName() const;
50 Q_AUTOTEST_EXPORT QString suffix() const;
51 Q_AUTOTEST_EXPORT QString completeSuffix() const;
52 Q_AUTOTEST_EXPORT bool isAbsolute() const;
53 Q_AUTOTEST_EXPORT bool isRelative() const;
54 Q_AUTOTEST_EXPORT bool isClean() const;
55
56#if defined(Q_OS_WIN)
57 Q_AUTOTEST_EXPORT bool isDriveRoot() const;
58 static bool isDriveRootPath(const QString &path);
59 static QString removeUncOrLongPathPrefix(QString path);
60#endif
61 Q_AUTOTEST_EXPORT bool isRoot() const;
62
63 Q_AUTOTEST_EXPORT bool isEmpty() const;
64
65 void clear()
66 {
67 *this = QFileSystemEntry();
68 }
69
70 Q_CORE_EXPORT static bool isRootPath(const QString &path);
71
72private:
73 // creates the QString version out of the bytearray version
74 void resolveFilePath() const;
75 // creates the bytearray version out of the QString version
76 void resolveNativeFilePath() const;
77 // resolves the separator
78 void findLastSeparator() const;
79 // resolves the dots and the separator
80 void findFileNameSeparators() const;
81
82 mutable QString m_filePath; // always has slashes as separator
83 mutable NativePath m_nativeFilePath; // native encoding and separators
84
85 mutable qint16 m_lastSeparator; // index in m_filePath of last separator
86 mutable qint16 m_firstDotInFileName; // index after m_filePath for first dot (.)
87 mutable qint16 m_lastDotInFileName; // index after m_firstDotInFileName for last dot (.)
88};
89
90QT_END_NAMESPACE
91
92#endif // include guard
93

source code of qtbase/src/corelib/io/qfilesystementry_p.h