Expand "~/" in paths to $HOME/

This commit is contained in:
josh committed 2018-03-20 22:07:40 -04:00
1 parent d93953a929
commit ec6d0eb8b7
3 files changed
+17 -1

No files matched your search

+14
View File
@@ -73,3 +73,17 @@ std::shared_ptr<std::vector<std::shared_ptr<std::string>>> Path::listdir(const s
return result;
}
std::string Path::clean(const std::string & s)
{
std::string p = s;
if (p.substr(0, 2) == "~/")
{
char * home = getenv("HOME");
if (home != nullptr)
{
p = home + p.substr(1, p.size());
}
}
return p;
}
+1
View File
@@ -19,6 +19,7 @@ public:
static bool is_file(const std::string & s);
static bool is_dir(const std::string & s);
static std::shared_ptr<std::vector<std::shared_ptr<std::string>>> listdir(const std::string & path);
static std::string clean(const std::string & s);
protected:
static std::string _join(const std::string & first, const std::string & second);