6#include <QtCore/qdir.h>
7#include <QtCore/qfile.h>
8#include <QtCore/private/qfsfileengine_p.h>
10#include <QtCore/qstringbuilder.h>
28 int idx = localPath.
indexOf(u
'\\', 2);
29 if (idx == -1 || idx + 1 == localPath.
length())
45 : m_lastSeparator(-1),
46 m_firstDotInFileName(-1),
47 m_lastDotInFileName(-1)
60 m_lastDotInFileName(0)
70 : m_filePath(filePath),
73 m_lastDotInFileName(0)
82 : m_nativeFilePath(nativeFilePath),
85 m_lastDotInFileName(0)
91 m_nativeFilePath(nativeFilePath),
94 m_lastDotInFileName(0)
106 resolveNativeFilePath();
107 return m_nativeFilePath;
110void QFileSystemEntry::resolveFilePath()
const
121void QFileSystemEntry::resolveNativeFilePath()
const
127 filePath = fixIfRelativeUncPath(m_filePath);
139 if (m_lastSeparator == -1 && m_filePath.
length() >= 2 && m_filePath.
at(1) == u
':')
140 return m_filePath.
mid(2);
142 return m_filePath.
mid(m_lastSeparator + 1);
148 if (m_lastSeparator == -1) {
150 if (m_filePath.
length() >= 2 && m_filePath.
at(1) == u
':')
151 return m_filePath.
left(2);
155 if (m_lastSeparator == 0)
158 if (m_lastSeparator == 2 && m_filePath.
at(1) == u
':')
159 return m_filePath.
left(m_lastSeparator + 1);
161 return m_filePath.
left(m_lastSeparator);
166 findFileNameSeparators();
168 if (m_firstDotInFileName >= 0) {
169 length = m_firstDotInFileName;
170 if (m_lastSeparator != -1)
174 if (m_lastSeparator == -1 && m_filePath.
length() >= 2 && m_filePath.
at(1) == u
':')
177 return m_filePath.
mid(m_lastSeparator + 1,
length);
182 findFileNameSeparators();
184 if (m_firstDotInFileName >= 0) {
185 length = m_firstDotInFileName + m_lastDotInFileName;
186 if (m_lastSeparator != -1)
190 if (m_lastSeparator == -1 && m_filePath.
length() >= 2 && m_filePath.
at(1) == u
':')
193 return m_filePath.
mid(m_lastSeparator + 1,
length);
198 findFileNameSeparators();
200 if (m_lastDotInFileName == -1)
203 return m_filePath.
mid(
qMax((
qint16)0, m_lastSeparator) + m_firstDotInFileName + m_lastDotInFileName + 1);
208 findFileNameSeparators();
209 if (m_firstDotInFileName == -1)
212 return m_filePath.
mid(
qMax((
qint16)0, m_lastSeparator) + m_firstDotInFileName + 1);
220 || (m_filePath.
at(0).unicode() !=
'/'
221 && !(m_filePath.
length() >= 2 && m_filePath.
at(1).unicode() ==
':')));
227 return ((m_filePath.
length() >= 3
228 && m_filePath.
at(0).isLetter()
229 && m_filePath.
at(1).unicode() ==
':'
230 && m_filePath.
at(2).unicode() ==
'/')
231 || (m_filePath.
length() >= 2
232 && m_filePath.
at(0) == u
'/'
233 && m_filePath.
at(1) == u
'/'));
244 return (!m_filePath.
isEmpty() && (m_filePath.
at(0).unicode() ==
'/'));
249bool QFileSystemEntry::isDriveRoot()
const
252 return QFileSystemEntry::isDriveRootPath(m_filePath);
255bool QFileSystemEntry::isDriveRootPath(
const QString &
path)
257 return (
path.length() == 3
258 &&
path.at(0).isLetter() &&
path.at(1) == u
':'
259 &&
path.at(2) == u
'/');
265 if (
path.size() < minPrefixSize)
269 const auto slash =
path[0];
270 if (slash != u
'\\' && slash != u
'/')
274 if (
data[2] == u
'?' &&
data[3] == slash && (
data[1] == slash ||
data[1] == u
'?')) {
278 if (
path.size() >= 4) {
280 if (
data[0] == u
'U' &&
data[1] == u
'N' &&
data[2] == u
'C' &&
data[3] == slash) {
282 return path.sliced(2);
295 || isDriveRootPath(
path)
317void QFileSystemEntry::findLastSeparator()
const
325void QFileSystemEntry::findFileNameSeparators()
const
329 int firstDotInFileName = -1;
330 int lastDotInFileName = -1;
331 int lastSeparator = m_lastSeparator;
334 if (lastSeparator < 0) {
338 stop = lastSeparator;
341 int i = m_filePath.
size() - 1;
342 for (;
i >= stop; --
i) {
343 if (m_filePath.
at(
i).unicode() ==
'.') {
344 firstDotInFileName = lastDotInFileName =
i;
346 }
else if (m_filePath.
at(
i).unicode() ==
'/') {
352 if (lastSeparator !=
i) {
353 for (--
i;
i >= stop; --
i) {
354 if (m_filePath.
at(
i).unicode() ==
'.')
355 firstDotInFileName =
i;
356 else if (m_filePath.
at(
i).unicode() ==
'/') {
362 m_lastSeparator = lastSeparator;
363 m_firstDotInFileName = firstDotInFileName == -1 ? -1 : firstDotInFileName -
qMax(0, lastSeparator);
364 if (lastDotInFileName == -1)
365 m_lastDotInFileName = -1;
366 else if (firstDotInFileName == lastDotInFileName)
367 m_lastDotInFileName = 0;
369 m_lastDotInFileName = lastDotInFileName - firstDotInFileName;
381 if (dots == 1 || dots == 2)
401 return (dots != 1 && dots != 2);
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
static QString fromNativeSeparators(const QString &pathName)
static QString toNativeSeparators(const QString &pathName)
static QString currentPath()
Returns the absolute path of the application's current directory.
Q_AUTOTEST_EXPORT NativePath nativeFilePath() const
Q_AUTOTEST_EXPORT bool isEmpty() const
Q_AUTOTEST_EXPORT QString baseName() const
Q_AUTOTEST_EXPORT bool isClean() const
Q_AUTOTEST_EXPORT QString completeBaseName() const
Q_AUTOTEST_EXPORT bool isRelative() const
static Q_CORE_EXPORT bool isRootPath(const QString &path)
Q_AUTOTEST_EXPORT QString suffix() const
Q_AUTOTEST_EXPORT QString path() const
Q_AUTOTEST_EXPORT bool isRoot() const
Q_AUTOTEST_EXPORT QString filePath() const
Q_AUTOTEST_EXPORT QString completeSuffix() const
Q_AUTOTEST_EXPORT QFileSystemEntry()
Q_AUTOTEST_EXPORT QString fileName() const
Q_AUTOTEST_EXPORT bool isAbsolute() const
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString left(qsizetype n) const &
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
const_iterator constEnd() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last character in...
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString sliced(qsizetype pos) const &
QString mid(qsizetype position, qsizetype n=-1) const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
QString right(qsizetype n) const &
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
QChar * data()
Returns a pointer to the data stored in the QString.
QString trimmed() const &
const_iterator constBegin() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the st...
qsizetype length() const noexcept
Returns the number of characters in this string.
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter * iter
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
constexpr int Uninitialized
constexpr const T & qMax(const T &a, const T &b)
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLchar *const * path
static QString fromNativeSeparators(const QString &pathName)