summaryrefslogtreecommitdiff
path: root/plugingui/directory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'plugingui/directory.cc')
-rw-r--r--plugingui/directory.cc44
1 files changed, 28 insertions, 16 deletions
diff --git a/plugingui/directory.cc b/plugingui/directory.cc
index be5fad9..d25a367 100644
--- a/plugingui/directory.cc
+++ b/plugingui/directory.cc
@@ -92,22 +92,7 @@ std::string Directory::cleanPath(std::string path) {
WARN(directory, "Cleaning path '%s'\n", path.c_str());
Directory::Path pathlst = parsePath(path);
-
- std::string cleaned_path;
- DEBUG(directory, "Number of directories in path %d\n", pathlst.size());
-
- for(Directory::Path::iterator it = pathlst.begin();
- it != pathlst.end(); it++) {
- std::string dir = *it;
- DEBUG(directory, "\tDir '%s'\n", dir.c_str());
- cleaned_path += "/" + dir;
- }
-
- DEBUG(directory, "Cleaned path '%s'\n", cleaned_path.c_str());
-
- if(cleaned_path.empty()) cleaned_path = "/";
-
- return cleaned_path;
+ return Directory::pathToStr(pathlst);
}
Directory::EntryList Directory::listFiles(std::string path) {
@@ -234,6 +219,33 @@ Directory::Path Directory::parsePath(std::string path_str) {
return path;
}
+std::string Directory::pathToStr(Directory::Path& path) {
+ std::string cleaned_path;
+ DEBUG(directory, "Number of directories in path %d\n", path.size());
+
+ for(Directory::Path::iterator it = path.begin();
+ it != path.end(); it++) {
+ std::string dir = *it;
+ DEBUG(directory, "\tDir '%s'\n", dir.c_str());
+ cleaned_path += "/" + dir;
+ }
+
+ DEBUG(directory, "Cleaned path '%s'\n", cleaned_path.c_str());
+
+ if(cleaned_path.empty()) cleaned_path = "/";
+
+ return cleaned_path;
+}
+
+std::string Directory::pathDirectory(std::string filepath) {
+ if(Directory::isDir(filepath)) return filepath;
+
+ Directory::Path path = parsePath(filepath);
+ if(path.size() > 0) path.pop_back();
+
+ return Directory::pathToStr(path);
+}
+
#ifdef TEST_DIRECTORY
//Additional dependency files
//deps: