From 1f3ac3805e8af32440620700c21bbabe01e4044f Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 10 Nov 2015 17:40:13 -1000 Subject: [PATCH] Win32 unicode-escape fix (all paths now sanitized with '/') --- hecl/lib/HECL.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hecl/lib/HECL.cpp b/hecl/lib/HECL.cpp index f61434306..18ad533ed 100644 --- a/hecl/lib/HECL.cpp +++ b/hecl/lib/HECL.cpp @@ -7,24 +7,36 @@ LogVisor::LogModule LogModule("HECL"); void SanitizePath(std::string& path) { + if (path.empty()) + return; 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 { + std::string::iterator p1 = path.begin(); + std::transform(path.begin(), path.end(), path.begin(), [&](const char a) -> char { + ++p1; static const std::string illegals {"<>?*\"|"}; if (illegals.find_first_of(a) != std::string::npos) return '_'; + if (a == '\\' && (p1 == path.end() || *p1 != '\\')) + return '/'; return a; }); } void SanitizePath(std::wstring& path) { + if (path.empty()) + return; 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 { + std::wstring::iterator p1 = path.begin(); + std::transform(path.begin(), path.end(), path.begin(), [&](const wchar_t a) -> wchar_t { + ++p1; static const std::wstring illegals {L"<>?*\"|"}; if (illegals.find_first_of(a) != std::wstring::npos) return L'_'; + if (a == L'\\' && (p1 == path.end() || *p1 != L'\\')) + return L'/'; return a; }); }