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

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