6#include <QtCore/qdir.h>
7#include <QtCore/qfile.h>
8#include <QtCore/private/qfsfileengine_p.h>
10#include <QtCore/qstringbuilder.h>
24 int idx = localPath.
indexOf(u
'\\', 2);
25 if (idx == -1 || idx + 1 == localPath.
length())
41 : m_lastSeparator(-1),
42 m_firstDotInFileName(-1),
43 m_lastDotInFileName(-1)
55 m_firstDotInFileName(-2),
56 m_lastDotInFileName(0)
66 : m_filePath(filePath),
68 m_firstDotInFileName(-2),
69 m_lastDotInFileName(0)
78 : m_nativeFilePath(nativeFilePath),
80 m_firstDotInFileName(-2),
81 m_lastDotInFileName(0)
87 m_nativeFilePath(nativeFilePath),
89 m_firstDotInFileName(-2),
90 m_lastDotInFileName(0)
102 resolveNativeFilePath();
103 return m_nativeFilePath;
106void QFileSystemEntry::resolveFilePath()
const
117void QFileSystemEntry::resolveNativeFilePath()
const
123 filePath = fixIfRelativeUncPath(m_filePath);
135 if (m_lastSeparator == -1 && m_filePath.
length() >= 2 && m_filePath.
at(1) == u
':')
136 return m_filePath.
mid(2);
138 return m_filePath.
mid(m_lastSeparator + 1);
144 if (m_lastSeparator == -1) {
146 if (m_filePath.
length() >= 2 && m_filePath.
at(1) == u
':')
147 return m_filePath.
left(2);
151 if (m_lastSeparator == 0)
154 if (m_lastSeparator == 2 && m_filePath.
at(1) == u
':')
155 return m_filePath.
left(m_lastSeparator + 1);
157 return m_filePath.
left(m_lastSeparator);
162 findFileNameSeparators();
164 if (m_firstDotInFileName >= 0) {
165 length = m_firstDotInFileName;
166 if (m_lastSeparator != -1)
170 if (m_lastSeparator == -1 && m_filePath.
length() >= 2 && m_filePath.
at(1) == u
':')
173 return m_filePath.
mid(m_lastSeparator + 1,
length);
178 findFileNameSeparators();
180 if (m_firstDotInFileName >= 0) {
181 length = m_firstDotInFileName + m_lastDotInFileName;
182 if (m_lastSeparator != -1)
186 if (m_lastSeparator == -1 && m_filePath.
length() >= 2 && m_filePath.
at(1) == u
':')
189 return m_filePath.
mid(m_lastSeparator + 1,
length);
194 findFileNameSeparators();
196 if (m_lastDotInFileName == -1)
199 return m_filePath.
mid(
qMax((
qint16)0, m_lastSeparator) + m_firstDotInFileName + m_lastDotInFileName + 1);
204 findFileNameSeparators();
205 if (m_firstDotInFileName == -1)
208 return m_filePath.
mid(
qMax((
qint16)0, m_lastSeparator) + m_firstDotInFileName + 1);
223 return ((m_filePath.
length() >= 3
227 || (m_filePath.
length() >= 2
228 && m_filePath.
at(0) == u
'/'
229 && m_filePath.
at(1) == u
'/'));
245bool QFileSystemEntry::isDriveRoot()
const
248 return QFileSystemEntry::isDriveRootPath(m_filePath);
251bool QFileSystemEntry::isDriveRootPath(
const QString &
path)
253 return (
path.length() == 3
254 &&
path.at(0).isLetter() &&
path.at(1) == u
':'
255 &&
path.at(2) == u
'/');
261 if (
path.size() < minPrefixSize)
265 const auto slash =
path[0];
266 if (slash != u
'\\' && slash != u
'/')
270 if (
data[2] == u
'?' &&
data[3] == slash && (
data[1] == slash ||
data[1] == u
'?')) {
274 if (
path.size() >= 4) {
276 if (
data[0] == u
'U' &&
data[1] == u
'N' &&
data[2] == u
'C' &&
data[3] == slash) {
278 return path.sliced(2);
291 || isDriveRootPath(
path)
313void QFileSystemEntry::findLastSeparator()
const
315 if (m_lastSeparator == -2) {
321void QFileSystemEntry::findFileNameSeparators()
const
323 if (m_firstDotInFileName == -2) {
325 int firstDotInFileName = -1;
326 int lastDotInFileName = -1;
327 int lastSeparator = m_lastSeparator;
330 if (lastSeparator < 0) {
334 stop = lastSeparator;
337 int i = m_filePath.
size() - 1;
338 for (;
i >= stop; --
i) {
340 firstDotInFileName = lastDotInFileName =
i;
342 }
else if (m_filePath.
at(
i).
unicode() ==
'/') {
348 if (lastSeparator !=
i) {
349 for (--
i;
i >= stop; --
i) {
351 firstDotInFileName =
i;
358 m_lastSeparator = lastSeparator;
359 m_firstDotInFileName = firstDotInFileName == -1 ? -1 : firstDotInFileName -
qMax(0, lastSeparator);
360 if (lastDotInFileName == -1)
361 m_lastDotInFileName = -1;
362 else if (firstDotInFileName == lastDotInFileName)
363 m_lastDotInFileName = 0;
365 m_lastDotInFileName = lastDotInFileName - firstDotInFileName;
377 if (dots == 1 || dots == 2)
397 return (dots != 1 && dots != 2);
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
constexpr char16_t unicode() const noexcept
Returns the numeric Unicode value of the QChar.
constexpr bool isLetter() const noexcept
Returns true if the character is a letter (Letter_* categories); 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 right(qsizetype n) const
Returns a substring that contains the n rightmost characters of the string.
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.
qsizetype size() const
Returns the number of characters in this string.
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QChar * data()
Returns a pointer to the data stored in the QString.
QString sliced(qsizetype pos) const
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
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
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 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)