add Path::ext()
This commit is contained in:
1 parent
87c3abe0fa
commit
a1e9c30af2
3 files changed
+38
No files matched your search
@@ -15,6 +15,7 @@ namespace jes
|
||||
Path(const char * path);
|
||||
Path(const std::string & path);
|
||||
PathRef dirname();
|
||||
PathRef ext(const std::string & new_ext);
|
||||
PathRef join(const Path & other);
|
||||
const std::string & to_s() { return m_path; }
|
||||
bool exists();
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace jes
|
||||
|
||||
PathRef Path::dirname()
|
||||
{
|
||||
if (m_path.size() == 0)
|
||||
return new Path("");
|
||||
size_t i = m_path.size() - 1;
|
||||
while (m_path[i] == '/')
|
||||
{
|
||||
@@ -42,6 +44,30 @@ namespace jes
|
||||
return new Path(std::string(m_path, 0, i + 1));
|
||||
}
|
||||
|
||||
PathRef Path::ext(const std::string & new_ext)
|
||||
{
|
||||
if (m_path.size() == 0)
|
||||
return new Path("");
|
||||
size_t i = m_path.size() - 1;
|
||||
while (m_path[i] != '.')
|
||||
{
|
||||
if ((i == 0) || (m_path[i] == '/'))
|
||||
{
|
||||
i = m_path.size();
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
if (new_ext[0] == '.')
|
||||
{
|
||||
return new Path(std::string(m_path, 0, i) + new_ext);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Path(std::string(m_path, 0, i) + "." + new_ext);
|
||||
}
|
||||
}
|
||||
|
||||
PathRef Path::join(const Path & other)
|
||||
{
|
||||
if (m_path.size() > 0 && *m_path.rbegin() == '/')
|
||||
|
||||
Reference in new issue
Block a user