backslash-escaping predicate

This commit is contained in:
Jack Andersen 2015-11-10 18:01:36 -10:00
parent 1f3ac3805e
commit faccdbc55a
2 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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;
});
}