Qt 4.8
Classes | Public Types | Public Functions | Private Functions | Properties | List of all members
QFileSystemEntry Class Reference

#include <qfilesystementry_p.h>

Classes

struct  FromInternalPath
 
struct  FromNativePath
 

Public Types

typedef QString NativePath
 

Public Functions

QString baseName () const
 
void clear ()
 
QString completeBaseName () const
 
QString completeSuffix () const
 
QString fileName () const
 
QString filePath () const
 
bool isAbsolute () const
 
bool isClean () const
 
bool isDriveRoot () const
 
bool isEmpty () const
 
bool isRelative () const
 
bool isRoot () const
 
NativePath nativeFilePath () const
 
QString path () const
 
 QFileSystemEntry ()
 
 QFileSystemEntry (const QString &filePath)
 Use this constructor when the path is supplied by user code, as it may contain a mix of '/' and the native separator. More...
 
 QFileSystemEntry (const QString &filePath, FromInternalPath dummy)
 Use this constructor when the path is guaranteed to be in internal format, i. More...
 
 QFileSystemEntry (const NativePath &nativeFilePath, FromNativePath dummy)
 
 QFileSystemEntry (const QString &filePath, const NativePath &nativeFilePath)
 
QString suffix () const
 

Private Functions

void findFileNameSeparators () const
 
void findLastSeparator () const
 
void resolveFilePath () const
 
void resolveNativeFilePath () const
 

Properties

QString m_filePath
 
qint16 m_firstDotInFileName
 
qint16 m_lastDotInFileName
 
qint16 m_lastSeparator
 
NativePath m_nativeFilePath
 

Detailed Description

Definition at line 65 of file qfilesystementry_p.h.

Typedefs

◆ NativePath

Definition at line 72 of file qfilesystementry_p.h.

Constructors and Destructors

◆ QFileSystemEntry() [1/5]

QFileSystemEntry::QFileSystemEntry ( )

Definition at line 77 of file qfilesystementry.cpp.

Referenced by clear().

78  : m_lastSeparator(0),
81 {
82 }

◆ QFileSystemEntry() [2/5]

QFileSystemEntry::QFileSystemEntry ( const QString filePath)
explicit

Use this constructor when the path is supplied by user code, as it may contain a mix of '/' and the native separator.

Warning
This function is not part of the public interface.

Definition at line 92 of file qfilesystementry.cpp.

94  m_lastSeparator(-2),
97 {
98 }
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using &#39;/&#39; as file separator.
Definition: qdir.cpp:848

◆ QFileSystemEntry() [3/5]

QFileSystemEntry::QFileSystemEntry ( const QString filePath,
FromInternalPath  dummy 
)

Use this constructor when the path is guaranteed to be in internal format, i.

Warning
This function is not part of the public interface. e. all directory separators are '/' and not the native separator.

Definition at line 108 of file qfilesystementry.cpp.

109  : m_filePath(filePath),
110  m_lastSeparator(-2),
113 {
114 }

◆ QFileSystemEntry() [4/5]

QFileSystemEntry::QFileSystemEntry ( const NativePath nativeFilePath,
FromNativePath  dummy 
)
Warning
This function is not part of the public interface. Use this constructor when the path comes from a native API

Definition at line 120 of file qfilesystementry.cpp.

122  m_lastSeparator(-2),
125 {
126 }
NativePath nativeFilePath() const
NativePath m_nativeFilePath

◆ QFileSystemEntry() [5/5]

QFileSystemEntry::QFileSystemEntry ( const QString filePath,
const NativePath nativeFilePath 
)

Definition at line 128 of file qfilesystementry.cpp.

131  m_lastSeparator(-2),
134 {
135 }
NativePath nativeFilePath() const
NativePath m_nativeFilePath
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using &#39;/&#39; as file separator.
Definition: qdir.cpp:848

Functions

◆ baseName()

QString QFileSystemEntry::baseName ( ) const

Definition at line 211 of file qfilesystementry.cpp.

212 {
214  int length = -1;
215  if (m_firstDotInFileName >= 0) {
216  length = m_firstDotInFileName;
217  if (m_lastSeparator != -1) // avoid off by one
218  length--;
219  }
220 #if defined(Q_OS_WIN)
221  if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
222  return m_filePath.mid(2, length - 2);
223 #endif
224  return m_filePath.mid(m_lastSeparator + 1, length);
225 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void findFileNameSeparators() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ clear()

void QFileSystemEntry::clear ( )
inline

Definition at line 102 of file qfilesystementry_p.h.

103  {
104  *this = QFileSystemEntry();
105  }

◆ completeBaseName()

QString QFileSystemEntry::completeBaseName ( ) const

Definition at line 227 of file qfilesystementry.cpp.

Referenced by QLibraryPrivate::load_sys().

228 {
230  int length = -1;
231  if (m_firstDotInFileName >= 0) {
233  if (m_lastSeparator != -1) // avoid off by one
234  length--;
235  }
236 #if defined(Q_OS_WIN)
237  if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
238  return m_filePath.mid(2, length - 2);
239 #endif
240  return m_filePath.mid(m_lastSeparator + 1, length);
241 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void findFileNameSeparators() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ completeSuffix()

QString QFileSystemEntry::completeSuffix ( ) const

Definition at line 253 of file qfilesystementry.cpp.

254 {
256  if (m_firstDotInFileName == -1)
257  return QString();
258 
260 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
short qint16
Definition: qglobal.h:935
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void findFileNameSeparators() const

◆ fileName()

QString QFileSystemEntry::fileName ( ) const

Definition at line 182 of file qfilesystementry.cpp.

Referenced by QDirIteratorPrivate::advance(), QDir::dirName(), QFileSystemEngine::fillMetaData(), and QLibraryPrivate::load_sys().

183 {
185 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
186  if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
187  return m_filePath.mid(2);
188 #endif
189  return m_filePath.mid(m_lastSeparator + 1);
190 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void findLastSeparator() const
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ filePath()

QString QFileSystemEntry::filePath ( ) const

◆ findFileNameSeparators()

void QFileSystemEntry::findFileNameSeparators ( ) const
private

Definition at line 341 of file qfilesystementry.cpp.

Referenced by baseName(), clear(), completeBaseName(), completeSuffix(), and suffix().

342 {
343  if (m_firstDotInFileName == -2) {
344  resolveFilePath();
345  int firstDotInFileName = -1;
346  int lastDotInFileName = -1;
347  int lastSeparator = m_lastSeparator;
348 
349  int stop;
350  if (lastSeparator < 0) {
351  lastSeparator = -1;
352  stop = 0;
353  } else {
354  stop = lastSeparator;
355  }
356 
357  int i = m_filePath.size() - 1;
358  for (; i >= stop; --i) {
359  if (m_filePath[i].unicode() == '.') {
360  firstDotInFileName = lastDotInFileName = i;
361  break;
362  } else if (m_filePath[i].unicode() == '/') {
363  lastSeparator = i;
364  break;
365  }
366  }
367 
368  if (lastSeparator != i) {
369  for (--i; i >= stop; --i) {
370  if (m_filePath[i].unicode() == '.')
371  firstDotInFileName = i;
372  else if (m_filePath[i].unicode() == '/') {
373  lastSeparator = i;
374  break;
375  }
376  }
377  }
378  m_lastSeparator = lastSeparator;
379  m_firstDotInFileName = firstDotInFileName == -1 ? -1 : firstDotInFileName - qMax(0, lastSeparator);
380  if (lastDotInFileName == -1)
381  m_lastDotInFileName = -1;
382  else if (firstDotInFileName == lastDotInFileName)
384  else
385  m_lastDotInFileName = lastDotInFileName - firstDotInFileName;
386  }
387 }
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
void resolveFilePath() const

◆ findLastSeparator()

void QFileSystemEntry::findLastSeparator ( ) const
private

Definition at line 327 of file qfilesystementry.cpp.

Referenced by clear(), fileName(), and path().

328 {
329  if (m_lastSeparator == -2) {
330  resolveFilePath();
331  m_lastSeparator = -1;
332  for (int i = m_filePath.size() - 1; i >= 0; --i) {
333  if (m_filePath[i].unicode() == '/') {
334  m_lastSeparator = i;
335  break;
336  }
337  }
338  }
339 }
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
void resolveFilePath() const

◆ isAbsolute()

bool QFileSystemEntry::isAbsolute ( ) const

Definition at line 270 of file qfilesystementry.cpp.

Referenced by QFileSystemEngine::absoluteName(), QLibraryPrivate::load_sys(), and QFileSystemEngine::nativeAbsoluteFilePath().

271 {
272  resolveFilePath();
273  return (!m_filePath.isEmpty() && ((m_filePath.length() >= 3
274  && (m_filePath[0].isLetter() && m_filePath[1].unicode() == ':' && m_filePath[2].unicode() == '/'))
275 #ifdef Q_OS_WIN
276  || (m_filePath.length() >= 2 && (m_filePath.at(0) == QLatin1Char('/') && m_filePath.at(1) == QLatin1Char('/')))
277 #endif
278  ));
279 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void resolveFilePath() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isClean()

bool QFileSystemEntry::isClean ( ) const

Definition at line 389 of file qfilesystementry.cpp.

Referenced by QFileSystemEngine::absoluteName(), QFileSystemEngine::nativeAbsoluteFilePath(), and QDirPrivate::resolveAbsoluteEntry().

390 {
391  resolveFilePath();
392  int dots = 0;
393  bool dotok = true; // checking for ".." or "." starts to relative paths
394  bool slashok = true;
395  for (QString::const_iterator iter = m_filePath.constBegin(); iter != m_filePath.constEnd(); iter++) {
396  if (*iter == QLatin1Char('/')) {
397  if (dots == 1 || dots == 2)
398  return false; // path contains "./" or "../"
399  if (!slashok)
400  return false; // path contains "//"
401  dots = 0;
402  dotok = true;
403  slashok = false;
404  } else if (dotok) {
405  slashok = true;
406  if (*iter == QLatin1Char('.')) {
407  dots++;
408  if (dots > 2)
409  dotok = false;
410  } else {
411  //path element contains a character other than '.', it's clean
412  dots = 0;
413  dotok = false;
414  }
415  }
416  }
417  return (dots != 1 && dots != 2); // clean if path doesn't end in . or ..
418 }
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first character in the string. ...
Definition: qstring.h:892
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qstring.h:898
void resolveFilePath() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isDriveRoot()

bool QFileSystemEntry::isDriveRoot ( ) const

Definition at line 294 of file qfilesystementry.cpp.

Referenced by QFileSystemEngine::fillMetaData(), isRoot(), tryDriveUNCFallback(), and tryFindFallback().

295 {
296  resolveFilePath();
297  return (m_filePath.length() == 3
298  && m_filePath.at(0).isLetter() && m_filePath.at(1) == QLatin1Char(':')
299  && m_filePath.at(2) == QLatin1Char('/'));
300 }
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
Definition: qchar.cpp:653
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void resolveFilePath() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isEmpty()

bool QFileSystemEntry::isEmpty ( ) const

Definition at line 319 of file qfilesystementry.cpp.

Referenced by QFileSystemEngine::canonicalName(), QFileSystemEngine::currentPath(), QFSFileEnginePrivate::doStat(), QFileSystemEngine::fillMetaData(), QFSFileEnginePrivate::longFileName(), openModeToFopenMode(), and QDirPrivate::resolveAbsoluteEntry().

320 {
322  return m_nativeFilePath.isEmpty();
323 }
void resolveNativeFilePath() const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
NativePath m_nativeFilePath

◆ isRelative()

bool QFileSystemEntry::isRelative ( ) const

Definition at line 263 of file qfilesystementry.cpp.

Referenced by isAbsolute(), QDir::isRelative(), QFileInfo::makeAbsolute(), QFileSystemEngine::nativeAbsoluteFilePath(), QDirPrivate::resolveAbsoluteEntry(), and resolveNativeFilePath().

264 {
265  resolveFilePath();
266  return (m_filePath.isEmpty() || (!m_filePath.isEmpty() && (m_filePath[0].unicode() != '/')
267  && (!(m_filePath.length() >= 2 && m_filePath[1].unicode() == ':'))));
268 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void resolveFilePath() const

◆ isRoot()

bool QFileSystemEntry::isRoot ( ) const

Definition at line 303 of file qfilesystementry.cpp.

Referenced by QDir::absoluteFilePath(), QFileSystemEngine::canonicalName(), and QDir::isRoot().

304 {
305  resolveFilePath();
306  if (m_filePath == QLatin1String("/")
307 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
308  || isDriveRoot()
309 #if defined(Q_OS_WIN)
311 #endif
312 #endif
313  )
314  return true;
315 
316  return false;
317 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool isUncRoot(const QString &server)
bool isDriveRoot() const
#define Q_OS_WIN
Definition: qglobal.h:270
void resolveFilePath() const

◆ nativeFilePath()

QFileSystemEntry::NativePath QFileSystemEntry::nativeFilePath ( ) const

◆ path()

QString QFileSystemEntry::path ( ) const

Definition at line 192 of file qfilesystementry.cpp.

Referenced by QFSFileEngine::fileName(), QFileInfoPrivate::getFileName(), QLibraryPrivate::load_sys(), and QFSFileEnginePrivate::longFileName().

193 {
195  if (m_lastSeparator == -1) {
196 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
197  if (m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
198  return m_filePath.left(2);
199 #endif
200  return QString(QLatin1Char('.'));
201  }
202  if (m_lastSeparator == 0)
203  return QString(QLatin1Char('/'));
204 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
205  if (m_lastSeparator == 2 && m_filePath.at(1) == QLatin1Char(':'))
206  return m_filePath.left(m_lastSeparator + 1);
207 #endif
209 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void findLastSeparator() const
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ resolveFilePath()

void QFileSystemEntry::resolveFilePath ( ) const
private

Definition at line 149 of file qfilesystementry.cpp.

Referenced by clear(), filePath(), findFileNameSeparators(), findLastSeparator(), isAbsolute(), isClean(), isDriveRoot(), isRelative(), and isRoot().

150 {
152 #if defined(QFILESYSTEMENTRY_NATIVE_PATH_IS_UTF16)
154 #ifdef Q_OS_WIN
155  if (m_filePath.startsWith(QLatin1String("//?/UNC/")))
157  if (m_filePath.startsWith(QLatin1String("//?/")))
159 #endif
160 #else
162 #endif
163  }
164 }
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
NativePath m_nativeFilePath
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using &#39;/&#39; as file separator.
Definition: qdir.cpp:848
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867

◆ resolveNativeFilePath()

void QFileSystemEntry::resolveNativeFilePath ( ) const
private

Definition at line 166 of file qfilesystementry.cpp.

Referenced by clear(), isEmpty(), and nativeFilePath().

167 {
169 #ifdef Q_OS_WIN
171  if (isRelative())
172  filePath = fixIfRelativeUncPath(m_filePath);
174 #elif defined(QFILESYSTEMENTRY_NATIVE_PATH_IS_UTF16)
176 #else
178 #endif
179  }
180 }
static QString fixIfRelativeUncPath(const QString &path)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString longFileName(const QString &path)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
NativePath m_nativeFilePath
QString filePath() const
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
bool isRelative() const
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812

◆ suffix()

QString QFileSystemEntry::suffix ( ) const

Definition at line 243 of file qfilesystementry.cpp.

Referenced by QLibraryPrivate::load_sys().

244 {
246 
247  if (m_lastDotInFileName == -1)
248  return QString();
249 
251 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
short qint16
Definition: qglobal.h:935
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void findFileNameSeparators() const

Properties

◆ m_filePath

QString QFileSystemEntry::m_filePath
mutableprivate

◆ m_firstDotInFileName

qint16 QFileSystemEntry::m_firstDotInFileName
mutableprivate

◆ m_lastDotInFileName

qint16 QFileSystemEntry::m_lastDotInFileName
mutableprivate

Definition at line 122 of file qfilesystementry_p.h.

Referenced by completeBaseName(), findFileNameSeparators(), and suffix().

◆ m_lastSeparator

qint16 QFileSystemEntry::m_lastSeparator
mutableprivate

◆ m_nativeFilePath

NativePath QFileSystemEntry::m_nativeFilePath
mutableprivate

The documentation for this class was generated from the following files: