[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: 'lightweight' QDir::isAbsolutePath replacement ?
From:       Ralf Habacker <ralf.habacker () freenet ! de>
Date:       2008-03-10 19:20:42
Message-ID: 47D58A0A.2000707 () freenet ! de
[Download RAW message or body]

Thiago Macieira schrieb:
> Ralf Habacker wrote:
>   
>> But - now the main question - is anyone from the trolltech devs here who
>> can ensure that such a patch would be accepted ?
>>     
>
> Yes.
>
> Everybody laughed at lunch when I explained the number of classes it had 
> to go through just to do some string comparisons (on Unix, to look at the 
> first character).
>
> Depending on the size of the patch, I'll push it to Qt 4.4.
>
>   
The patch is appended. It adds 
static bool QFileInfo::isAbsolute(const QString &path);
static bool QFileInfo::isRelative(const QString &path);

and fixes
static bool QDir::isAbsolutePath(const QString &path);
static bool QDir::isRelativePath(const QString &path);

all the above mentioned methods are based on
static bool QFSFileEngine:isAbsolutePath(const QString &path);
static bool QFSFileEngine::isRelative(const QString &path);

which makes the internal string compare functions accesable

PS: I have not thoughed the non static related member methods

Regards
Ralf



["qt-corelib-isAbsolutePath.patch" (text/plain)]

Index: corelib/io/qdir.cpp
===================================================================
--- corelib/io/qdir.cpp	(revision 783508)
+++ corelib/io/qdir.cpp	(working copy)
@@ -2160,7 +2160,7 @@
 
 bool QDir::isRelativePath(const QString &path)
 {
-    return QFileInfo(path).isRelative();
+    return QFSFileEngine::isRelativePath(path);
 }
 
 /*!
Index: corelib/io/qfileinfo.cpp
===================================================================
--- corelib/io/qfileinfo.cpp	(revision 783508)
+++ corelib/io/qfileinfo.cpp	(working copy)
@@ -706,7 +706,18 @@
     return d->data->fileEngine->isRelativePath();
 }
 
+/*!
+    Returns true if \a path is relative; returns false if it is
+    absolute.
 
+    \sa isAbsolute()
+*/
+
+bool QFileInfo::isRelative(const QString &path)
+{
+    return QFSFileEngine::isRelativePath(path);
+}
+
 /*!
     Converts the file's path to an absolute path if it is not already in that form.
     Returns true to indicate that the path was converted; otherwise returns false
Index: corelib/io/qfileinfo.h
===================================================================
--- corelib/io/qfileinfo.h	(revision 783508)
+++ corelib/io/qfileinfo.h	(working copy)
@@ -132,6 +132,9 @@
     bool caching() const;
     void setCaching(bool on);
 
+    static bool isRelative(const QString &path);
+    static inline bool isAbsolute(const QString &path) { return !isRelative(path); }
+
 #ifdef QT3_SUPPORT
     enum Permission {
         ReadOwner = QFile::ReadOwner, WriteOwner = QFile::WriteOwner, ExeOwner = \
                QFile::ExeOwner,
Index: corelib/io/qfsfileengine.h
===================================================================
--- corelib/io/qfsfileengine.h	(revision 783508)
+++ corelib/io/qfsfileengine.h	(working copy)
@@ -107,7 +107,8 @@
     static QString rootPath();
     static QString tempPath();
     static QFileInfoList drives();
-
+    static bool isRelativePath(const QString &path);
+    static inline bool isAbsolutePath(const QString &path) { return \
!isRelativePath(path); }  protected:
     QFSFileEngine(QFSFileEnginePrivate &dd);
 };
Index: corelib/io/qfsfileengine_unix.cpp
===================================================================
--- corelib/io/qfsfileengine_unix.cpp	(revision 783508)
+++ corelib/io/qfsfileengine_unix.cpp	(working copy)
@@ -825,6 +825,13 @@
     return d->filePath[0] != QLatin1Char('/');
 }
 
+bool QFSFileEngine::isRelativePath(const QString &path)
+{
+    if (path.size() == 0)
+        return true;
+    return path[0] != QLatin1Char('/');
+}
+
 uint QFSFileEngine::ownerId(FileOwner own) const
 {
     Q_D(const QFSFileEngine);
Index: corelib/io/qfsfileengine_win.cpp
===================================================================
--- corelib/io/qfsfileengine_win.cpp	(revision 783508)
+++ corelib/io/qfsfileengine_win.cpp	(working copy)
@@ -1933,6 +1933,14 @@
         || (d->filePath.at(0) == QLatin1Char('/') && d->filePath.at(1) == \
QLatin1Char('/')))));                // drive, e.g. a:  }
 
+bool QFSFileEngine::isRelativePath(const QString &path)
+{
+    return !(path.startsWith(QLatin1Char('/'))
+           || path.startsWith(QLatin1Char('\\'))
+           || (path.length() >= 2 &&
+            ( (path.at(0).isLetter() && path.at(1) == QLatin1Char(':')))));
+}
+
 /*!
     \reimp
 */



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic