diff options
Diffstat (limited to 'libs/pbd')
-rw-r--r-- | libs/pbd/pathexpand.cc | 30 | ||||
-rw-r--r-- | libs/pbd/pbd/pathexpand.h | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/libs/pbd/pathexpand.cc b/libs/pbd/pathexpand.cc index 3398bd1152..e9bef4c4aa 100644 --- a/libs/pbd/pathexpand.cc +++ b/libs/pbd/pathexpand.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Paul Davis + Copyright (C) 2013-2014 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,10 +25,12 @@ #include <regex.h> +#include <glibmm/fileutils.h> #include <glibmm/miscutils.h> #include "pbd/pathexpand.h" #include "pbd/strsplit.h" +#include "pbd/tokenizer.h" using std::string; using std::vector; @@ -192,3 +194,29 @@ PBD::search_path_expand (string path) return r; } + +std::vector <std::string> +PBD::parse_path(std::string path, bool check_if_exists) +{ + vector <std::string> pathlist; + vector <std::string> tmp; + PBD::tokenize (path, string(G_SEARCHPATH_SEPARATOR_S), std::back_inserter (tmp)); + + for(vector<std::string>::const_iterator i = tmp.begin(); i != tmp.end(); ++i) { + if ((*i).empty()) continue; + std::string dir; +#ifndef PLATFORM_WINDOWS + if ((*i).substr(0,1) == "~") { + dir = Glib::build_filename(Glib::get_home_dir(), (*i).substr(1)); + } + else +#endif + { + dir = *i; + } + if (!check_if_exists || Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) { + pathlist.push_back(dir); + } + } + return pathlist; +} diff --git a/libs/pbd/pbd/pathexpand.h b/libs/pbd/pbd/pathexpand.h index 5c5d4cf772..b7a0779d5e 100644 --- a/libs/pbd/pbd/pathexpand.h +++ b/libs/pbd/pbd/pathexpand.h @@ -20,6 +20,7 @@ #define __libpbd_path_expand_h__ #include <string> +#include <vector> #include "pbd/libpbd_visibility.h" @@ -27,6 +28,7 @@ namespace PBD { LIBPBD_API std::string canonical_path (const std::string& path); LIBPBD_API std::string path_expand (std::string path); LIBPBD_API std::string search_path_expand (std::string path); + LIBPBD_API std::vector<std::string> parse_path(std::string path, bool check_if_exists = false); } #endif /* __libpbd_path_expand_h__ */ |