This commit is contained in:
Jack Andersen 2015-08-05 13:02:08 -10:00
commit b8391c7a5f
3 changed files with 48 additions and 8 deletions

View File

@ -122,6 +122,9 @@ inline std::string operator+(const char* lhs, const SystemStringView& rhs) {retu
typedef struct stat Sstat;
#endif
void SanitizePath(std::string& path);
void SanitizePath(std::wstring& path);
static inline void Unlink(const SystemChar* file)
{
#if _WIN32
@ -395,8 +398,12 @@ protected:
std::string m_utf8RelPath;
#endif
ProjectPath(const SystemString& projRoot)
: m_projRoot(projRoot), m_absPath(projRoot), m_relPath(_S(".")), m_hash(m_relPath)
: m_projRoot(projRoot), m_absPath(projRoot), m_relPath(_S("."))
{
SanitizePath(m_projRoot);
SanitizePath(m_relPath);
SanitizePath(m_absPath);
m_hash = Hash(m_relPath);
#if HECL_UCS2
m_utf8AbsPath = WideToUTF8(m_absPath);
m_utf8RelPath = ".";
@ -420,10 +427,10 @@ public:
* @param parentPath previously constructed ProjectPath which ultimately connects to a ProjectRootPath
* @param path valid filesystem-path (relative or absolute) to subpath
*/
ProjectPath(const ProjectPath& parentPath, const SystemString& path) {assign(parentPath, path);}
void assign(const ProjectPath& parentPath, const SystemString& path);
/* ProjectPath(const ProjectPath& parentPath, const SystemString& path) {assign(parentPath, path);}
void assign(const ProjectPath& parentPath, const SystemString& path);*/
#if HECL_UCS2
#ifndef HECL_UCS2
ProjectPath(const ProjectPath& parentPath, const std::string& path) {assign(parentPath, path);}
void assign(const ProjectPath& parentPath, const std::string& path);
#endif
@ -541,7 +548,6 @@ public:
relTarget += target.m_relPath;
MakeLink(relTarget.c_str(), m_absPath.c_str());
}
/**
* @brief HECL-specific blowfish hash
* @return unique hash value

View File

@ -3,4 +3,29 @@
namespace HECL
{
LogVisor::LogModule LogModule("HECL");
void SanitizePath(std::string& path)
{
path.erase(std::remove(path.begin(), path.end(), '\n'), path.end());
path.erase(std::remove(path.begin(), path.end(), '\r'), path.end());
std::transform(path.begin(), path.end(), path.begin(), [](const char a) -> char {
static const std::string illegals {"<>?*\"|"};
if (illegals.find_first_of(a) != std::string::npos)
return '_';
return a;
});
}
void SanitizePath(std::wstring& path)
{
path.erase(std::remove(path.begin(), path.end(), L'\n'), path.end());
path.erase(std::remove(path.begin(), path.end(), L'\r'), path.end());
std::transform(path.begin(), path.end(), path.begin(), [](const wchar_t a) -> wchar_t {
static const std::wstring illegals {L"<>?*\"|"};
if (illegals.find_first_of(a) != std::wstring::npos)
return L'_';
return a;
});
}
}

View File

@ -3,7 +3,6 @@
namespace HECL
{
static const SystemRegex regGLOB(_S("\\*"), SystemRegex::ECMAScript|SystemRegex::optimize);
static const SystemRegex regPATHCOMP(_S("[/\\\\]*([^/\\\\]+)"), SystemRegex::ECMAScript|SystemRegex::optimize);
static const SystemRegex regDRIVELETTER(_S("^([^/]*)/"), SystemRegex::ECMAScript|SystemRegex::optimize);
@ -21,6 +20,7 @@ static SystemString canonRelPath(const SystemString& path)
std::vector<SystemString> comps;
HECL::SystemRegexMatch matches;
SystemString in = path;
SanitizePath(in);
for (; std::regex_search(in, matches, regPATHCOMP) ; in = matches.suffix())
{
const SystemString& match = matches[1];
@ -57,10 +57,15 @@ static SystemString canonRelPath(const SystemString& path)
void ProjectPath::assign(const ProjectPath& parentPath, const SystemString& path)
{
SystemString in = path;
m_projRoot = parentPath.m_projRoot;
m_relPath = canonRelPath(parentPath.m_relPath + _S('/') + path);
m_relPath = canonRelPath(parentPath.m_relPath + _S('/') + in);
m_absPath = parentPath.m_projRoot + _S('/') + m_relPath;
SanitizePath(m_projRoot);
SanitizePath(m_relPath);
SanitizePath(m_absPath);
m_hash = Hash(m_relPath);
#if HECL_UCS2
m_utf8AbsPath = WideToUTF8(m_absPath);
m_utf8RelPath = WideToUTF8(m_relPath);
@ -70,10 +75,14 @@ void ProjectPath::assign(const ProjectPath& parentPath, const SystemString& path
#if HECL_UCS2
void ProjectPath::assign(const ProjectPath& parentPath, const std::string& path)
{
std::string in = path;
m_projRoot = parentPath.m_projRoot;
std::wstring wpath = UTF8ToWide(path);
std::wstring wpath = UTF8ToWide(in);
m_relPath = canonRelPath(parentPath.m_relPath + _S('/') + wpath);
m_absPath = parentPath.m_projRoot + _S('/') + m_relPath;
SanitizePath(m_projRoot);
SanitizePath(m_relPath);
SanitizePath(m_absPath);
m_hash = Hash(m_relPath);
m_utf8AbsPath = WideToUTF8(m_absPath);
m_utf8RelPath = WideToUTF8(m_relPath);