Added cFile:ChangeFileExt() function.

This commit is contained in:
Mattes D
2015-04-06 22:00:54 +02:00
parent 31953b19b8
commit 6952f2295a
3 changed files with 28 additions and 0 deletions
+23
View File
@@ -453,6 +453,29 @@ AString cFile::ReadWholeFile(const AString & a_FileName)
AString cFile::ChangeFileExt(const AString & a_FileName, const AString & a_NewExt)
{
auto res = a_FileName;
auto DotPos = res.rfind('.');
if (DotPos == AString::npos)
{
// No extension, just append it:
res.push_back('.');
res.append(a_NewExt);
}
else
{
// Replace existing extension:
res.erase(DotPos + 1, AString::npos);
res.append(a_NewExt);
}
return res;
}
int cFile::Printf(const char * a_Fmt, ...)
{
AString buf;
+4
View File
@@ -127,6 +127,10 @@ public:
/** Returns the entire contents of the specified file as a string. Returns empty string on error. */
static AString ReadWholeFile(const AString & a_FileName);
/** Returns a_FileName with its extension changed to a_NewExt.
a_FileName may contain path specification. */
static AString ChangeFileExt(const AString & a_FileName, const AString & a_NewExt);
// tolua_end
/** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */