From faccdbc55ae6cf7fdf574c98354db7d7f1326d2d Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 10 Nov 2015 18:01:36 -1000 Subject: [PATCH] backslash-escaping predicate --- hecl/extern/libpng/CMakeLists.txt | 2 +- hecl/lib/HECL.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hecl/extern/libpng/CMakeLists.txt b/hecl/extern/libpng/CMakeLists.txt index 561fb1b26..49ad89341 100644 --- a/hecl/extern/libpng/CMakeLists.txt +++ b/hecl/extern/libpng/CMakeLists.txt @@ -3,7 +3,7 @@ find_library(PNG_LIB png) endif() if(WIN32 OR APPLE OR PNG_LIB STREQUAL PNG_LIB-NOTFOUND) -message("-- Using HECL's built-in libpng") +message(STATUS "Using HECL's built-in libpng") include_directories(${ZLIB_INCLUDE_DIR}) add_library(png png.h diff --git a/hecl/lib/HECL.cpp b/hecl/lib/HECL.cpp index 18ad533ed..c545e4462 100644 --- a/hecl/lib/HECL.cpp +++ b/hecl/lib/HECL.cpp @@ -12,13 +12,22 @@ 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::string::iterator p1 = path.begin(); + bool ic = false; std::transform(path.begin(), path.end(), path.begin(), [&](const char a) -> char { ++p1; + if (ic) + { + ic = false; + return a; + } static const std::string illegals {"<>?*\"|"}; if (illegals.find_first_of(a) != std::string::npos) return '_'; if (a == '\\' && (p1 == path.end() || *p1 != '\\')) + { + ic = true; return '/'; + } return a; }); } @@ -30,13 +39,22 @@ 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::wstring::iterator p1 = path.begin(); + bool ic = false; std::transform(path.begin(), path.end(), path.begin(), [&](const wchar_t a) -> wchar_t { ++p1; + if (ic) + { + ic = false; + return a; + } 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'\\')) + { + ic = true; return L'/'; + } return a; }); }