[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/kdepim/enterprise4/kdelibs-4.0.83/kdecore/kernel
From: Jaroslaw Staniek <js () iidea ! pl>
Date: 2008-07-09 13:02:25
Message-ID: 1215608545.623622.6801.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 829970 by staniek:
KStandardDirs: one crash fix + code cleanups
Important fix:
- Windows: avoid crash in KStandardDirs::exists(fullPath) for empty fullPath
Minor cleanups:
- KStandardDirs::addResourceDir(): check for empty absdir or type
- use more constness
- lookupPrefix(): do not check for relpath.isEmpty() twice
- replace checking for (bool)filter.length() with !filter.isEmpty()
- use QString::isEmpty() instead of isNull()
- use default value of 2nd arg for QString::mid()
backport from r829968 trunk
(reviewed)
M +20 -19 kstandarddirs.cpp
--- branches/kdepim/enterprise4/kdelibs-4.0.83/kdecore/kernel/kstandarddirs.cpp \
#829969:829970 @@ -393,12 +393,14 @@
const QString& absdir,
bool priority)
{
+ if (absdir.isEmpty() || !type)
+ return false;
// find or insert entry in the map
- QStringList &paths = d->absolutes[type];
QString copy = absdir;
if (copy.at(copy.length() - 1) != '/')
copy += '/';
+ QStringList &paths = d->absolutes[type];
if (!paths.contains(copy)) {
if (priority)
paths.prepend(copy);
@@ -554,13 +556,13 @@
// access() and stat() give a stupid error message to the user
// if the path is not accessible at all (e.g. no disk in A:/ and
// we do stat("A:/.directory")
- if(fullPath.at(fullPath.length() - 1) == '/')
+ if (fullPath.endsWith('/'))
return QDir(fullPath).exists();
return QFileInfo(fullPath).exists();
#else
KDE_struct_stat buff;
if (access(QFile::encodeName(fullPath), R_OK) == 0 && KDE_stat( \
QFile::encodeName(fullPath), &buff ) == 0) {
- if (fullPath.at(fullPath.length() - 1) != '/') {
+ if (!fullPath.endsWith('/')) {
if (S_ISREG( buff.st_mode ))
return true;
} else
@@ -577,7 +579,7 @@
QStringList& relList,
bool recursive, bool unique)
{
- QString pattern = regexp.pattern();
+ const QString pattern = regexp.pattern();
if (recursive || pattern.contains('?') || pattern.contains('*'))
{
if (path.isEmpty()) //for sanity
@@ -678,15 +680,12 @@
QString path;
QString rest;
- if (relpath.length())
- {
- int slash = relpath.indexOf('/');
- if (slash < 0)
- rest = relpath.left(relpath.length() - 1);
- else {
- path = relpath.left(slash);
- rest = relpath.mid(slash + 1);
- }
+ int slash = relpath.indexOf('/');
+ if (slash < 0)
+ rest = relpath.left(relpath.length() - 1);
+ else {
+ path = relpath.left(slash);
+ rest = relpath.mid(slash + 1);
}
if (prefix.isEmpty()) //for sanity
@@ -753,11 +752,10 @@
SearchOptions options,
QStringList &relList) const
{
- QStringList list;
QString filterPath;
QString filterFile;
- if ( filter.length() )
+ if ( !filter.isEmpty() )
{
int slash = filter.lastIndexOf('/');
if (slash < 0) {
@@ -793,6 +791,7 @@
QRegExp regExp(filterFile, Qt::CaseSensitive, QRegExp::Wildcard);
+ QStringList list;
foreach ( const QString& candidate, candidates )
{
lookupPrefix(candidate, filterPath, "", regExp, list,
@@ -831,6 +830,8 @@
return QFile::decodeName(realpath_buffer);
}
+ if ( !dirname.endsWith('/') )
+ return dirname + '/';
return dirname;
}
@@ -1069,7 +1070,7 @@
QStringList tokens;
QString p = pstr;
- if( p.isNull() )
+ if( p.isEmpty() )
{
p = QString::fromLocal8Bit( qgetenv( "PATH" ) );
}
@@ -1259,7 +1260,7 @@
token += str[ index ];
}
}
- if ( token.length() > 0 )
+ if ( !token.isEmpty() )
{
tokens.append( equalizePath(token) );
}
@@ -1572,7 +1573,7 @@
for (QStringList::ConstIterator it = kdedirList.begin();
it != kdedirList.end(); ++it) {
QString dir = *it;
- if (dir.length() < 1 || dir[dir.length()-1] != '/')
+ if (!dir.endsWith('/'))
dir += '/';
kdedirDataDirs.append(dir+"share/");
}
@@ -1779,7 +1780,7 @@
// generate directory list, there may be more than 1.
QStringList dirs = (*it2).split(',');
QStringList::Iterator sIt(dirs.begin());
- QString resType = key.mid(4, key.length());
+ QString resType = key.mid(4);
for (; sIt != dirs.end(); ++sIt)
{
addResourceDir(resType.toLatin1(), *sIt, priority);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic