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

@ -1 +1 @@
Subproject commit fddb684e260dd4b84f166e80d7f86f2d19ba7533
Subproject commit 7da7bd751d1fbfee35fabc806db6cdb6176b87e7

2
hecl/extern/libBoo vendored

@ -1 +1 @@
Subproject commit 939c0250beea32d6806a2813af3273796e4cd82a
Subproject commit c96f961c4d67945cf684a31b744ebf82462ebf44

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