FileName: Fix isChildOf for some corner cases

empty directory has no children, and root directory was not handled correctly

Change-Id: I1936eab96aef0a3be462f705c60f1f26995be68b
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Orgad Shaneh
2012-10-04 06:06:09 +02:00
committed by Orgad Shaneh
parent c29123158a
commit 34354148db
2 changed files with 46 additions and 0 deletions

View File

@@ -526,10 +526,16 @@ bool FileName::operator>=(const FileName &other) const
/// \returns whether FileName is a child of \a s
bool FileName::isChildOf(const FileName &s) const
{
if (s.isEmpty())
return false;
if (!QString::startsWith(s, cs))
return false;
if (size() <= s.size())
return false;
// s is root, '/' was already tested in startsWith
if (s.QString::endsWith(QLatin1Char('/')))
return true;
// s is a directory, next character should be '/' (/tmpdir is NOT a child of /tmp)
return at(s.size()) == QLatin1Char('/');
}