2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 15:44:56 +00:00

Add ProjectPath::getPathComponents()

This commit is contained in:
Jack Andersen
2016-01-06 11:03:41 -10:00
parent 68d0e5202a
commit 50f09bd20e
3 changed files with 73 additions and 2 deletions

2
hecl/extern/Athena vendored

Submodule hecl/extern/Athena updated: fddb684e26...7da7bd751d

2
hecl/extern/libBoo vendored

Submodule hecl/extern/libBoo updated: 939c0250be...c96f961c4d

View File

@@ -891,6 +891,77 @@ public:
return nullptr;
}
/**
* @brief Build vector of project-relative directory/file components
* @return Vector of path components
*/
std::vector<HECL::SystemString> getPathComponents() const
{
std::vector<HECL::SystemString> ret;
if (m_relPath.empty())
return ret;
auto it = m_relPath.cbegin();
if (*it == _S('/'))
{
ret.push_back(_S("/"));
++it;
}
HECL::SystemString comp;
for (; it != m_relPath.cend() ; ++it)
{
if (*it == _S('/'))
{
if (comp.empty())
continue;
ret.push_back(std::move(comp));
comp.clear();
continue;
}
comp += *it;
}
if (comp.size())
ret.push_back(std::move(comp));
return ret;
}
/**
* @brief Build vector of project-relative directory/file components
* @return Vector of path components encoded as UTF8
*/
std::vector<std::string> getPathComponentsUTF8() const
{
#if HECL_UCS2
const std::string& relPath = m_utf8RelPath;
#else
const std::string& relPath = m_relPath;
#endif
std::vector<std::string> ret;
if (relPath.empty())
return ret;
auto it = relPath.cbegin();
if (*it == '/')
{
ret.push_back(_S("/"));
++it;
}
std::string comp;
for (; it != relPath.cend() ; ++it)
{
if (*it == _S('/'))
{
if (comp.empty())
continue;
ret.push_back(std::move(comp));
comp.clear();
continue;
}
comp += *it;
}
if (comp.size())
ret.push_back(std::move(comp));
return ret;
}
/**
* @brief Access fully-canonicalized absolute path in UTF-8
* @return Absolute path reference