summaryrefslogtreecommitdiff
path: root/tools/minicargo/path.h
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-08-30 21:08:51 +0800
committerJohn Hodge <tpg@mutabah.net>2017-08-31 16:31:24 +0800
commit5dce4fe24f29818b250eda177c68da5e2c7ee487 (patch)
tree5293dec3a5d154634ae211fe60997afd4bbccd67 /tools/minicargo/path.h
parent4e9adae0c15e163290426db1c7d1956abc4c56f5 (diff)
downloadmrust-5dce4fe24f29818b250eda177c68da5e2c7ee487.tar.gz
minicargo - Build scripts working (mostly)
Diffstat (limited to 'tools/minicargo/path.h')
-rw-r--r--tools/minicargo/path.h55
1 files changed, 45 insertions, 10 deletions
diff --git a/tools/minicargo/path.h b/tools/minicargo/path.h
index 54cb8f40..833fe90a 100644
--- a/tools/minicargo/path.h
+++ b/tools/minicargo/path.h
@@ -31,26 +31,45 @@ public:
return m_str != "";
}
- path operator/(const path& p) const
+ path& operator/=(const path& p)
{
- if(!this->is_valid())
- throw ::std::runtime_error("Appending to an invalid path");
if(!p.is_valid())
throw ::std::runtime_error("Appending from an invalid path");
- if(p.m_str[0] == '/')
+
+ return *this /= p.m_str.c_str();
+ }
+ path& operator/=(const char* o)
+ {
+ if(!this->is_valid())
+ throw ::std::runtime_error("Appending to an invalid path");
+ if(o[0] == '/')
throw ::std::runtime_error("Appending an absolute path to another path");
- return *this / p.m_str.c_str();
+ this->m_str.push_back(SEP);
+ this->m_str.append(o);
+ return *this;
}
- /// Append a relative path
- path operator/(const char* o) const
+ path& operator/=(const string_view& o)
{
if(!this->is_valid())
throw ::std::runtime_error("Appending to an invalid path");
- if (o[0] == '/')
+ if(o[0] == '/')
throw ::std::runtime_error("Appending an absolute path to another path");
+ this->m_str.push_back(SEP);
+ this->m_str += o;
+ return *this;
+ }
+
+ path operator/(const path& p) const
+ {
auto rv = *this;
- rv.m_str.push_back(SEP);
- rv.m_str.append(o);
+ rv /= p;
+ return rv;
+ }
+ /// Append a relative path
+ path operator/(const char* o) const
+ {
+ auto rv = *this;
+ rv /= o;
return rv;
}
/// Add an arbitary string to the final component
@@ -65,6 +84,21 @@ public:
return rv;
}
+ bool pop_component()
+ {
+ if(!this->is_valid())
+ throw ::std::runtime_error("Calling pop_component() on an invalid path");
+ auto pos = m_str.find_last_of(SEP);
+ if(pos == ::std::string::npos || pos == 0)
+ {
+ return false;
+ }
+ else
+ {
+ this->m_str.resize(pos);
+ return true;
+ }
+ }
path parent() const
{
if(!this->is_valid())
@@ -81,6 +115,7 @@ public:
return rv;
}
}
+ path to_absolute() const;
const ::std::string& str() const
{