From f1f12495b2fe33e6ae424e1654a66e220162e926 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 24 Jan 2015 15:59:06 +0100 Subject: cFile: Added ReplaceFileNameInvalidChars(). --- src/OSSupport/File.cpp | 23 +++++++++++++++++++++++ src/OSSupport/File.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 8957dfaef..1ee9feafe 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -453,6 +453,29 @@ AString cFile::ReadWholeFile(const AString & a_FileName) +AString cFile::ReplaceFileNameInvalidChars(const AString & a_FileName, char a_Replacement) +{ + AString res(a_FileName); + for (auto & ch: res) + { + switch (ch) + { + case ':': + case '\\': + case '/': + { + ch = a_Replacement; + break; + } + } + } + return res; +} + + + + + int cFile::Printf(const char * a_Fmt, ...) { AString buf; diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index dfb38e839..b39f71e28 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -126,6 +126,9 @@ public: /** Returns the entire contents of the specified file as a string. Returns empty string on error. */ static AString ReadWholeFile(const AString & a_FileName); + + /** Replaces characters that cannot be in a file name with the specified char. */ + static AString ReplaceFileNameInvalidChars(const AString & a_FileName, char a_Replacement = '_'); // tolua_end -- cgit v1.2.3