Changeset View
Changeset View
Standalone View
Standalone View
src/utils/directoryfindchilditem.cpp
- This file was added.
1 | #include <QtCore/QString> | ||||
---|---|---|---|---|---|
2 | #include <QtCore/QUrl> | ||||
3 | #include <QtCore/QDir> | ||||
4 | #include "directoryfindchilditem.h" | ||||
5 | | ||||
6 | /** | ||||
7 | * Returns the item which is located in directory in the argument | ||||
8 | * when filename is an item located in directory or one of its children. | ||||
9 | * Returns an empty QUrl when that is not the case | ||||
10 | * | ||||
11 | * @param directory | ||||
12 | * @param filename | ||||
13 | * @return | ||||
14 | */ | ||||
15 | QUrl directoryFindChildItem(const QUrl& directory, const QUrl& filename) | ||||
16 | { | ||||
17 | const QString dirStr = directory.adjusted(QUrl::StripTrailingSlash).toString(); | ||||
18 | const QString urlStr = filename.toString(); | ||||
19 | const int dirLen = dirStr.length() + 1; | ||||
20 | | ||||
21 | if (!urlStr.startsWith(dirStr)) { | ||||
22 | return QUrl(); | ||||
23 | } | ||||
24 | | ||||
25 | return QUrl(QStringLiteral("%1/%2").arg( | ||||
26 | dirStr, urlStr.mid(dirLen, urlStr.indexOf(QDir::separator(), dirLen + 1) - dirLen))); | ||||
27 | } | ||||
28 | No newline at end of file |